Tuesday, 23 April 2013

ATM MACHINE PROJECT

Prepared by:

Ahmed Khan (Telecom Engineering Student)

Description:

This Project perform almost all functions of ATM Machine. This project is developed in Turbo C++. Its tested in (TurboC++ version 2.3) and the program works well. It performs following functions:


  1. New Account
  2. Close Account
  3. Modify Account
  4. Display Account
  5. Display All Accounts
  6. Withdraw Amount
  7. Deposit Amount
  8. Exit Program

AIRWAYS RESERVATION SYSTEM PROJECT

Description:

This Project is an online ticket booking system. A computer reservation system which is used for the reservations of a particular airline. This project is built in C++ and is tested in Visual Studio 2012. It performs following functions:

  1. Local Booking
  2. International Booking
  3. Available Flights

PREPARED BY:

AFRAZ AHMED KHAN
RANA JAHANZEB


REPORT OF PROJECT MCQ'S EXAM


Report on Project of MCQ’s Exam
Purpose:

  1. To analyze this project completely.
  2. To discuss all its features.
  3. To describe all important things, necessary for running this program.
Special thanks to:
Sir Muhammad Jamil Khan
Date of completion:
16-7-2012.
Abstract:        
               This project (MCQ’s Exam) is developed for the easiness of exam taking system. With the help of this project a student will not be imposed to carry a clip board, pencils and papers. Furthermore it is also helpful for paper checking system as it immediately check answers and quickly produce results. It is also helpful to control results cheating as it is developed so that each and every student will get different questions because questions will occur randomly. 

MCQ'S EXAM PROJECT

Description:

This Project is like simple MCQ's exam system on computers. It can be used for online Exam system.

INSTRUCTIONS:

  • Make a folder in 'd' drive naming 'mcq'.
  • In 'mcq' folder make three subfolders naming 'itc', 'itt', 'oop'.
  • Then in each subfolder make 33 text doccument files . Each file contains one mcq question having three or four choices.
  • Then change the part of code having answers accordingly.

Code to produce increasing and decreasing stars

Description:

This program produce increasing and decreasing stars automatically.

Code:


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int i,j;
    for(i=1;i<=9;i=i+2)
     {
        for(j=0;j<i;j++)
        cout<<"*";
        cout<<endl;
        }
         if(i==11)
         {i=i-4;
         for(i=7;i>=1;i=i-2)
          {for(j=0;j<i;j++)
          {
            cout<<"*";
         
            }
            cout<<endl;}}
            getche();
 }


Output:


CODE TO DISPLAY FEBRUARY MONTH AS IN CALENDER

Description:
This program show february month as in calender automatically.
CODE:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{int i,j,k=6;

    cout<<setw(20)<<"Feb 2012"<<endl;
    cout<<endl;
    cout<<setw(5)<<"MO"<<setw(5)<<"TU"<<setw(5)<<"W"<<setw(5);
cout<<"TH"<<setw(5)<<"Fr"<<setw(5)<<"Sa"<<setw(5)<<"Su"<<endl;
cout<<setw(5)<<"30";
cout<<setw(5)<<"31";

for(i=1;i<=5;i++)
cout<<setw(5)<<i;
cout<<endl;
for(i=0;i<3;i++)
{for(j=0;j<7;j++)
{
cout<<setw(5)<<k;
k++;
 }

 cout<<endl;
                }
 for(i=27;i<30;i++)
 cout<<setw(5)<<i;
 cout<<endl;
 cout<<endl;
cout<<"     **** Hafiz Junaid Hassan ****"<<endl;
cout<<setw(5)<<"           11-TE-14     ";


getche();
return 0;
}


GAME OF CHANCE USING RANDOM FUNCTION

Description:

This is a simple game of chance which is made using random function of c++.

CODE:


