Get types to line up and add this keyword

main
Micke Nordin 2 years ago
parent 9dc0fc008c
commit 6a8035dd74
Signed by: micke
GPG Key ID: 014B273D614BE877

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

Loading…
Cancel
Save