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

Relative to coord, overload the * and / operators. Demonstrate that they work.

      

Relative to coord, overload the * and / operators. Demonstrate that they work.

  

Answers


Davis
// Overload the * and / relative to coord class.
#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(int &i, int &j) {i=x; j=y;}
coord operator*(coord ob2);
coord operator/(coord ob2);
};
// Overload * relative to coord class.
coord coord::operator*(coord ob2)
{
coord temp;
temp.x = x * ob2.x;
temp.y = y * ob2.y;
return temp;
}
//Overload / relative to coord class.
coord coord::operator/(coord ob2)
{
coord temp;
temp.x = x / ob2.x;
temp.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: " << x <<", y: " << y << "\n";
o3= o1 / o2;
o3.get_xy(x,y);
cout << "(o1/o2) x: " << x <<" y: " << y << "\n";
return 0;
}
Githiari answered the question on May 31, 2018 at 17:53


Next: Other than spreadsheets, describe how modern technology can be used by the finance department.
Previous: Why would the following be an inappropriate use of an overloaded operator?coord coord:: operator%(coord ob) {double i;cout << "Enter a number:";cin >>i;cout << "root of...

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


Learn High School English on YouTube

Related Questions