// task 10 == and != bool const operator ==(const CRational & firstNumber, const CRational & secNumber) { return ((firstNumber.GetNumerator() == secNumber.GetNumerator()) && (firstNumber.GetDenominator() == secNumber.GetDenominator())); }
void VerifyRational(const CRational & r, int expectedNumerator, int expectedDenominator) { BOOST_CHECK_EQUAL(r.GetNumerator(), expectedNumerator); BOOST_CHECK_EQUAL(r.GetDenominator(), expectedDenominator); }
void VerifyCompoundFraction(const CRational &r, int expectedInteger, int expectedNumerator, int expectedDeniminator) { BOOST_CHECK_EQUAL(r.ToCompoundFraction().first, expectedInteger); BOOST_CHECK_EQUAL(r.ToCompoundFraction().second.GetNumerator(), expectedNumerator); BOOST_CHECK_EQUAL(r.ToCompoundFraction().second.GetDenominator(), expectedDeniminator); }
// task 7 / CRational const operator /(const CRational & firstNumber, const CRational & secNumber) { int numerator = firstNumber.GetNumerator() * secNumber.GetDenominator(); int denominator = firstNumber.GetDenominator() * secNumber.GetNumerator(); return CRational(numerator, denominator); }
const bool operator > (const CRational &num1, const CRational &num2) { const unsigned lcm = LCM(num1.GetDenominator(), num2.GetDenominator()); return (num1.GetNumerator() * (lcm / num1.GetDenominator()) > num2.GetNumerator() * (lcm / num2.GetDenominator())); }
////////////////////////////////////////////////////////////////////////// // TODO: 4. Реализовать бинарный - const CRational operator - (const CRational &num1, const CRational &num2) { const unsigned lcm = LCM(num1.GetDenominator(), num2.GetDenominator()); return CRational(num1.GetNumerator() * (lcm / num1.GetDenominator()) - num2.GetNumerator() * (lcm / num2.GetDenominator()), lcm); }
const bool operator == (const CRational &num1, const CRational &num2) { return (num1.GetNumerator() == num2.GetNumerator() && num1.GetDenominator() == num2.GetDenominator()); }
////////////////////////////////////////////////////////////////////////// // TODO: 8. Реализовать оператор / const CRational operator / (const CRational &num1, const CRational &num2) { return CRational(num1.GetNumerator() * num2.GetDenominator(), num2.GetNumerator() * num1.GetDenominator()); }
void CheckEquality(CRational const &num1, CRational const &num2) { BOOST_CHECK_EQUAL(num1.GetNumerator(), num2.GetNumerator()); BOOST_CHECK_EQUAL(num1.GetDenominator(), num2.GetDenominator()); }
bool const operator<(const CRational & rational1, const CRational & rational2) { return rational1.GetNumerator() * rational2.GetDenominator() < rational1.GetDenominator() * rational2.GetNumerator(); }
bool const operator==(const CRational & rational1, const CRational & rational2) { return rational1.GetNumerator() == rational2.GetNumerator() && rational1.GetDenominator() == rational2.GetDenominator(); }