diff --git a/fractions.hpp b/fractions.hpp index e830627..6e11858 100644 --- a/fractions.hpp +++ b/fractions.hpp @@ -23,7 +23,7 @@ private: s.erase(i + 1, s.length()); bool point = false; int count = 0; - for (int i = 0; i < s.length(); i++) { + for (long unsigned i = 0; i < s.length(); i++) { if (s[i] == '.') { point = true; } else { @@ -69,10 +69,11 @@ public: n = q.n; d = q.d; } + ~fraction() {} // Member functions int get_sign() const { return (!(n >= 0) != !(d >= 0)) ? -1 : 1; } - signed long long get_n() const { return n; } - signed long long get_d() const { return d; } + signed long long get_n() const { return this->n; } + signed long long get_d() const { return this->d; } double to_double() const { double dec = (double)n / (double)d; return dec; @@ -132,17 +133,17 @@ public: return os; } void operator=(const fraction &q) { - n = q.n; - d = q.d; + this->n = q.n; + this->d = q.d; } void operator=(const int i) { - n = (signed long long)i; - d = (signed long long)1; + this->n = (signed long long)i; + this->d = (signed long long)1; } void operator=(const double dec) { const fraction q(dec); - n = q.n; - d = q.d; + this->n = q.n; + this->d = q.d; } bool operator>(const fraction &q) const { signed long long hcf = gcd(d, q.d); @@ -155,7 +156,7 @@ public: return (*this > q); } bool operator==(const fraction &q) const { - return ((n == q.n) && (d == q.d)); + return ((this->n == q.n) && (this->d == q.d)); } bool operator==(const int i) const { fraction q(i);