#include<iostream>
#include<conio.h>
#include<cstdlib>
#include<ctime>
using namespace std;
int rolldice(void);
int main()
{
    enum status{Continue,won,lost};
    int sum;
    int mypoint;
    char ch3;
    cout<<"Welcom to this exciting game of chance"<<endl;
    cout<<"The rules of the game are as follows"<<endl;
    cout<<"in the first round if your points are 7 or 11 you will win"<<endl;
    cout<<"and if your points are 2 , 3 or 12 you will loose"<<endl;
    cout<<"if your points are other than these you will go to the second round"<<endl;
    cout<<"in second round if your points become equal to your first round points then you will win"<<endl;
    cout<<"and if your second round points become equal to 7 then you will loose"<<endl;
    status gamestatus;
    srand(time(0));
    sum=rolldice();
    switch(sum)
    {
       case 7:
       case 11:
       gamestatus=won;
       break;
       case 2:
       case 3:
       case 12:
       gamestatus=lost;
       break;
       default:
       gamestatus=Continue;
       mypoint=sum;
       cout<<"your first round points are"<<mypoint<<endl;
       cout<<"your decesion can not be made on rolling"<<endl<<"If you want to continue pay 1$"<<endl;
       cout<<"if you have paid then press Y"<<endl;
       break;
               }
       cin>>ch3;
       if(ch3=='y'||ch3=='Y')
       {
       while(gamestatus==Continue)
       {
          sum=rolldice();
          if(sum==mypoint)
          gamestatus=won;
          else if(sum==7)
          gamestatus=lost;
                                  }
          if(gamestatus==won)
          cout<<"player wins"<<endl;
          else if(gamestatus==lost)
          cout<<"player loses"<<endl;
          getche();
          return 0;
    }
}
    int rolldice(void)
    {
        int die1,die2,worksum;
        char ch1,ch2;
        cout<<"press A for your first roll of dice"<<endl;
        cin>>ch1;
        if(ch1=='a'||ch1=='A')
        die1=1+rand()%6;
        cout<<"player rolled "<<endl<<die1<<endl;
        cout<<"press B for your second roll of dice"<<endl;
        cin>>ch2;
        if(ch2=='b'||ch2=='B')
        die2=1+rand()%6;
        worksum=die1+die2;

        cout<<"player rolled "<<endl<<die2<<endl<<"your total points are"<<worksum<<endl;
        return worksum;
     
        }


OUTPUT:


Welcom to this exciting game of chance
The rules of the game are as follows
in the first round if your points are 7 or 11 you will win
and if your points are 2 , 3 or 12 you will loose
if your points are other than these you will go to the second round
in second round if your points become equal to your first round points then you
will win
and if your second round points become equal to 7 then you will loose
press A for your first roll of dice
A
player rolled
2
press B for your second roll of dice
B
player rolled
6
your total points are8
your first round points are8
your decesion can not be made on rolling
If you want to continue pay 1$
if you have paid then press Y
Y
press A for your first roll of dice
A
player rolled
1
press B for your second roll of dice
B
player rolled
4
your total points are5
press A for your first roll of dice
A
player rolled
3
press B for your second roll of dice
B
player rolled
4
your total points are7
player loses

FILE HANDLING PROGRAMS

Description:

Here some tasks are performed using file handling concept.

CODE1:


#include<conio.h>
#include<fstream>
using namespace std;
int main()
{
ofstream outfile("TEST.TXT");
outfile<<"Ifear the ancient thee,ancient Mariner!\n";
outfile<<"I fear the skinny hand\n";
    outfile<<"And thou art long, and lank, and brown\n;
    outfile<<"As is the ribbed sea sand.\n";
getche();
}


CODE2:


#include<fstream>
#include<conio.h>
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str="Time is a great teacher, but unfortunately"
"it kills all its pupils. Berlioz";
ofstream outfile("TEST.TXT");
for(intj=0;j<str.size();j++)
outfile.put(str[j]);
cout<<"File written\n"
getche();
}


CODE3:

#include<fstream>
#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
ifstream infile("TEST.TXT");
cout<<infile.rdbuf();
cout<<endl;
getche();
}

CODE4:

#include<fstream>
#include<conio.h>
#include<iostream>
using namespace std;
class person
{
protected:
char name [80];
short age;
public:
void getData()
{
cout<<"Enter name : "cin>>name;
cout<<"Enter age: "cin>>age;
}
};
int main()
{
person pers;
pers.getData();
ofstream outfile("PERSON.DAT", ios::binary);
outfile.write(reinterpert_cast<char*>(&pers),sizeof(pers));
getche();
}

CODE5:

