Üye Kayıt Üye Giriş

Hex, Octal ve Dec arası değişim


Hex, Octal ve Dec arası değişim


//****************************************************************************//
//                                                                            //
// Program Name : ConvDec.cpp                                                 //
//                                                                            //
//   Programmer : K.Angel                                                     //
//              : Novice C++                                                  //
//                                                                            //
//  Description : The user is asked to input a number in either Hex, Octal or //
//                Decimal, which is then converted to Hex, Octal & Decimal.   //
//                The user can exit the program from the MAIN MENU or by      //
//                the Escape key after each convertion.                       //
//                                                                            //
//     Compiler : Borland Turbo C++ v4.5.                                     //
//         Date : 16/03/2006                                                  //
//                                                                            //
//****************************************************************************//
 
#include <iostream.h>
#include <conio.h>             // for clrscr() & getche() functions...
#include <stdlib.h>            // for exit() function...
 
const int ESC = 27;           // Used for escape sequince
 
int main()
{
     int key = 0;
     int choise = 0;
     long number;
 
     while(key != ESC)
     {
          cout << "Choose Your Number Base\n";
          cout << "\n\t1. Hexadecimal.";
          cout << "\n\t2. Octal.";
          cout << "\n\t3. Decimal.";
          cout << "\n\t4. Exit.\n\t       ";
          cin  >> choise;
 
          switch(choise)
          {
               case 1: clrscr();
                               cout << "Enter a Hex number: ";
                               cin  >> hex >> number;
                               cout << "\n   value in octal = "
                               << oct << number << endl;
                               cout << " value in decimal = "
                               << dec << number << endl;
                               break;
               case 2: clrscr();
                               cout << "Enter a Octal number: ";
                               cin  >> oct >> number;
                               cout << "\n       value in hex = "
                               << hex << number << endl;
                               cout << "   value in decimal = "
                               << dec << number << endl;
                               break;
               case 3: clrscr();
                               cout << "Enter a dec number: ";
                               cin  >> dec >> number;
                               cout << "\n   value in octal = "
                               << oct << number << endl;
                               cout << "     value in hex = "
                               << hex << number << endl;
                               break;
               case 4:  clrscr();
                               cout << "Program terminated by user...";
                               exit(0);
                               break;                 //Unreachable code....  
               default : clrscr();
                               cout << "ERROR ~ Invalid selection\n\n";
                               break;
          }
          cout << "Press any key to continue or 'Esc' to exit";
          key = getche();
          clrscr();
     }
     cout << "Program terminated by user...";
     return 0;
}
 

Bilgisayar Dershanesi Ders Sahibi;
Bilgisayar Dershanesi

Yorumlar

Yorum Yapabilmek İçin Üye Girişi Yapmanız Gerekmektedir.

ETİKETLER