CIS 083
Assignment Number 02-S98

Using Classes: Money, Strings, and Streams

Reading: Part B of the Syllabus. See also, Sections 2.4 and 3.7 of the Friedman/Koffman text (2nd Edition).

Programming: Four small programs are required. They are to be done individually. Feel free to discuss your ideas with others, but write the programs on your own.

PART I -- (Individual -- no groups)

A. Two short programs:

  1. Write a program to add the value 0.1 (representing 10 cents) to itself 100,000 times. Represent all data in type float. Then redo the problem representing all data as type double. Print only the initial value and the final result. Is the result what y ou 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. Again, keep all data in type float. Do not bother to redo using type double. (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 type money values times a type float value? Can you think of any real-life situation where you might want to multiply one money value times another? Justify your answer.
  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 descriptions (with pseudo-code algorithms as needed for 2. and 3.) of what I am supposed to do. For Part B, among other things, I n eed to know exactly how to add two type money data elements and how to multiply a money type element times a float type element.

Due Date: No later than Tuesday, February 3 (in class).

PART II (Individuals, no groups)

Read carefully Chapter 5 in Savitch's text [and look over Appendix C (also on Stream I/O) in Headington and Riley].

Do Programming Project Number 8 (p. 276 in Savitch's book)

Turn In: Working versions of the programs for Project Number 8 (no documentation is needed). Test your programs on data samples of around a dozen records. You should construct your own data file and you may assume there are no errors in your fil e.

Due Dates: Friday, February 6 at noon (handed in to the lab instructor).