#include<fstream>
#include<conio.h>
#include<iostream>
class person
{
protected:
char name[80];
int age;
public:
void getdata()
{
cout "\nEnter name:";cin>>name;
cout<<"Enter age: ";cin >>age;
}
void showdata()
{
cout<<"\n Name: "<<name;
cout<<"\n Age: "<<age;
}
};
int main()
{
char ch;
person pers;
fstream file;
file.open("GROUP.DAT"), ios::app|ios::out|
ios::in|ios::binary);
do
{
cout<<"\nEnter person's data:";
pers.getdata();
file.write(reinterpret_cast<char*>(&pers),
sizeof(pers));
cout <<"enter another person(y/n)?"
cin>>ch;
}


FILE HANDLING CODES

Description:

Here some examples and functions of "file handling" (an important concept of c++) are presented.

CODE:



POLYMORPHISM EXAMPLE1

Description:

Some examples of 'Polymorphism' (an important concept of c++) are presented here.

TASK:

 virtual   functions   with  person  class

CODE:


#include  <iostream>
using   namespace   std;
////////////////////////////////////////////////////////////////
class   person  //person  class
{
protected :
  char  name[40];
public:
  void  getName()
  {   cout << "   Enter   name:   " ;   cin   >>  name;   }
  void  putName()
  {   cout << "Name   is:  "   <<  name <<  endl;   }
  virtual   void  getData()   =   0;  //pure  virtual   func
  virtual   bool  isOutstanding()  =  0;  //pure  virtual   func
};
////////////////////////////////////////////////////////////////
class   student   :   public  person //student  class
{
private :
  float   gpa;  //grade   point   average
public:
  void  getData()   //get   student   data  from  user
  {
   person::getName();
   cout  <<  "  Enter   student’s   GPA:  " ;   cin   >>  gpa;
  }
  bool  isOutstanding()
  {   return  (gpa  >   3.5)  ?   true  :  false ;  }
};
////////////////////////////////////////////////////////////////
class   professor   :  public  person  //professor  class
{
private :
  int   numPubs;  //number  of  papers  published
public:
  void  getData()   //get   professor   data  from  user
  {
   person::getName();
   cout  <<  "  Enter   number  of  professor’s  publications:  " ;
   cin   >>  numPubs;
  }
  bool  isOutstanding()
  {   return  (numPubs  >  100)  ?   true :   false ;   } };
////////////////////////////////////////////////////////////////
int   main()
{
  person*   persPtr[100];  //array  of  pointers  to  persons
  int   n   =  0;  //number of  persons   on  list
  char  choice;
  do
  {
   cout  <<  "Enter  student   or  professor   (s/p):  " ;
   cin   >>  choice;
   if(choice== 's' )   //put   new   student
   persPtr[n]  =   new  student;  //  in  array
   else  //put   new   professor
   persPtr[n]  =   new  professor;  //  in  array
   persPtr[n++] ‐ >getData();  //get   data  for  person
   cout  <<  "  Enter   another   (y/n)?  " ;   //do  another  person?
   cin   >>  choice;
  }   while (   choice=='y'   );  //cycle   until   not   ‘y’

for ( int   j=0;  j<n;  j++)  //print   names  of  all
  {   //persons,  and
   persPtr[j]‐ >putName();  //say   if  outstanding
   if(   persPtr[j]‐ >isOutstanding()   )
   cout  <<  "  This  person  is  outstanding\n" ;
  }
  return 0;
}   //end   main()

INHERITANCE EXAMPLE2

TASK2:


 Complete the following tasks:
a. Create a base class named  Rectangle  that includes data members for the length
and width of a  Rectangle, as well as functions to as sign and display those values.
Derive a class named  Block  that contains an additional data member to store height,
and contains functions to assign and display the height. Write a main()function that
demonstrates the classes by instantiating and displaying the values for both a
Rectangle  and a  Block. Save the file as  RectangleAndBlock.cpp.
b. Add a member function to the Rectangle  class that computes the area of a
Rectangle  (length multiplied by width). Add a member function to  Block  that has the
same name, but overrides the computation  with a volume calculation (length by
width by height). Write a main() function that demonstrates the classes. Save the file
as RectangleAndBlock2.cpp.

CODE(A):


