Problem Description:
You are to write a four-function calculator which works on rational numbers. That is, given a command (+,-,*,/) and two fractions, your program is to perform exact arithmetic and print the rational result in lowest terms. The input will be in the form: 1/2 + 3/8, and the output shoud be: 1/2 + 3/8 = 7/8. All input numbers will be integers in the range -1000 .. +1000. There are no spaces between the numbers and the /. There is one space before and after the operator. The operator will be +,-,*, or /. In the ouptut there should be one space before and after the equal sign. The result must be in lowest terms. Zero is denoted by 0/1. The input is not necessarily in lowest terms. In the result, a negative number is shown by a negative numerator. Thus 3/12 - 4/8 = -1/4, 3/4 - 12/16 = 0/1, 1/2+ -4/3 = -5/6, and 1/2 * 4/-5=-2/5.
Input:
The input is from the file IN.TXT and consists of multiple lines, each lines contains one operation in the form given above.
Output:
The output should be in the
form given above, and should be one line for each line of input. The output
is to the file OUT.TXT
Sample Input:
3/12 - 4/8
3/4 - 12/16
1/2 + -4/3
1/2 * 10/5
5/6 / -3/-4
Sample Output:
**********************
* Team ##, Problem 2 *
**********************
3/12 - 4/8 = -1/4
3/4 - 12/16 = 0/1
1/2 + -4/3 = -5/6
1/2 * 10/5 = 1/1
5/6 / -3/-4 = 10/9