ESc 014
Lab 4 -- The Money Changer
Thursday, April 25, 2002
Objectives
- To know when to use call-by-value vs. call-by-reference parameters
- To practice using casting
Introduction
Modern banks have sophisticated machines for taking a lot
of loose change (coins) and determining the amount of
money in dollars and cents. In this lab, you'll write code
that will do the same task.
Lab summary
You will write two functions in a program designed to ask
the user for a certain coin type (penny, nickel, dime, or quarter)
and the number of coins the user has of that type.
You will then convert that input into dollars and cents and
display it.
Download the starter code
On blackduck in the "esc014pub" directory is a directory named
"lab 4". Transfer this directory to the DesktopAnnex folder
on your desktop. Go back to lab 1 if you
need a refresher on the instructions.
Inside the "lab 4" folder is the starter code you should
begin with named "yourNameHere.cpp".
Change the filename to your
own name (keep the .cpp extension).
The starter code has the main function that you should use.
You should NOT alter this code until directed to below. Study
the code to
understand what's going on. It calls two functions that
you need to write.
The getInput function
This function will take two OUTPUT parameters: the number of coins
the user wishes to convert and the coin denomination. The function
will simply ask the user to input both of these values. The user
will enter the coin denomination as an integer (1 for penny,
5 for nickel, 10 for dime, and 25 for quarter). These values
will then be returned via the output parameters.
The computeDollars function
This function will take the number of coins
and the coin denomination as input parameters. It will compute
the amount of money as dollars and cents and return it.
Debug your code until it works. Be sure to test your
program thoroughly and
make sure you paste the results of your tests into your source code!
A second way to do it
It is possible to get your computeDollars function to
work both when it has a return type and when it does not have
a return type (i.e. void). You wrote it using one of these two ways
above. How would you write it the other way? Write an alternative
function for computeDollars called compute2 that will
do the same task as computeDollars but would have a
return type of void. Don't erase the computeDollars function.
Just add the compute2 function to your program. Then, alter
the main method to call this new function
where appropriate.
(Don't erase anything in main. Just comment out what you don't need).
Debug your code until it works with your new compute2 function.
How to turn in this lab
Remember, you will be graded on the
correctness of your implementation, neatness, presentation, style of
your
program code, thoroughness of your testing, and good use of
the C++ language. It's important to comment your
code where appropriate and to do little things like space things
properly, use
readable indentation, and also to make sure the overall design and logic
of the
program are coherent.
Turn in a hard copy of your source code along with the output appended
at the bottom as a comment. Then turn in the source code
electronically on BlackBoard.
Return to Lab Index