123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include <iostream>
- #include <algorithm>
- #include "Rational.h"
-
- using namespace std;
-
-
- Rational::Rational() {
- num = 0;
- den = 1;
- }
-
- Rational::Rational(int n, int d) {
- num = n;
- den = d;
- }
-
- void Rational::reduce() {
- int g = __gcd(num,den);
- num /= g;
- den /= g;
- }
-
- Rational Rational::sum(const Rational &b) const {
- return Rational(num * b.den + den * b.num, den * b.den);
- }
-
- bool Rational::gt(const Rational &b) const {
- /*
- if (num * b.den > den * b.num) {
- return true;
- }
- else {
- return false;
- }
- */
- return num * b.den > den * b.num;
-
- }
-
-
- void Rational::display() const {
- cout << num << " / " << den << endl;
- }
|