#include #include "genlib.h" #include "proj3.h" /* Numerator: Returns the numerator of the fraction */ int Numerator(fraction f) { return(f.top) ; } /* Denominator: Returns the denominator of the fraction */ int Denominator(fraction f) { return(f.bottom) ; } /* PrintFraction: prints out the fraction */ void PrintFraction (fraction f) { printf("%d/%d", f.top, f.bottom) ; } /* MakeFraction: Returns a fraction that has numerator and denominator as specified. Checks for zero denominator. If so, the function bombs. Checks that the denominator is not negative. If so, corrections are made. The return value is a reduced fraction. */ fraction MakeFraction(int numerator, int denominator) { fraction result ; /* Check for zero denominator */ if (denominator == 0) { Error("MakeFraction --- zero denominator!") ; } /* Check for negative numerator and/or negative denominator. if not normal form (neg num and pos denom) then correct signs */ if (numerator < 0 && denominator < 0) { numerator = - numerator ; denominator = - denominator ; } else if (numerator > 0 && denominator < 0) { numerator = - numerator ; denominator = - denominator ; } result.top = numerator ; result.bottom = denominator ; result = ReduceFraction(result) ; return(result) ; } /* OK, no more Mr. Nice Guy. The rest of the functions are for you to implement. */ fraction ReduceFraction (fraction f) { } fraction AddFraction (fraction f1, fraction f2) { } fraction SubtractFraction (fraction f1, fraction f2) { } fraction MultiplyFraction (fraction f1, fraction f2) { } fraction DivideFraction(fraction f1, fraction f2) { } bool EqualFraction(fraction f1, fraction f2) { } bool LessThanFraction(fraction f1, fraction f2) { }