ASCII Program in C++

ASCII – American Standard Code for Information Interchange

The program below is a demonstration of ASCII code printing which only prints the alphabet (uppercase, lowercase), numeric, and some special characters ascii code.

Along with ASCII values, their original values have also been printed in the program so that readability can be obtained and the program can be easily understood.

In C++, to print an ASCII value of a value, we assign the same value to the two different data-type, such as-

char = 'a';

Now, to print the ASCII code of this a

int (a); // 97 will be print

Before starting the program, see the output of the program, so that you can easily understood.

#include<iostream.h>
#include<conio.h>
#include<dos.h>

void prntline(); // print line ____
void prntln();  // print line ====

void main()
{
   clrscr();
   char c='A',s='a';
   cout<<endl;

   cout<<"ASCII code(for capital latter): \n";
   prntln(); // print line
   cout<<"\n\n";

/********FOR CAPITAL LATTER*******/

   int i =0;
    while(i<26) // because alphabet has 26 
    {
       cout<<c<<"-"; // print variable c value
     // printing char variable using int data type
       cout<<int(c++)<<" ";
       i++;
    }
   cout<<endl;
   prntline();
   getch();

/********FOR SMALL LATTER*******/

   cout<<"\n\nASCII code(for small latter):\n";
   prntln();
   cout<<"\n\n";
   int j =0;
    while(j<26)
    {
	cout<<s<<"-"; // print variable s value
	cout<<int(s++)<<" ";
	j++;
    }
   cout<<endl;
   prntline(); // print a line
   getch();

/********FOR NUMERIC VALUE*******/

   cout<<"\n\nASCII code(for numeric values): \n";
   prntln(); // print line
   cout<<"\n\n";

    for(int k=48;k<=57;k++)
     {
       cout<<k<<"-"; // print k value
                        //print int variable value using char data type
       cout<<char(k)<<" "; // printing ascii code
     }
   cout<<endl;
   prntline(); // print a line
   getch();

/*****FOR SPECIAL CHARECTER*****/

  cout<<"\n\nASCII code(for special chahrecter):\n";
  prntline(); // print line
  cout<<"\n\n";
    
   for(int x=32;x<48;x++)
    {
      cout<<x<<"-"; // print original value
      cout<<char(x)<<" "; // print ascii value
    }
  cout<<endl;
  prntline(); // print line
  getch();
}                           // close void main() function

void prntline()
 {
     // line ___ definition
     int l=0;
     while(l<80)
     {
	 cout<<"_";
         l++;
     } 
 }

 void prntln()
 {
          // line ==== definition
    int n=0;

    while(n<35)
    {
       cout<<"=";n++;
    }

  }
OUTPUT:-
ASCII code(for capital latter): 
===================================
A-65 B-66 C-67 D-68 E-69 F-70 G-71 H-72 I-73 J-74 K-75 L-76 M-77 N
-78 O-79 P-80 Q-81 R-82 S-83 T-84 U-85 V-86 W-87 X-88 Y-89 Z-90 
________________________________________________________________
ASCII code(for small latter):
===================================
a-97 b-98 c-99 d-100 e-101 f-102 g-103 h-104 i-105 j-106 k-107 l-108 
m-109 n-110 o-111 p-112 q-113 r-114 s-115 t-116 u-117 v-118 w-119 x-
120 y-121 z-122 
________________________________________________________________
ASCII code(for numeric values): 
===================================
48-0 49-1 50-2 51-3 52-4 53-5 54-6 55-7 56-8 57-9 
________________________________________________________________
ASCII code(for special charecter): 
=================================== 
32-space 33-! 34-" 35-# 36-$ 37-% 38-& 39-' 40-( 41-) 42-* 43-+ 44-, 45-- 46-. 47-/
________________________________________________________________

The program below is a demonstration of ASCII code printing which only prints the alphabet (uppercase, lowercase), numeric, and some special characters ascii code.

Along with ASCII values, their original values have also been printed in the program so that readability can be obtained and the program can be easily understood.

In C++, to print an ASCII value of a value, we assign the same value to the two different data-type, such as-

char = 'a';

Now, to print the ASCII code of this a

int (a); // 97 will be print

Before starting the program, see the output of the program, so that you can easily understood.

#include
#include
#include
void prntline(); // print line ____ void prntln(); // print line ==== void main() { clrscr(); char c='A',s='a'; cout<<endl; cout<<"ASCII code(for capital latter): \n"; prntln(); // print line cout<<"\n\n"; /********FOR CAPITAL LATTER*******/ int i =0; while(i<26) // because alphabet has 26 { cout<<c<<"-"; // print variable c value // printing char variable using int data type cout< c++;i++; } cout<<endl; prntline(); getch(); /********FOR SMALL LATTER*******/ cout<<"\n\nASCII code(for small latter):\n"; prntln(); cout<<"\n\n"; int j =0; while(j<26) { cout<<s<<"-"; // print variable s value cout< s++;j++; } cout<<endl; prntline(); // print a line getch(); /********FOR NUMERIC VALUE*******/ cout<<"\n\nASCII code(for numeric values): \n"; prntln(); // print line cout<<"\n\n"; for(int k=48;k<=57;k++) { cout<<k<<"-"; // print k value //print int variable value using char data type cout<<char(k)<<" "; // printing ascii code } cout<<endl; prntline(); // print a line getch(); /*****FOR SPECIAL CHARECTER*****/ cout<<"\n\nASCII code(for special chahrecter):\n"; prntlin(); // print line cout<<"\n\n"; for(int x=32;x<48;x++) { cout<<x<<"-"; // print original value cout<<char(x)<<" "; // print ascii value } cout<<endl; prntline(); // print line getch(); } // close void main() function void prntline() { // line ___ definition int l=0; while(l<80) { cout<<"_"; l++; } } void prntln() { // line ==== definition int n=0; while(n<35) { cout<<"=";n++; } }
OUTPUT:-

ASCII code(for capital latter): 
===================================
A-65 B-66 C-67 D-68 E-69 F-70 G-71 H-72 I-73 J-74 K-75 L-76 M-77 N
-78 O-79 P-80 Q-81 R-82 S-83 T-84 U-85 V-86 W-87 X-88 Y-89 Z-90 
________________________________________________________________

ASCII code(for small latter):
===================================
a-97 b-98 c-99 d-100 e-101 f-102 g-103 h-104 i-105 j-106 k-107 l-108 
m-109 n-110 o-111 p-112 q-113 r-114 s-115 t-116 u-117 v-118 w-119 x-
120 y-121 z-122 
________________________________________________________________

ASCII code(for numeric values): 
===================================
48-0 49-1 50-2 51-3 52-4 53-5 54-6 55-7 56-8 57-9 
________________________________________________________________

ASCII code(for special charecter): 
=================================== 
32-space 33-! 34-" 35-# 36-$ 37-% 38-& 39-' 40-( 41-) 42-* 43-+ 44-, 45-- 46-. 47-/
________________________________________________________________