|
|
@ -34,10 +34,10 @@ class fraction {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
// Constructors
|
|
|
|
// Constructors
|
|
|
|
fraction() {
|
|
|
|
fraction() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
fraction(const fraction &q) {
|
|
|
|
fraction(const fraction &q) {
|
|
|
|
signed long long hcf = gcd(q.n, q.d);
|
|
|
|
signed long long hcf = gcd(q.n, q.d);
|
|
|
|
n = q.n / hcf;
|
|
|
|
n = q.n / hcf;
|
|
|
@ -70,15 +70,9 @@ class fraction {
|
|
|
|
d = q.d;
|
|
|
|
d = q.d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Member functions
|
|
|
|
// Member functions
|
|
|
|
int get_sign() const {
|
|
|
|
int get_sign() const { return (!(n >= 0) != !(d >= 0)) ? -1 : 1; }
|
|
|
|
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 n;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
signed long long get_d() const {
|
|
|
|
|
|
|
|
return 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;
|
|
|
|