First Object Oriented CPP Program
//my first object oriented cpp program
#include<iostream>
using namespace std;
int x;//variable
class Maths
{
int num1;//Data member
int num2;
int res;
public:
void getData()//member function
{
cout<<"Enter first number";
cin>>num1;
cout<<"\n Enter second number";
cin>>num2;
}//end of function getData
//num1=10;
//num2=20;
void sum()
{
res=num1+num2;
cout<<"\n The sum of "<<num1<<" and "<<num2<<" is: "<<res;
}//end of function sum
};
int main()//non member funtion
{
Maths mt;
mt.getData();
mt.sum();
}//end of main
Comments
Post a Comment