Write a complete C++ program that asks the user to input a character. Using the ASCII character set as a guide, state whether the user's character is a digit (0 to 9), a letter (a to z or A to Z) or a symbol. Include the character's decimal, octal, and hex valur as well in your input.
C++ Code:
#include <iostream>
using namespace std;
void convertToOctal(int dec){
int octal[100];
int a=0;
while (dec != 0) {
octal[a]=dec%8;
dec=dec/8;
a++;
}
for (int b=a-1;b>=0;b--)
cout<<octal[b];
}
void convertToHex(int dec){
int a=1,b,c;
char hex[100];
while(dec!=0)
{
c=dec%16;
if(c<10)
hex[a++]=c+48;
else
hex[a++]=c+55;
dec=dec/16;
}
for (b=a;b>0;b--)
cout<<hex[b];
}
int main() {
char ch;
int dec;
cout<<"Enter a character: ";
cin>>ch;
if(ch>=48 && ch<=57){
cout<<ch<<" is a digit"<<endl;
dec=ch;
cout<<"Decimal value of "<<ch<<" is "<<dec<<endl;
cout<<"Octal value of "<<ch<<" is ";
convertToOctal(dec);
cout<<endl;
cout<<"Hex value of "<<ch<<" is ";
convertToHex(dec);
cout<<endl;
}
else if(ch>=65 && ch<=122){
cout<<ch<<" is an Alphabet"<<endl;
dec=ch;
cout<<"Decimal value of "<<ch<<" is "<<dec<<endl;
cout<<"Octal value of "<<ch<<" is ";
convertToOctal(dec);
cout<<endl;
cout<<"Hex value of "<<ch<<" is ";
convertToHex(dec);
cout<<endl;
}
else{
cout<<ch<<" is a Symbol"<<endl;
dec=ch;
cout<<"Decimal value of "<<ch<<" is "<<dec<<endl;
cout<<"Octal value of "<<ch<<" is ";
convertToOctal(dec);
cout<<endl;
cout<<"Hex value of "<<ch<<" is ";
convertToHex(dec);
cout<<endl;
}
}



if you like the answer please provide a thumbs up.
Write a complete C++ program that asks the user to input a character. Using the ASCII...