#include "Fraction.h" bool Fraction::read() { std::cin >> numerator >> denominator; simplify(); return std::cin.good(); } bool Fraction::simplify() { long long common = gcd(); numerator /= common; denominator /= common; if ( denominator < 0 ) { numerator *= -1; denominator = -denominator; } return common > 1; } long long Fraction::gcd(long long a, long long b) { a = a >= 0 ? a : -a; b = b >= 0 ? b : -b; while ( b > 0 ) { long long t = b; b = a % b; a = t; } return a; } Fraction Fraction::add(const Fraction& other) const { return Fraction( this->numerator * other.denominator + denominator * other.numerator , denominator * other.denominator); } Fraction Fraction::operator*(const Fraction& other) const { return Fraction( numerator * other.numerator, denominator * other.denominator); } // } // namespace ecci