Work 05: 9/20

posted Sep 20, 2018, 10:37 AM by JonAlf Dyrland-Weaver   [ updated Sep 20, 2018, 12:19 PM ]
Write the following functions in racket
  • average3
    • Has 3 number parameters.
    • Returns the average of those three numbers.
    • examples
      • (average3 1 2 3) ==> 2
      • (average3 23 176 5) ==> 68 
  • tip
    • Takes one argument representing the cost of a meal.
    • Returns the total amount you should pay including an 18% tip
      • Examples
        • (tip 100) ==> 118
        • (tip 64) ==> 75.52
  • gravity
    • Takes 3 arguments representing the masses of 2 objects and the distance between them.
    • Returns the gravitational force as calculated by Newton's formula:
      • Force = (G * mass1 * mass2) / distance2
      • G is a constant defined as 6.674 * 10-11 , which can be written as 6.674e-11 in racket.
    • Examples
      • (gravity 1 2 3) ==> 0.000000000014831
      • (gravity 100000 20000000 6) ==> 3.707
  • coinValue
    • Has 4 parameters representing the number of pennies, nickels, dimes and quarters, respectively.
    • Returns the total value, in dollars, of the coins
    • Examples:
      • (coinValue 1 2 3 4) ==> 1.41
      • (coinValue 2 2 2 2) ==> 0.82
      • Note: you might actually get a number like 0.8200000000000001 back
  • getHundredsDigit
    • Takes one argument representing an integer.
    • Returns the hundreds digit of that number.
    • Examples
      • (getHundredsDigit 234) ==> 2
      • (getHundredsDigit 76348) ==> 3
    • Hint: you may find a function from the previous assignment helpful.
Submit this as test0-review
Comments