//defining member function outside the class
//******************************************
#include<iostream>
using namespace std;
class sum //making the class name sum
{
private: //private part of the class
int a,b;
public: //public part of the class
void getdata(); //this is the function decleartion
void putdata() //this is the function defination
{
int t;
t=a+b;
cout<<"the sum of two numbers is:"<<t<<endl;
}
};
void sum :: getdata() //this is the method of defining the function outside the class
{
cout<<"enter the first number:";
cin>>a;
cout<<"enter the second number:";
cin>>b;
}
int main()
{
sum s; //making the object of the class and calling the function with the help of object
s.getdata();
s.putdata();
}
No comments:
Post a Comment