Thursday, 8 August 2013

Source code: Conversion of ASCII Value to Character and Character to ASCII Value using C++ [ user friendly, easy, object oriented ]

#include <iostream>
using namespace std;

void a2c()
{
int ch;
cout <<"enter the ASCII value: ";
cin>> ch;
cout <<"\ncharacter: "<< static_cast<char>(ch)<<endl<<endl;
}

void c2a()
{
char ing;
cout <<"\n\n\nenter the character: ";
cin>> ing;
cout <<"\nASCII: " <<static_cast<int>(ing)<<endl<<endl;
}

int main()
{
char c;
cout <<"pick what you want: \n";
cout <<"a. ASCII to Character\n";
cout <<"b. Character to ASCII\npick: ";
cin>> c;

switch(c)
{
case 'a': a2c(); break;
case 'b': c2a(); break;
}
}

No comments:

Post a Comment