Get premium membership and access questions with answers, video lessons as well as revision papers.

Overload the - and / operators for the coord class using friend functions.

      

Overload the - and / operators for the coord class using friend functions.

  

Answers


Davis

#include
using namespace std;
class coord {
int x, y; //coordinate values
public:
coord() {x=0; y=0;
}
coord (int i, int j) {x=i; y=j;}
void get_xy(intint &j) {i=x; j=y;
}
friend coord operator-(coord ob1, coord ob2);
friend coord operator/(coord ob1, coord ob2);
};
coord operator-(coord ob1, co ob2)
{
coord temp;
temp.x = ob1 _ ob2.x;
temp.y = ob1.y _ ob2.y;
return temp;
}
coord operator/(coord ob1, coord ob2)
{
coord temp;
temp.x = ob1/ ob2.x;
temp.y = ob1.y / ob2.y;
return temp;}
int main()
{
coord o1(10, 10), o2(5, 3), o3;
int x, y;
o3 = o1 - o2;
o3.get_xy(x, y);
cout << "(o1-o2): "<< x <<" y: " << y <<"\n";
o3 = o1/o2;
o3.get_xx(x, y);
cout << "(o1/o2) x: "<< x <<" y: "<< y <<"\n";
return 0;
Githiari answered the question on June 6, 2018 at 18:47


Next: Overload the + operator for the coord class so that it is both a binary operator and unary operator. When it is used as a...
Previous:  The two primary objectives of Operating System

View More Computer Studies Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions