CMSC 160
Fall 2018
Due:  Wed, Sept 26

Assignment:    (12 points)

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.

yellow bar separator

(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:
  • ask the user for the purchase price
  • ask the user for the weight
  • display the price, the tax, the shipping and the total
Your modifications go into function main.     Restriction:   the code you add may not contain the identifier  cout    It is intended that you call upon the functions already there.

handin  cmsc160  labshopping   ShoppingFunctions.cpp

yellow bar separator

1)   Get the file  FunctionsExercise.cpp.  Run it and see that it gives a lot wrong answers.

For each of the 4 functions, there is a tester function   (EG   testLastDigit)      For each of the lines in the tester functions, make sure you know what the answer should be.  Put a comment at the end of the line with the expected answer.   For instance:

    cout << 169426 << " --- " << lastDigit(169426) << endl;      // answer should be 6

Special notes:
  • 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] -  function determines and returns what the last digit is.    (Recall the /  and % operators for integers.)   
  • stateOfMatter [4 points] - function determines what state (solid, liquid, or gas) water would be in at the given temperature.     Specifications:
    • boiling point and above:   gas
    • freezing point and below:  solid
    • between boiling and freezing point:  liquid
    • Celsius:
      • boiling point: 100 degrees
      • freezing point:  0 degrees
    • Fahrenheit:
      • boiling point: 212 degrees
      • freezing point:  32 degrees
  • isRightTriangle [4 points]- function determines and returns whether the parameters can denote the lengths of the sides of a right triangle.   That is, if the three side lengths are labelled a, b, and c, they are a Pythagorean Triple 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 0.  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