Rational.h 948 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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(float num);
  11. Rational(int num1, int num2);
  12. Rational& operator *=(const Rational& r);
  13. Rational operator *(const Rational& r) const;
  14. Rational& operator += (const Rational& r);
  15. Rational operator + (const Rational& r) const;
  16. Rational& operator -= (const Rational& r);
  17. Rational operator - (const Rational& r) const;
  18. Rational operator / (const Rational& r) const;
  19. Rational& operator /= (const Rational& r);
  20. operator int () const;
  21. operator double() const;
  22. friend ostream& operator <<(ostream& out, const Rational& r);
  23. private:
  24. // упрощение самого себя
  25. void simple();
  26. // НОК
  27. int lcm(long long int num1, long long int num2);
  28. // НОД
  29. int gcd(long long int num1, long long int num2);
  30. };
  31. #endif