Write a program to test the inputting of integer values in decimal, octal and hexadecimal formats. Output each integer read by the program in all three formats. Test the program with the following input data: 10, 010, 0x10.

What will be an ideal response?


```
#include
#include
#include
using namespace std;

void show( const string message )
{
int integer; // holds values input by user

// prompt user to enter data in decimal format
cout << "\n" << message;
cin >> integer; // store data in integer

// display integer in decimal, octal and hexadecimal format
cout << showbase << "As a decimal number " << dec
<< integer << "\nAs an octal number " << oct << integer
<< "\nAs a hexadecimal number " << hex << integer << endl;
} // end function show

int main()
{
show( "Enter an integer: " );
cin >> oct;
show( "Enter an integer in octal format: " );
cin >> hex;
show( "Enter an integer in hexadecimal format: " );
} // end main
```
Enter an integer: 10
As a decimal number 10
As an octal number 012
As a hexadecimal number 0xa
Enter an integer in octal format: 010
As a decimal number 8
As an octal number 010
As a hexadecimal number 0x8
Enter an integer in hexadecimal format: 0x10
As a decimal number 16
As an octal number 020
As a hexadecimal number 0x10

Computer Science & Information Technology

You might also like to view...

The ________ attribute defines where the image is stored

Fill in the blank(s) with correct word

Computer Science & Information Technology

The ____ function randomly scrambles the order of characters in a string.

A. str_scramble() B. str_shuffle() C. str_jumble() D. str_random()

Computer Science & Information Technology

SSL protocols are the only security protocols that are supported by all web browsers.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Explain briefly how the Add pathfinder works.

What will be an ideal response?

Computer Science & Information Technology