
Comp 150 / 170 Lab: Fraction Calculator Page 1 of 6
The goal of this lab is to give you more practice in using functions that return values through the return statement and
through the parameter-list. You will complete a program that implements a simple fraction calculator. When the program is
completed it should run according to the example below.
Add, subtract, multiply & divide โ positive fractions only
Enter โ0/0 + 0/0โ to quit.
>1/2 + 3/4
2/4 + 3/4 = 5/4
>2/16 + 29/32
4/32 + 29/32 = 33/32
> 1/7 + 1/5
5/35 + 7/35 = 12/35
>1/2 โ 1/3
3/6 โ 2/6 = 1/6
>200/100 * 25/50
2/1 * 1/2 = 1/1
>1/2 * 3/4
1/2 * 3/4 = 3/8
>1/2 / 3/4
1/2 / 3/4 = 2/3
>0/0 + 0/0
Note that the program will add, subtract, multiply, and divide positive fractions only. For subtraction, the lager fraction must
be given first so that the answer will be positive also. All answers will be fractions in lowest terms. For purposes of
simplifying this assignment, a whole number such as 5 will be written as 5/1.
On the second page is a structure chart that show how the functions that you will write will be called by one another. Also
given are some diagrams that illustrate what each of the four missing functions is to do. On the third page is a brief
description for each function that restates in English what the diagrams are saying. Pages 4 & 5 contain flowcharts for the
GCD (Greatest Common Divisor) and LCM (Least Common Multiple) algorithms. Page 6 contains the code for the main
function of fraction.cpp that is available at \\cs1\Classes\Comp170\fraction.cpp. Copy this file to your computer so that you
can complete the program.
This lab will be due at the beginning of the next class period. Complete the four functions and submit your working program
to Easel (http://cs.harding.edu/easel/). Make sure your name and date are documented at the top of the program.