Rational.h 883 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef _RATIONAL_
  2. #define _RATIONAL_
  3. #include <iostream>
  4. using namespace std;
  5. class Rational {
  6. public:
  7. int num;
  8. int denum;
  9. Rational();
  10. Rational(int num1, int num2);
  11. Rational& operator *=(const Rational& r);
  12. Rational operator *(const Rational& r) const;
  13. Rational& operator += (const Rational& r);
  14. Rational operator + (const Rational& r) const;
  15. Rational& operator -= (const Rational& r);
  16. Rational operator - (const Rational& r) const;
  17. Rational operator / (const Rational& r) const;
  18. Rational& operator /= (const Rational& r);
  19. operator int () const;
  20. operator double() const;
  21. friend ostream& operator <<(ostream& out, const Rational& r);
  22. private:
  23. // упрощение самого себя
  24. void simple();
  25. // НОК
  26. int lcm(int num1, int num2);
  27. // НОД
  28. int gcd(int num1, int num2);
  29. };
  30. #endif