Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int gcd (int a, int b) {
- if (b == 0) {
- return a;
- } else {
- return gcd (b, a % b);
- }
- }
- class Rational {
- private:
- int x, y;
- public:
- Rational(int a = 0, int b = 1): x(a), y(b) {
- standart();
- }
- int numerator() const {
- return x;
- }
- int denominator() const {
- return y;
- }
- int& num() {
- return x;
- }
- int& den() {
- return y;
- }
- void standart() {
- if (y < 0) {
- y = -y;
- x = -x;
- }
- int g = gcd(std::abs(x), std::abs(y));
- x /= g;
- y /= g;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement