C++ Program to find the sum of two integer numbers using classes and objects
Program
#include<iostream>
using namespace std;
class Add
{
int a, b;
public:
void getData()
{
cout << "Enter two numbers a and b" << endl;
cin >> a >> b;
}
void add()
{
cout << "Sum:\t" << a + b << endl;
}
};
int main()
{
Add sum;
sum.getData();
sum.add();
return 0;
}
Output
Enter two numbers a and b
12
9
Sum: 21