CIS 223
Assignment Number 2-S97

Money Examples and The Fractions Problem

Reading: Part B of the Syllabus. Also -- for Project II, you will find it helpful to examine some code (example code for money and fractions classes) that made available to you on the WWW.

Programming: Two projects. One individual and one group.

PROJECT I -- (Individual -- no groups)

A. Two short programs:
  1. Write a program to add the value 0.1 (representing 10 cents) to itself 10,000 times. Print only the initial value and the final result. Is the result what you expected? Explain?

  2. Write a program to compute and print successive powers of the fraction 1/2, starting with 1/2 raised to the zero power and continuing until 1/2 to the 999th power is computed OR until some power k is reached such that 1/2 to the kth power equals zero. (All you mathematicians in the house -- is the result what you expected? Explain.)
B. Given the results illustrated in Part A., perhaps we need a better way to handle money in C++. It appears as though the use of floating point values may not do the job -- perhaps we will lose some pennies along the way? We need to come up with a new scheme for representing and manipulating money -- perhaps as dollars and cents?

Devise such a new scheme -- one that I could program once you tell me what to do. In particular, tell me the following:

  1. How should I store the necessary value(s) representing a money value?
  2. What sort of an algorithm will I need to add together two money values?
  3. What sort of an algorithm will I need to multiply a money value times some other floating point value? (Can you think of any real ;life situation where you might want to multiply one money value times another?)
  4. How would you like me to display values of type money? For example -- with a dollar sign in front? With commas (as in $27,895.84) etc.?

Turn In: For Part A., just turn in the two programs (no documentation is needed). For Part B., turn in an English description (with pseudo-code algorithms as needed) of what I am supposed to do. For Part B, among other things, I need to know exactly how to add to type money data elements and how to multiply a money type element times an integer (or a float) type data element.

Due Date: Tuesday, February 11 (in class).

PROJECT II (To Be Done in Groups)

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) of arithmetic using fractions.

We need to write an interactive program that prompts the young 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, and you might even give them the pleasure of typing in their initials (max of three) at the very start and welcoming them to your “All About Fractions Program.”

Once the two fractions have been entered, prompt the user to enter the sum and then the product of the two fractions. These results MUST APPEAR AS FRACTIONS REDUCED TO LOWEST TERMS -- DO 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 values 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. Compute sum and product results in “lowest term fractions” -- that is, as fractions with numerators and denominators for which there are no common divisors. You will have to write a recursive 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 take advantage of this restriction anywhere in your program.

COMMENTS: If Parts A. and B are not carefully planned out you may never get them to work. The better your decomposition, the easier the task. There is no substitute for starting early and meeting often up until all components, their responsibilities and interfaces are agreed to and documented. You will want to devise a class (for a new data type called fraction) that handles, among other things, extraction, insertion, addition, and multiplication operations defined on fractions.

Turn In: Data Requirements Tables for each component of your program, and a Program Structure Chart. Also, turn in a compiled, working program and output. A personal one page statement as discussed below (see NOTE 1).

Due Dates: By Friday, February 21 at 4:30pm. The assignments should be slid under the door of the lab assistant’s office.

NOTE 1: If things work out right, you will have some class time to work on this problem. Remember -- each of you has a substantial responsibility to the other members of your group.

If you put in some quality time as a group working on the design of the program and allocating the work on the four main components to team members, you should have a much easier time. In a sense, each member of the group is making a contractual agreement with the other members. This agreement contains a complete description of WHAT each component will do but not HOW it will do it. In other words, you each agree on the services to be provided by your component to the other members of your team. And, of course, you each will need to provide the others with complete interfaces to your functions.

THIS IS A GROUP PROJECT. WE WILL TALK FURTHER IN CLASS ABOUT HOW TO SPLIT UP THE VARIOUS TASKS, AS WELL AS ABOUT ISSUES OF COMMUNICATION AMONG THE MEMBERS OF THE GROUP. WHEN YOUR GROUP TURNS IN ITS PROJECT, EACH OF YOU WILL BE RESPONSIBLE FOR YOUR OWN PERSONAL ONE PAGE REPORT ASSESSING THE POSITIVE AND NEGATIVE ASPECTS THE GROUP APPROACH AND WHAT YOU HAVE LEARNED FROM THIS APPROACH.

You should try to be as professional yet honest as you know how to be when you write your report. You may wish to keep a log of your experiences in working with your group as use this log to help formulate you report. Please note carefully: the one page report is NOT intended as documentation of the software system you produced. Rather it is intended as a record of:

NOTE 2: By Friday, Tuesday, February 14 (in class) you should turn in to me a complete breakdown of the components of the project together with an assignment as to who is to do what and when this work is to be completed. This is essentially your contract with each other and you all need to agree to it and stick with it.

Return to Previous Page