This assignment gives you a chance to write Racket expressions
that will be the body of a function.
Template Source File
Download
this template file
and use it as the starting point for your submission. Please
name the file homework02.rkt!
homework02.rkt includes a require
expression at the top. It imports the rackunit
module so that we can define unit tests to check our solutions.
+
The template file contains several test cases for each problem.
Make one of the arguments floating-point. Dividing
the elevation by 500.0 instead of 500 will do the trick.
Problems
Write a Racket function named discriminant
that takes exactly three integer arguments. They are the
coefficients for a quadratic equation,
ax² + bx + c.
discriminant returns the value
b² - 4ac. For example:
> (discriminant 1 4 4) ; an equation with one real root
0
> (discriminant 1 5 6) ; an equation with two real roots
1
I have provided check-equal? expressions for
these two examples in your template file.
Write a Racket function named total-grade that
takes exactly three integer arguments: a homework average,
a quiz average, and a final exam average. Each argument will
be in the range 0 .. 100. total-grade returns
the overall grade for the course, based on
the weights defined in the syllabus:
25%, 45%, and 30%, respectively. For example:
I have provided check-= expressions for these
three examples in your template file.
Suppose we have two concentric circles. The outer circle has
a radius of rO, and the inner circle has
a radius of rI. The area of the ring
they form is the difference between the
areas of the two circles.
Write a Racket function named ring-area that
takes two arguments, inner and outer,
both in inches. The function returns the area of the ring
formed by the concentric circles. For example:
> (ring-area 1 2)
9.42477796076938
You may want to write a function to compute the area of a
circle and use it to compute ring's area.
I have provided a check-= expression in your
template file for the example above, as well as two more
check-= expressions to test your solution further.
According to
The Joy of Cooking,
when you are cooking candy syrups, you should cook them 1 degree
cooler than listed in the recipe for every 500 feet of elevation
you are above sea level. For example, the recipe for Chocolate
Carmels calls for a temperature of 244° Fahrenheit. If you
were making your Chocolate Carmels in Denver, the Mile-High
City, you would want to cook the syrup at 233.44°.
Write a Racket function named candy-temperature
that takes two arguments, the recipe's temperature in degrees
Fahrenheit and the elevation in feet, and returns the temperature
to use at that elevation. For example:
> (candy-temperature 244 5280) ;; Denver, the Mile-High City
233.44
> (candy-temperature 302 977.69) ;; the highest point in Cedar Falls
300.04462 ;; is approx. 298m above sea level
> (candy-temperature 302 -1401) ;; the Dead Sea, 1401 ft below sea level
304.802
I have provided check-= expressions for these three
examples in your template file.
Generally, the dimensions of engineered components are
not exactly the specified value, but rather within a certain
tolerance of the specified value. The tolerance generally
depends upon the application and the material being used.
For example, a metal piece used in construction that is listed
as 5 cm in length might actually be any length within 1 mm of
5 cm, that is, between 4.9 cm and 5.1 cm, inclusive.
Write a Racket function named in-range? that
takes three numbers as arguments: two numbers to compare, and
a tolerance, epsilon. in-range?
returns true if its first two arguments are within
epsilon of one another, and false otherwise.
For example: