CIS 501
Spring, 2003

Assignment Number 01

Using Classes: Money, Strings, and Streams

Reading: Part A of the Syllabus. See also the hand out material for the first day of classes.

Programming: This assignment is in four parts. They are to be done individually. Feel free to discuss your ideas with others, but write the programs on your own.

  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 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. 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.)

    NOTE: For problems 1 and 2, write a short driver program and a function that does all the work. The program will not do much other than call the function and print a message when done.

  3. Given the results illustrated in Part 1 and 2, 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 mechanism for representing and manipulating money -- perhaps as dollars and cents?

    Devise such a new mechanism. In other words – what might be a more effective way to represent money -- one that I could program. Tell me how I might go about building a new data type to represent your improved version of money. For example:

    1. How should I store the necessary data 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.?
    5. In what form(s) would you like to be able to read in values for your new money type? (What sort of flexibility would you like to have for your input operations?)

    Turn In: For Parts 1 and 2 just turn in the two programs (no documentation is needed). For Part 3., present a concise, precise discussion, perhaps in list form, to tell me exactly what I would need to program.

  4. Do the Programming Project below. Test your program on data samples of around a dozen records. Construct your own data file.

    Project: Write a program to compute a numeric total score and a letter grade for each student in this course. The file is in the following format:

    For each line (data record) we have:

    Each data element in a line is separated from the other elements by one or more blanks. Each exam score and the homework grade are represented by an integer between 0 and 100. Each quiz score is represented by an integer between 0 and 10. The Exam, Homework, and Quiz scores may appear in any order following the student’s first name.

    NOTE: The homework grade counts 25% of the grade; each exam score counts 15%, and the quiz scores (taken together) count 30%. Be sure to verify that all input data is correct. If any single input item for a student is incorrect, generate a "data error" message and ignore that student record. HINT: Mark end of lines with a special symbol like #. WHY?

    Your output for each student should appear exactly as the input except that the names should be left adjusted and the numeric data should be right adjusted so as to produce nice, neat columns. Two other data elements should appear on each line: the total weighted score, and a letter grade such as A, A-, B+, B, B-, …, D, D-, F. Be sure to properly annotate your output with a nice header indicating the name and number of the course, the instructors name, and the days and time of the course. Meaningful headers above the columns would also be helpful.

    NOTE: The maximum weighted total score is 100. The mapping of total scores to letter grades is as follows:


    A 92-100
    A- 90- 91
    B+ 88- 89
    B 82- 87
    B- 80- 81
    ... D+ 68- 69
    D 62- 67
    D- 60- 61
    F 59 or less
    Due Dates:
    1) E-mail me Parts 1, 2, and 3 of Assignment 1 by noon Thursday, January 30.
    2) E-mail me the Preliminary Assignment by noon Monday, February 3.
    3) Part 4 of Assignment 1 is due noon Monday, February 10.