Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Rational {
- public:
- Rational() = default;
- Rational(const Rational&) = default;
- Rational(const int num, const int denum = 1);
- Rational& operator=(const Rational&) = default;
- ~Rational() = default;
- int num() const;
- int denum() const;
- bool operator==(Rational& rhs) const;
- bool operator!=(Rational& rhs) const;
- bool operator>(Rational& rhs) const;
- bool operator>=(Rational& rhs) const;
- bool operator<(Rational& rhs) const;
- bool operator<=(Rational& rhs) const;
- Rational& operator+=(const Rational& rhs);
- Rational& operator+=(const int& rhs);
- Rational& operator-=(const Rational& rhs);
- Rational& operator-=(const int& rhs);
- Rational& operator/=(const Rational& rhs);
- Rational& operator/=(const int& rhs);
- Rational& operator*=(const Rational& rhs);
- Rational& operator*=(const int& rhs);
- std::ostream& writeTo(std::ostream& ostr) const;
- std::istream& readFrom(std::istream& istr);
- static const char sep {'/'};
- private:
- int _num {0};
- int _denum {1};
- void normalize();
- int gcd(int a, int b);
- };
- std::istream operator>>(std::istream istream, Rational& rhs);
- std::ostream operator<<(std::ostream ostream, const Rational& rhs);
- Rational operator+(Rational& lhs, Rational& rhs);
- Rational operator-(Rational& lhs, Rational& rhs);
- Rational operator*(Rational& lhs, Rational& rhs);
- Rational operator/(Rational& lhs, Rational& rhs);
- Rational operator+(Rational& lhs, int& rhs);
- Rational operator-(Rational& lhs, int& rhs);
- Rational operator*(Rational& lhs, int& rhs);
- Rational operator/(Rational& lhs, int& rhs);
- Rational operator+(int& rhs, Rational& lhs);
- Rational operator-(int& rhs, Rational& lhs);
- Rational operator*(int& rhs, Rational& lhs);
- Rational operator/(int& rhs, Rational& lhs);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement