Beispiel #1
0
// task 10 == and !=
bool const operator ==(const CRational & firstNumber, const CRational & secNumber)
{
	return ((firstNumber.GetNumerator() == secNumber.GetNumerator())
		&& (firstNumber.GetDenominator() == secNumber.GetDenominator()));
}
Beispiel #2
0
void VerifyRational(const CRational & r, int expectedNumerator, int expectedDenominator)
{
	BOOST_CHECK_EQUAL(r.GetNumerator(), expectedNumerator);
	BOOST_CHECK_EQUAL(r.GetDenominator(), expectedDenominator);
}
Beispiel #3
0
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);
}
Beispiel #4
0
// 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);
}
Beispiel #5
0
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()));
}
Beispiel #6
0
//////////////////////////////////////////////////////////////////////////
// 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);
}
Beispiel #7
0
const bool operator == (const CRational &num1, const CRational &num2)
{
	return (num1.GetNumerator() == num2.GetNumerator() && num1.GetDenominator() == num2.GetDenominator());
}
Beispiel #8
0
//////////////////////////////////////////////////////////////////////////
// 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());
	}
Beispiel #10
0
bool const operator<(const CRational & rational1, const CRational & rational2)
{
	return rational1.GetNumerator() * rational2.GetDenominator() < rational1.GetDenominator() * rational2.GetNumerator();
}
Beispiel #11
0
bool const operator==(const CRational & rational1, const CRational & rational2)
{
	return rational1.GetNumerator() == rational2.GetNumerator() && rational1.GetDenominator() == rational2.GetDenominator();
}