// Class for rational numbers. #include using namespace std; #ifndef rational #define rational class Rational { friend ostream &operator<<(ostream&, const Rational&); friend istream &operator>>(istream&, Rational&); public: Rational(const int = 0, const int = 1); // Rational default constructor. Rational(const int &); // Rational constructor for an integer. Rational(const Rational&); // Copy constructor. void setRational(const int, const int); // Set new values to a rational object. int getNumerator() const; // Get Numerator. int getDenominator() const; // Get Denominator. Rational operator-() const; // Rational unary minus. Rational operator+(const Rational &) const; // Rational addition. Rational operator-(const Rational &) const; // Rational substraction. Rational operator*(const Rational &) const; // Rational multiplication. Rational operator/(const Rational &) const; // Rational division. bool operator==(const Rational &) const; // Equal relation for rational numbers. bool operator!=(const Rational &) const; // Not equal relation for rational numbers. bool operator<(const Rational &) const; // Less than relation for rational numbers. bool operator>(const Rational &) const; // Greater than relation for rational numbers. bool operator<=(const Rational &) const; // Less than or equal to relation for rational numbers. bool operator>=(const Rational &) const; // Greater than or equal to relation for rational numbers. Rational &operator=(const Rational &); // Assignment. Rational &operator+=(const Rational &); // Assignment with addition. Rational &operator-=(const Rational &); // Assignment with substraction. Rational &operator*=(const Rational &); // Assignment with multiplication. Rational &operator/=(const Rational &); // Assighment with division. Rational rabs(void) const; // Absolute value of rational numbers. private: int nume; // numerator (¤À¤l) int deno; // denominator (¤À¥À) int gcd(int, int); // GCD: greatest common divisor. Rational &simplify(); // Simplify a rational number. }; #endif