#include <iostream>
using namespace std;
class Rational
{
public:
Rational() { x = 0; y = 1; }
Rational(int x, int y) { this->x = x; this->y = y; }
bool operator>(const Rational &p2) {
return this->x * p2.y > this->y * p2.x;
}
bool operator==(const Rational &p2) {
return this->x * p2.y == this->y * p2.x;
}
bool operator<(const Rational &p2) {
return this->x * p2.y < this->y * p2.x;
}
private:
int x, y;
};
int main()
{
Rational a(4,5), b(2,3);
cout<< "a>b? " << (a>b ? "true" : "false") << endl;
cout<< "a==b? " << (a==b ? "true" : "false") << endl;
cout<< "a<b? " << (a<b ? "true" : "false") << endl;
return 0;
}
Post Views: 6