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());
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);

Loading…
Cancel
Save