CSC 101 Programming Assignment 3

CSC 101 Programming Assignment 3:
Enhancements to Making Change
Using C++ Conditional Logic


Overview

This assignment is a variation of the change making program of Assignment 2. The program for this assignment computes from the perspective of the customer making the purchase as well as from the perspective of the place where the purchase is being made.

As with Assignment 2, the program starts by inputting the amount of a purchase. The program then inputs values for the amount of money in the purchaser's wallet (or pocket, or change purse, or whatever). Given these inputs, the program computes how the customer should pay for the purchase, based on the money available in the wallet. Finally, the program computes and outputs the total change due.

Specification

The program starts with the input of a real number in dollars and cents for the amount of purchase. The program then inputs eight integers, for the number of twenties through pennies in the wallet. The program then computes an amount tendered that is greater than or equal to the amount of purchase, based on the money available in the wallet. The amount tendered is output in the form of a list that indicates how many of each denomination of money from the wallet are to be paid out.

The amount tendered output must satisfy the following constraints:

  1. There is no extra of any denomination in the amount tendered. That is, for any denomination for which one or more of that denomination is tendered, there should be no change back in that denomination. For example, if the purchase price is $19.00, and there are three twenties in the wallet, only one of the twenties is tendered.
  2. The amount tendered output lists only those denominations that are non-zero.

There are no additional constraints on the amount tendered output. In particular, the output denominations do not have to be "sensible" in the way that a human might typically select them. For example, suppose the purchase amount is 25 cents, and the wallet contains a twenty, a one, and a quarter. In this case a human would typically consider the quarter as the "sensible" choice to be tendered. Your program does NOT have to choose sensibly in this way, as long as the above two constraints are met.

If the wallet contains insufficient funds to cover the amount of purchase, then the program outputs how far short of the purchase amount the available funds are; this output is a real number of dollars and cents, in two decimal places. If there are sufficient funds, then following the amount tendered output, the program outputs the total amount of change in dollars and fractional cents, to two decimal points of accuracy.

Here is are a couple sample runs of the program, the first with sufficient funds, the second without.



Sample 1:

Input the amount of the purchase, in dollars and cents: 56.92
Input eight integers for the numbers of twenties through pennies in the wallet:
    2 0 3 1 3 3 1 4

Amount tendered:
    2 twenties
    3 fives
    1 ones
    3 quarters
    2 dimes

Total change due: 0.03

Sample 2:

Input the amount of the purchase, in dollars and cents: 56.92
Input eight integers for the numbers of twenties through pennies in the wallet:
    1 1 0 6 3 3 1 4

The funds are insufficient to cover the purchase, by 19.78

Note that this program outputs only a single real number for the total change, NOT the change in the individual denominations as was done in Assignments 1 and 2. The reason for this is to keep the size of the program manageable. Also note that as in Assignments 1 and 2, the labels for each denomination are written in the plural spelling, even if only one of the denomination is output.

Program Design and Implementation Strategy

This program will probably end up being rather lengthy (250+ lines including comments). However, there is one key pattern of computation that is repeated with only minor alternation for each denomination of money. This computational pattern uses an if statement that is nested two or three levels deep and is about ten lines long. A good strategy for this assignment is to think about the algorithm for this computational pattern, code the pattern for one denomination of money, then reuse the same pattern for the remaining denominations.

Reading Resources

The C++ features necessary to complete this program are presented in Chapters 2, 3, and 5 of the textbook and Lecture Notes Weeks 2 and 3.

Program Turnin Procedure

Turn in one program for this assignment, named program3.cpp. Follow the normal turnin procedure, giving the name of this assignment as program3, name of program file as program3.cpp, and send to csc10101 if you are in the morning section or to csc10103 if you are in the afternoon section.



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