Write a program to overload the expression (ob1*ob2) %ob3. Where ob1, ob2 and ob3 are the objects of a class. Assume 2 number of integer data members in the class.
#include <iostream>
using namespace std;
class Object
{
int x;
int y;
public:
Object(){}
Object(int _x,int _y):x(_x),y(_y){}
Object operator* (Object& o)
{
Object tmp;
tmp.x = x*o.x;
tmp.y = y*o.y;
return tmp;
}
Object operator% (Object& o)
{
Object tmp;
tmp.x = x%o.x;
tmp.y = y%o.y;
return tmp;
}
friend ostream& operator<< (ostream&, Object&);
};
ostream& operator<< (ostream& os, Object& o)
{
return os<<"\nInfo about object: " << "x = " << o.x << " y = " << o.y;
}
int main()
{
Object ob1(5, 9);
Object ob2(2, 4);
Object ob3(3, 8);
Object ob4 = (ob1*ob2) % ob3;
cout << ob4;
}
Comments
Leave a comment