#include<iostream>
#include<conio.h>
using namespace std;
class rectangle
{
private:
            float length,width;
public:
            void getdata()
            {
             cout<<"Enter the value of length:";cin>>length;
             cout<<"Enter the value of width:";cin>>width;
            }
            void showdata()
            {
             cout<<"Length:"<<length<<endl;
             cout<<"Width:"<<width<<endl;
            }
};
class block:public rectangle
{
private:
            float height;
public:
            void getdata()
            {
             rectangle::getdata();
             cout<<"Enter value of height:";cin>>height;
            }
            void showdata()
            {
             rectangle::showdata();
             cout<<"Height:"<<height<<endl;
            }
};
int main()
{
  rectangle rec1;
  block bl1;
  cout<<"Enter data for rectangle "<<endl;
  rec1.getdata();
  cout<<"Enter dat for block"<<endl;
  bl1.getdata();
  cout<<"Entered data for rectangle is"<<endl;
  rec1.showdata();
  cout<<"Entered data for block is"<<endl;
  bl1.showdata();
  cout<<endl;
  getche();
  return 0;
}

OUTPUT:


Enter data for rectangle
Enter the value of length:75
Enter the value of width:38
Enter dat for block
Enter the value of length:92
Enter the value of width:83
Enter value of height:23
Entered data for rectangle is
Length:75
Width:38
Entered data for block is
Length:92
Width:83
Height:23

CODE(B):

#include<iostream>
#include<conio.h>
using namespace std;
float area1;
class rectangle
{
private:
            float length,width;
public:
            void getdata()
            {
             cout<<"Enter the value of length:";cin>>length;
             cout<<"Enter the value of width:";cin>>width;
            }
            void showdata()
            {
             cout<<"Length:"<<length<<endl;
             cout<<"Width:"<<width<<endl;
             cout<<"Area:";
             cout<<AreaAndVolume(length,width)<<endl;
             
            }
            int AreaAndVolume(float length2,float width2)
            {
             
           
              area1=length*width;
              return area1;
            }
};
class block:public rectangle
{
private:
            float height;
public:
            void getdata()
            {
             cout<<"Enter value of height:";cin>>height;
            }
            void showdata()
            {
             cout<<"Height:"<<height<<endl;
             cout<<"volume:";
             cout<<AreaAndVolume(height)<<endl;
            }
            int AreaAndVolume(float height)
            {
             float vol1;
             vol1=area1*height;
             return vol1;
            }
};
int main()
{
  rectangle rec1;
  block bl1;
  cout<<"Enter data for rectangle "<<endl;
  rec1.getdata();
  cout<<"Enter dat for block"<<endl;
  bl1.getdata();
  cout<<"Entered data for rectangle is"<<endl;
  rec1.showdata();
  cout<<"Entered data for block is"<<endl;
  bl1.showdata();
  cout<<endl;
  getche();
  return 0;
}
Output:
Enter data for rectangle
Enter the value of length:75
Enter the value of width:86
Enter dat for block
Enter value of height:758
Entered data for rectangle is
Length:75
Width:86
Area:6450
Entered data for block is
Height:758
volume:4889100


INHERITANCE EXAMPLE1

Description:

Here some examples of "Inheritance" (important concept of c++) are presented.

CODE:



#include<iostream>

#include<conio.h>

using namespace std;
class B
{
public:
            int m,a;
            int product1()
            {
             return a*m;
            }
};
class D:public B
{
public:
            int n;
            int product2()
            {
             return n*product1();
            }
};
int main()
{
 D d1;
 d1.m=5;
 d1.a=4;
 d1.n=3;
 cout<<"product1 = "<<d1.product1()<<endl;
 cout<<"product2 = "<<d1.product2()<<endl;
 getche();
 return 0;
}

OUTPUT:


product1 = 20
product2 = 60


Monday, 22 April 2013

Code to produce decreasing stars

Description:

This program simply produce increasing and decreasing stars automatically.

Code:


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int i,j;
    for(i=5;i>=1;i--){
    for(j=0;j<i;j++)
    {cout<<"*";
    }
    cout<<endl;
}
    getche();
}

 
Output :



Code for Simple Calculator

Description:

This program perform different operation of calculator.

