#include "fraction.h" //------------------------------------------------------------------------ // fraction.cpp -- implementation of a Fraction class // //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Fraction::SetValue -- set the value of the fraction //------------------------------------------------------------------------ void Fraction::SetValue (int numerator, int denominator) { num = numerator; den = denominator; } //------------------------------------------------------------------------ // Fraction::GetValue -- get the approx. value of the fraction //------------------------------------------------------------------------ double Fraction::GetValue () { return ((double) num / (double) den); // typecasts force double division } //------------------------------------------------------------------------ // Fraction::Add -- add two fractions, return a new third fraction //------------------------------------------------------------------------ Fraction Fraction::Add (Fraction rhs) { Fraction retval; retval.SetValue (num * rhs.den + rhs.num * den, den * rhs.den); return retval; }