Lab 4-1 - Count CoinsDue: Feb 22, 11:55pm |
Requirement | Grading Comments | Points | Score |
---|---|---|---|
Run examples with correct output on required trial data | 25 | ||
Good clean, easy to understand input and output operations | 5 | ||
Code is correctly implements the computeCoins function | 15 | ||
Complete source code with good formatting and organization, variables names, and comments | 5 | ||
Total | 50 |
This is a very simple program. It is merely a main function that calls the computeCoin function. The trick is that you MUST follow a "specification" (given below) to write the computeCoin function to work exactly as the the comments in the declaration below specify. The learning goals here are:
Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and half-dollar coins. Your program will use a function that meets the following specifications. The idea is that you are being asked to write a specific function computeCoins, that is a general purpose function that when given a coin value coinValue (25, 10, or 1 in this case), and an amount of change remaining amountLeft, will return the quantity of that coin that should be given as change in the cal-by-reference parameter number, and will update the amount left in the call-by-reference parameter amountLeft to be the amount left AFTER subtracting the number * coinValue quantity from the amountLeft.
void computeCoins(int coinValue, int& number, int& amountLeft); //Precondition: 0 < coinValue < 100; 0 <= amountLeft < 100. //(CoinValue will always be 25, 10, or 1 for this project) //Postcondition: number has been set equal to the maximum number of coins of //denomination coinValue cents that can be obtained from amountLeft //amountLeft has been decreased by the value of the coins to be returned, that is, //amountLeft is decreased by number*coinValue.
For example, suppose the value of the variable amountLeft is 86 . Then, after the following call, the value of number will be 3 (for 3 quaters) and the value of amountLeft will be 11 (because when you take 3 quarters from 86 cents, this leaves 11 cents):
amountLeft = 37; computeCoins(25, number, amountLeft); cout << "Quarters to return:" << number << " with " << amountLeft << "cents remaining." << endl;
The above sample code would return:
Quarters to return: 1 with 12 cents remaining.
So - once you have written the function computeCoins, you will write a main program that uses computeCoins to figure out the change for an given amount entered by the user. It will need to call computerCoins several times to do this correctly.
Note that computeCoins will NOT do any input or output (e.g. cin or cout). This will all be done in the main program.
Include a loop in your program that lets the user repeat this computation for new input values until the user says he or she wants to end the program.
Enter the amount of money between 1 and 99 cents: 62 Quarters: 2 Dimes: 1 Pennies: 2 go again? (y to continue):y Enter the amount of money between 1 and 99 cents: 23 Quarters: 0 Dimes: 2 Pennies: 3 go again? (y to continue):y Enter the amount of money between 1 and 99 cents: 133 Amount must be between 1 and 99 cents Enter the amount of money between 1 and 99 cents: 45 Quarters: 1 Dimes: 2 Pennies: 0 go again? (y to continue):n
I | Attachment | History | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|---|
jpg | United_States_coins_public_domain.jpg | r1 | manage | 110.8 K | 2016-09-30 - 23:28 | JimSkon | |
png | mystica-Coins-Money.png | r1 | manage | 1282.1 K | 2016-09-30 - 18:18 | JimSkon |