hw12_03.cpp

#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; 
}

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

滚动至顶部