CSC 101 Programming Assignment 1

CSC 101 Programming Assignment 1:
Making Change


Program Specification

Write a C++ program that makes change, per the following specifications. The program inputs two integer values: the amount of a purchase and an amount tendered. Both inputs are in cents. The program outputs the total amount of change due, which is the difference between the amount tendered and the purchase amount. Following the total change value, the program outputs the change in five specific denominations of money: dollars, quarters, dimes, nickels, and pennies. The change in these dominations is computed to be the maximum whole number of units in each denomination that add up to the total change due.

The program may assume the following:

  1. The inputs are correctly entered as positive integer values.
  2. The amount tendered is greater than or equal to the purchase amount.

Here is a sample run of how the program must behave given a purchase amount of 216 (i.e., $2.16) and an amount tendered of 500 (i.e., $5.00):


Input the amount of the purchase, in cents: 216
Input the amount tendered, in cents: 500

Total change due = 284

Change in dollars through pennies is:
    2 dollars
    3 quarters
    0 dimes
    1 nickels
    4 pennies

Your program must prompt for input and write output in precisely the same format as this sample. Note that you do not need to worry about ungrammatical plurals in the output. E.g., the output "1 nickels" is correct for this program, even though the more correct English output would be "1 nickel".

Program Testing

Test your program with enough sample inputs to convince yourself that it works properly. In providing test inputs, you may rely on assumptions a and b above to be true. Therefore, you need not test your program with inputs that are negative values, or with inputs where the amount tendered is less than the purchase amount. In upcoming assignments, we will learn how to enhance the change-making program to check for these anomalous input conditions, and output appropriate error messages when the conditions are detected.

Program Structure and a Program Temple to Work From

The program must be written per the conventions defined in the handout CSC 101 Programming Conventions, Volume 1.

This program is sufficiently small that it can be written all within a single C++ main function. Therefore, no additional functions other than main need to be defined. You should note that this is the first and last time that your programs will be small enough to fit entirely within one main function.

Since this is your very first programming assignment, we are giving you a template that outlines the structure of the program, including the in-line comments that define the program's algorithm. Your specific job for this assignment is as follows:

  1. Fill in the asked-for information in the four places where the words "FILL IN" appear in the program template. When you have done the fill in, delete the "FILL IN ..." remarks themselves.
  2. Fill in all necessary C++ code following each of the in-line comments in the body of the main function. This is the code that will implement the program to make it run as specified.
Here is the code template for you to work from:
////
//
// FILL IN a description of what the program does, per conventions.
//
// Author: FILL IN your name followed by your email address in parentheses
// Created: FILL IN the initial creation date of this file
// Modified: FILL IN the date the file was last modified (before turnin)
//
////

#include <iostream.h>

int main() {

    //
    // Declare program variables to hold the purchase amount, amount tendered,
    // total change amount, and the amounts of each denomination of change,
    // from dollars to pennies.  (Don't forget the variable comments.)
    //

    //
    // Prompt the user for the amount of purchase.
    //


    //
    // Input the amount of purchase.
    //


    //
    // Prompt for the amount tendered.
    //


    //
    // Input the amount tendered.
    //


    //
    // Output a blank line, for nice formatting.
    //


    //
    // Compute the total amount of change due, in cents.  Assume that this
    // value is non-negative.
    //


    //
    // Output the total change amount, followed by a blank line.
    //


    //
    // Compute the number of dollars in change by dividing the total change by
    // 100.
    //


    //
    // Compute the remaining amount of change by subtracting the amount of
    // change in dollars from the total change.
    //


    //
    // Proceed in the same way as for dollars with quarters, dimes, nickels,
    // and pennies.  (Note: this step takes several lines of code).
    //


    //
    // Output the results of the pieces of change computations.  (Note: this
    // step takes several lines as well.)
    //

}
The easiest way to begin your work is to copy this file from

~gfisher/classes/101/assignments/program1-template.cpp

to the file program1.cpp in your csc101 directory. Note well that your file for this assignment must be named "program1.cpp" NOT program1-template.cpp". Hence, you must know enough UNIX to change the name of a file.

Reading Resources

All of the C++ features necessary to complete this program are presented in Chapter 2 of the textbook, except for the cin operator, which is covered at the beginning of Chapter 4, on pages 132-136. This program only requires the most basic form of cin, so you need not read beyond the middle of page 136.

Grading Criteria

Your program will be graded with a raw score of 100 points, broken down as follows:


Program Feature           Points
------------------------+-------------------------------
Correct compilation     | 30
Correct output          | 45
Correct documentation   | 25
  top-level comment     |   12
  variable comments     |   5
  in-line code comments |   8      (these comments are
                        |          provided for you in
                        |          the template, so you
                        |          get these 8 points
                        |          for free)

Note that in terms of the grading scheme presented in the course syllabus, this point breakdown means that a completely undocumented program is worth at best a "C" grade.

Program Turnin Procedure

For this and all future programming assignments, you will use the UNIX turnin command on polylog1. When you run turnin, it will prompt you for information about what you're turning in. Here is a sample that shows exactly how to respond to turnin for this assignment. The text you will type is in shown in boldface. Note: mail to csc10101 if you're in the morning section or csc10103 if you're in the afternoon section.

Enter the name of this assignment > program1

Enter the e-mail address of the instructor or class account that
you wish to mail this assignment to > csc10101 -or- csc10103

Enter the name of the file to be included.
Enter return when done > program1.cpp

Enter the name of the file to be included.
Enter return when done >

Your assignment has been sent.  If you do not receive a confirmation
in the next 30 minutes, please contact your instructor

In order for all of this to work properly:

  1. the file containing your solution for programming assignment 1 must be named "program1.cpp"
  2. you must be in the UNIX directory containing program1.cpp when you run turnin
  3. you must type all inputs to turnin correctly, noting in particular the email address csc101gf, which must be spelled exactly this way, with all letters in lower case
  4. you must type only return (i.e., Enter) in response to the second prompt "Enter the name of the file ... "


index | lectures | labs | handouts | assignments | solutions | grades | help