Wed, Sept 26
For each of these, be certain that
there is a
comment at the
top of the file saying what the program does, who wrote the
program, and anyone you received help from. You
may not be reminded of this in the future.
0) (2 points) Get the file
ShoppingFunctions.cpp on the server.
Look through the code and understand it.
Ask any questions you have. Your task is to get
the program to:
Your modifications go into function main.
Restriction: the code you add may not contain the
It is intended that you call upon the functions
- ask the user for the purchase price
- ask the user for the weight
- display the price, the tax, the shipping and the total
handin cmsc160 labshopping
1) Get the file FunctionsExercise.cpp.
Run it and see that it gives a lot wrong answers.
each of the 4 functions, there is a tester function (EG
testLastDigit) For each of the lines in
functions, make sure you know what the answer should be. Put
comment at the end of the line with the expected answer. For
cout << 169426 << " --- " <<
<< endl; // answer should
- You are welcome to add more test cases if you wish.
- I will be adding more test cases when I run your
programs for grading.
Your task is to fill in the following functions so that the program
gives correct answers.
- lastDigit [2 points] -
determines and returns what the last digit is.
the / and % operators for
- stateOfMatter [4 points]
- function determines what state (solid, liquid, or gas) water would be
in at the given temperature.
- boiling point and above: gas
- freezing point and below: solid
- between boiling and freezing point: liquid
- boiling point: 100 degrees
- freezing point: 0 degrees
- boiling point: 212 degrees
- freezing point: 32 degrees
- isRightTriangle [4 points]- function
determines and returns whether the parameters can denote the lengths of
of a right triangle. That is, if the three side lengths are labelled a, b, and c, they are a Pythagorean
if they satisfy a2 + b2 = c2.
Note that your function must work regardless of the order in which the
values are entered. EG (3,4,5) is
Pythagorean Triple, as are (4,3,5) and (5,3,4)
- closestBusStop [EXTRA CREDIT: 3 points] - function
determines and returns the location of the closest bus
stop. Busses stop every five blocks and start at block number
Hence, busses stop at 0,5,10,15, etc.
The parameter indicates what
block you are currently on. For instance, if you
are on block 7, the closest bus stop is at block 5.
If you are on block 8, the closest bus stop is at block 10.
If the parameter is negative, the closest bus stop
is at block 0.
handin cmsc160 labfunctions FunctionsExercise.cpp