inline void Fraction::UnifyDenominators(Fraction& p_first, Fraction& p_second)
		{
			if (p_first.m_denominator == p_second.m_denominator)
			{
				return;
			}

			int firstNumerator = p_first.m_numerator;
			int firstDenominator = p_first.m_denominator;

			p_first.SetNumerator(firstNumerator * p_second.m_denominator);
			p_first.SetDenominator(firstDenominator * p_second.m_denominator);

			p_second.SetNumerator(p_second.m_numerator * firstDenominator);
			p_second.SetDenominator(p_second.m_denominator * firstDenominator);
		}
示例#2
0
const Fraction operator*(const Fraction& term1, const Fraction& term2) {
	//Turned into improper fractions and then mulitplied through
	Fraction result;
	result.SetNumerator(((term1.GetWhole() * term1.GetDenominator()) + term1.GetNumerator()) * ((term2.GetWhole() * term2.GetDenominator()) + term2.GetNumerator()));
	result.SetDenominator(term1.GetDenominator() * term2.GetDenominator());
	result.Normalize();
	
	return result;
}
示例#3
0
const Fraction operator/(const Fraction& term1, const Fraction& term2) {
	//Multiplies by the reciprocal of term2
	Fraction result;
	result.SetNumerator(((term1.GetWhole() * term1.GetDenominator()) + term1.GetNumerator()) * term2.GetDenominator());
	result.SetDenominator(term1.GetDenominator() * ((term2.GetWhole() * term2.GetDenominator()) + term2.GetNumerator()));
	result.Normalize();
	
	return result;
}