Lab assignment - due March 5, 1998

Write a fraction analyzer that is menu-driven just like your text editor. The choices are:

A - Add 2 fractions.

S - Subtract 2 fractions, hint: a/b - c/d is the same as : a/b + -c/d

M - Multiply 2 fractions.

D - Divide 2 fractions. Hint: a/b / c/d = a/b * d/c

R - Reduce a fraction (e.g., 9/12 reduces to ¾)

Q - Quit

You should write functions that do each of these operations (except quit). Each of these operations should return the numerator and denominator of the result fraction through the last 2 arguments in the argument list.

As an example:

case 'A': case 'a': // add 2 fractions

read_frac(n1, d1); // read 1st fraction

read_frac(n2, d2); //read 2nd fraction

add_two(n1, d1, n2, d2, nresult, dresult); //do addition

reduce(nresult, dresult); //reduce the result fraction

print_frac(nresult, dresult); //display fraction

You need to write all these functions and also multiply_frac.

Hint: to reduce a fraction, you need to find the greatest common divisor of its numerator and denominator (Use function gcd, p. 617) and divide the numerator and denominator by this number.