Tuesday, February 12, 2013

A simple C++ program with class - C++ program - A simple class program

A Simple C++ program through the class:

// Adding two number using class (C++)
#include<iostream.h>
#include<conio.h>
class add
{
 private:
     int a,b,c;
 public:
      void read()
      {
          cout<<"Enter Frist Number;
          cin>>a;
          cout<<"Enter Second Number;
          cin>>b;
      }
      void display()
      {
         cout<<"A = "<<a<<endl;
         cout<<"B = "<<b<<endl;
         cout<<"C = "<<c<<endl;
      }
      void sum()
      {
       c= a+b;
      }
};
void main()
{
  add z; // z is a object off add
  clrscr();
  z.read();
  z.sum();
  z.display();
  getch();
}

0 comments:

Post a Comment