CIS 067 Section 1

Assignment Number 04-F2001

          

The Fractions Problem

(without classes – an exercise in argument passing)

 

Reading: Complete the reading required to take you to Exam I.

 

Programming: This program needs to be carefully modularized and the components clearly documented, each component on a separate page:

n       Data Table and Structure Chart for Main

n       Data Table (with function interfaces and local variables) for all other functions

n       Basic algorithm outlines for all functions.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

Your little sister or brother (or a young neighbor or cousin) is having trouble learning about fractions. So you are going to write a program to help them learn the rules (or at least some of them) for addition and multiplication using fractions. 

 

We need to write an interactive program that prompts the user to enter two fractions in the form n / d, where n, the numerator, and d, the denominator, are both single-digit integers. Each fraction must be entered on a separate line.  (You might give the user the pleasure of typing in their first name at the very start and welcoming them to your "All About Fractions Program.")  All input is limited single digit fractions such as 3 / 4 and 9 / 2.

 

Once the user has entered two fractions of the form n1 / n2, prompt the user to enter the sum and then the product of the two fractions. Their answers MUST APPEAR AS FRACTIONS REDUCED TO LOWEST TERMS - THEY SHOULD NOT USE DECIMAL NUMBERS SUCH AS .5, or .333, or .1, etc. If the user gets the sum and product of the two fractions correct, congratulate them and stop execution. If not, provide an encouraging message and give the correct answer as needed.

 

Your program should be written to do the following:

1. Repeat the above process until a 0 / 0 pair is entered, at which point the program should display a message and stop.

2. Check the three data values (int char int) n / d entered for each fraction to ensure they are valid and ask the user to re-enter any fraction n / d if either n, /, or d is incorrect. Continue to prompt the user until both fractions have been correctly entered. 

3. To carry out the above task, YOUR program must compute the sum and product results in "lowest term fractions" -- that is, as fractions with numerators and denominators for which there are no common divisors. We will give you a function gcd which, given two integers, n1 and n2, returns the greatest common divisor of these values.

 

NOTE: The fact that the n and d are single digit integers is relevant ONLY for the validation step. Otherwise, you should not need to worry about this restriction anywhere in your program.

 

COMMENTS: If this project is not carefully planned out you may never get it to work. The better your decomposition, the easier the task.

 

Turn In: To be decided, but probably due Wednesday Oct 3 at 4pm.