Add two data member of class

Thursday, October 08, 2015 Unknown 0 Comments

Addition of two data member of class...

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

class test    // class class_name
{
      Private:     //visibility mode that data only access by mathod of this class.......

         int a,b;

       public:    //it is another visibility mode that data also access by outside of class.....

             void getdata()         //method of class
             {
                       cout<<"enter value of A &B : ";
                       cin>>a>>b;
             }

             void sum()       //it is another mathod of class that sum two number......
             {
                      cout<<"Sum = "<<a+b;
             }
};

void main()
{
            test t1;        //create object of that class.....
             t1.getdata();      //call public mathod of class.....
             t1.sum();    
             getch();
}


OUTPUT:-enter value of A & B : 10 20
Sum = 30


To know about God and Godly University please click here : www.pbks.info

other programs.....
1.simple cpp program
2.simple class
3.add two numbers of class

show this all programs

0 comments: