//Program - 4 Overload Binary Operator + (plus) using member function
#include <iostream.h>
#include <conio.h>
class calculate
{
int a, b;
public:
void getdata()
{
cout << "Enter value a = ";
cin >> a;
cout << "Ente value b = ";
cin >> b;
}
void print()
{
cout << endl << "A = " << a;
cout << endl << "B = " << b;
}
calculate operator+(calculate ob2)
{
calculate temp;
temp.a = a + ob2.a;
temp.b = b + ob2.b;
return temp;
}
};
void main()
{
clrscr();
calculate obj1, obj2, obj3;
obj1.getdata();
obj2.getdata();
obj3 = obj1 + obj2; //calls operator+() fuction
obj3.print();
getch();
}
Comments
Post a Comment