Courses‎ > ‎Intro to CS - Half Year‎ > ‎Dyrland-Weaver‎ > ‎Work‎ > ‎

### 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:discriminantHas 3 parameters, representing the coefficients of a quadratic equation (i.e. ax2 + bx + c = 0)Returns the value of the discriminant of the equationFor the less mathematically inclined: discriminant = b2 - 4acexamples`(discriminant 4 2 2) ==> -28``(discriminant 2 4 2) ==> 0``(discriminant 5 10 3) ==> 40`posRootHas 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 familiargetOnesDigitHas 1 parameter representing an integer.Returns the ones digit of the parameter.examples`(getOnesDigit 124) ==> 4``(getOnesDigit 5) ==> 5`disasterConsider 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 otherHas 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 / speedsubmit these as racket-2. Don't forget to include test cases.
Comments