Code:


#include<iostream>
#include<conio.h>
using namespace std;
int sum(int,int);
int difference(int,int);
int multiplication(int,int);
float division(int,int);
int average(int,int);
int s=0,d=0,m=0,g=0;float v=0;
int main()
{
   int a,b;
cout<<"enter first number"<<endl;
 cin>>a
cout<<"enter second number"<<endl;
cin>>b;
 s= sum (a,b);
 cout<<s<<endl;
 d= difference (a,b);
 cout<<d<<endl;
 m= multiplication (a,b);
 cout<<m<<endl;
 v= division (a,b);
 cout<<v<<endl;
 g= average (a,b);
 cout<<g<<endl;
 cout<<"ok";
getche();
return 0;
}
int sum (int x,int y)
{
 s=x+y;
 cout<<"sum="<<endl;
return s;
}
int difference (int x,int y)
{
d=x-y;
cout<<"difference="<<endl;
return d;
}
int multiplication (int x,int y)
{
m=x*y;
cout<<"multiplication="<<endl;
return m;
}
float division (int x,int y)
{
v=x/y;
cout<<"division="<<endl;
return v;
}
int average (int x,int y)
{
g=(x+y)/2;
cout<<"average="<<endl;
return g;
}


Output:


Getting Maximum Value from Array Elements

Description:

This program take different values from user and store these values in array and find maximum value from these entered values automatically.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
    int i,j,k,a[5],max;
    cout<<"enter values of elements of array"<<endl;
    for(i=0;i<=4;i++)
    {cout<<"a["<<i<<"]=";
    cin>>a[i];
    cout<<endl;}
    cout<<"your entered elements of array are"<<endl;
    for(i=0;i<=4;i++)
    {cout<<a[i];
    cout<<endl;}
    max=a[0];
    for(i=0;i<=4;i++)
    {
    if(max<a[i])
    max=a[i];}
    cout<<"maximum valu is "<<endl<<max;
    getche();
    return 0;
 
    }


Output:


Manipulating Array Elements

Description:

This program define elements of array and perform different operations on elements of array. In C++ array is used to store values at different indexes of array.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
    int i,j,k,sum,avrg;
    float a[5];
    cout<<"Enter values of elements of array"<<endl;
    for(i=0;i<=4;i++)
    {cout<<"a["<<i<<"]"<<" =";
    cin>>a[i];
    }
    cout<<"your entered values of array are"<<endl;
    for(i=0;i<=4;i++)
    cout<<a[i];
    sum=avrg=0;
    for(i=0;i<=4;i++)
    sum=sum+a[i];
    avrg=sum/5;
    cout<<endl<<"The sum of elements of array is"<<endl<<sum<<endl;
    cout<<"The average of elements of array is"<<endl<<avrg<<endl;
    getche();
    return 0;
    }


Output:


A programe to calculate factorial of a number

Description:

This program take a number from user as input and find its factorial automatically.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
       float a,b=1,c,i,f;
    cout<<"A programe to calculate factorial of a number"<<endl;
    xy:
    cout<<"Enter a number to calculate its factorial"<<endl;
    cin>>a;
    cout<<endl;
    i=a;
    while(i>=1)
    {
      b=b*i;
      i--;
      }
      cout<<"The factorial of the given number is"<<b<<endl;
      goto xy;
      getche();
      return 0;
      }


Output:


Programm to get multiplication table

Description:

This program take a number as input and make its multiplication table automatically.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
    int i,n=1,p;
    xy:
    cout<<"Enter the number to get its multiplication table"<<endl;
    cin>>n;
    cout<<endl;
    i=1;
    while(i<=10)
    {p=n*i;
     cout<<n<<"*"<<i<<"="<<p<<endl;
     i++;
     }
     goto xy;
     getche();
     return 0;
     }


Output:


Calculating sum of first ten odd numbers using loop

Description:

This program automatically calculate sum of first ten odd numbers using 'for' loop.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
    int i,j,s=0;
    i=1;
    cout<<"The first ten odd numbers are"<<endl;
    while(i<20)
    {
      if(i%2!=0)
     {
      cout<<i<<" ";
      s=s+i;
      }
      i++;
      }
      cout<<endl<<"The sum of first ten odd numbers is"<<endl<<s;
      getche();
      return 0;
      }


