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

Overload the < and > operators relative to the coord class.

      

Overload the < and > operators relative to the coord class.

  

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; int operator<(coord ob2);
int operator>(coord ob2);
};
//Overload the < operator for coord.
int coord::operator <(coord ob2)
{
return x}
//Overload the > operator for coord.
int coord::operate >(coord ob2)
{
return x>ob2.x && y>ob2.y;
}
int main()
{
coord o1(10, 10), o2(5, if(o1>o2) cout << "o1 > o2\n";
else cout << "o1 <= o2\n";
if(o1else cout << " o1 >= o2\";
return 0;
}
Githiari answered the question on June 8, 2018 at 17:55


Next: Explain the politcal successes of United Nations
Previous: Overload the -- operator for the coord class. Create its both prefix and postfix forms

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


Learn High School English on YouTube

Related Questions