Work 04: 9/18

posted Sep 18, 2018, 9:53 AM by JonAlf Dyrland-Weaver   [ updated Sep 18, 2018, 12:46 PM ]
Write the following functions in racket:
  • discriminant
    • Has 3 parameters, representing the coefficients of a quadratic equation (i.e. ax2 + bx + c = 0)
    • Returns the value of the discriminant of the equation
      • For the less mathematically inclined: discriminant = b2 - 4ac
    • examples
      • (discriminant 4 2 2) ==> -28
      • (discriminant 2 4 2) ==> 0
      • (discriminant 5 10 3) ==> 40
  • posRoot
    • Has 3 parameters, representing the coefficients of a quadratic equation (i.e. ax2 + bx + c = 0)
    • Returns the root of the equation obtained by this formula:

    • examples
      • (root1 2 4 2) ==> -1
      • (root1 4 8 12) ==> -1.0+1.4142135623730951i
    • note: you cannot put  a - in front of a variable to make it negative (doing -x will create an error)
    • second note: part of this formula should look familiar
  • getOnesDigit
    • Has 1 parameter representing an integer.
    • Returns the ones digit of the parameter.
    • examples
      • (getOnesDigit 124) ==> 4
      • (getOnesDigit 5) ==> 5
  • disaster
    • Consider 2 trains, traveling directly towards each other at different speeds on the same track.
    • Write a function that will return how long it will take for the two trains to crash into each other
    • Has 3 parameters, the first 2 represent the speed of the trains in miles per hour, and the third represents the distance between the trains at the start in miles.
    • examples
      • (disaster 20 80 100) ==> 1
      • (disaster 4 2 30) ==> 5
    • hint: time = distance / speed

submit these as racket-2. Don't forget to include test cases.
Comments