Output:


A programe to find the roots of quadratic equation

Description:

This program take three constants of quadratic equation as input and find real and imaginary roots of that quadratic equation automatically.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
    float a,b,c,d,f,e,g,h,i,j,k,l;
    cout<<"A programe to find the roots of quadratic equation"<<endl;
    xy:
    cout<<"Enter the values of a,b,c"<<endl;
    cout<<"Enter value of a"<<endl;
    cin>>a;
    cout<<endl<<"Enter the value of b"<<endl;
    cin>>b;
    cout<<endl<<"Enter the value of c"<<endl;
    cin>>c;
    cout<<endl;
    d=b*b-(4*a*c);
    if(d>0||d==0)
    {
      f=(-b+sqrt(d))/(2*a);
      e=(-b-sqrt(d))/(2*a);
      cout<<"The required roots are"<<endl<<"The first root is ="<<f<<endl<<"The second root is ="<<e<<endl;
      }
    if(d<0)
    {
      g=-b/(2*a);//x1
      h= sqrt(-d)/(2*a);//x1
      j=-sqrt(-d)/(2*a);//x2
      k=g+h;
      l=g+j;
      cout<<"the required roots are"<<endl;
      cout<<"first root="<<k<<"i"<<endl;
      cout<<"second root="<<l<<"i"<<endl;
      }
      goto xy;
      getche();
      return 0;
      }


Output:


A programme to check the divisibility of a number by 3

Description:

In C++ if there is conditional logic then "if", "else" statements are used.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{
    int a,b,c;
    cout<<"A programe to check the divisibility of a number by 3"<<endl;
    xy:
    cout<<"Enter the number to check its divisibility"<<endl;
    cin>>a;
    cout<<endl;
    if(a%3==0)
    {
              cout<<"The number is divisible by 3"<<endl;
           
              }
           
              goto xy;
              getche();
              return 0;
              }


Output:


Conversion of Fahrenheit Temperature in Celcius

Description:

In C++ 'float' (data type) is used for decimal numbers. And 'int' (data type) is used for integer numbers.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{
    float c,f,a;
    xy:
    cout<<"Enter the value of temperature in Fahrenheit"<<endl;
    cin>>f;
    c=(f-32)*5/9;
    cout<<endl<<"The value of temperature in celsius degrees is"<<endl<<c<<endl;
    goto xy;
    getche();
 
    }


Output:


Addition and Multiplication of Two Numbers

Description:

In c++ 'goto' operator is used to repeat program again. In other words it acts as infinite loop.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{
    int a,b,c,d;
    xy:
    cout<<"Enter two numbers to get their sum and product"<<endl;
    cout<<"Enter the value of a"<<endl;
    cin>>a;
    cout<<"You have entered a="<<a;
    cout<<endl<<"Enter the value of b"<<endl;
    cin>>b;
    cout<<"You have entered b="<<b<<endl;
    c=a+b;
    cout<<"The sum of a and b is"<<endl<<"a+b="<<c<<endl;
    d=a*b;
    cout<<"The product of a and b is"<<endl<<"a*b="<<d<<endl;
    goto xy;
    getche();
    return 0;
    }


Output:


Taking two inputs in variables and then interchanging their values

Description:

In c++, to take inputs from user 'cin' operator is used and to show output 'cout' operator is used.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{
    int a,b,c;
    cout<<"Enter value of A"<<endl;
    cin>>a;
    cout<<endl;
    cout<<"Enter value of B"<<endl;
    cin>>b;
    c=a;
    a=b;
    b=c;
    cout<<"interchanged values are"<<endl;
    cout<<a<<endl<<b<<endl<<"ok";
    getche();
    return 0;
    }


Output:


Creating Columns using "SETW" Operator

Description:

In c++ "Setw(x)" operator is used to separate columns up to 'x' units. It stands for set width. Used in making tables.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{
    cout<<setw(6)<<"62"<<setw(6)<<"8"<<endl;
    cout<<setw(6)<<"100"<<setw(6)<<"77"<<endl;
    cout<<setw(6)<<"5"<<setw(6)<<"162"<<endl;
    getche();
    return 0;
    }


Output: