- Engineering
- Computer Science
- solve in drracket and use rackunit ai buy soda in...
Question: solve in drracket and use rackunit ai buy soda in...
Question details
Solve in DrRacket and use rackunit
A.I buy soda in 12-packs of 12-ounce cans or
6-packs of 24-ounce bottles. In the last fews year, stores have
begun to sell 6-packs of 16.9-ounce bottles and
charging the price usually associated with the larger 24-ounce
bottles. I am not amused by this marketing strategy. I need a
function that helps me compare prices by the ounce.
Write a Racket function named price-per-ounce that
takes three arguments: the number of units (bottles or cans) in a
pack, the size of each unit in ounces, and the price for a pack.
price-per-ounce returns the price of the pack per ounce. For
example:
> (price-per-ounce 6 24 1.44) ; a 6-pack of 24-ounce bottles costs $1.44 0.01 > (price-per-ounce 6 16.9 1.44) ; I am not amused 0.014201183431952664
I have provided check-equal? expressions for these two examples in your template file.
[template file]
(require rackunit) ; enables you to use rackunit tests
; -------------------
; ----- [1] -----
; -------------------
(define price-per-ounce
(lambda (units-per-pack ounces-per-unit pack-price)
0
))
; replace the 0 with your code
(check-equal? (price-per-ounce 6 24 1.44)
0.01)
(check-equal? (price-per-ounce 6 16.9 1.44)
0.014201183431952664)
B. A 10-foot ladder leans against a wall. If
its base is 6 feet away from the bottom of the wall, then it
reaches 8 feet high on the wall. This is a simple example of the
Pythagorean theorem.
Write a Racket function named ladder-height that
takes two arguments, the length of the ladder and the distance at
the base. Both are in feet. The function returns the distance up
the wall reached by the ladder, also in feet. For example:
> (ladder-height 10 6) 8 > (ladder-height 13 5) 12 > (ladder-height 20 3.5) ; that's steep... be careful!! 19.691368667515217
I have provided check-equal? expressions for all of these examples in your template file.
[template file]
; -------------------
; ----- [2] -----
; -------------------
(define ladder-height
(lambda (ladder-length base-distance)
0
))
; replace the 0 with your code
(check-equal? (ladder-height 10 6) 8)
(check-equal? (ladder-height 13 5) 12)
(check-equal? (ladder-height 20 3.5)
19.691368667515217)
You may want to create a function to square a number, and use it to
compute the ladder's height.
C. 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, baby! 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
Write check-equal? expressions for these three examples.
[template file]
; -------------------
; ----- [3] -----
; -------------------
(define candy-temperature
(lambda (temp elevation)
0
))
; replace the 0 with your code
D.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:
> (in-range? 4.95 5.0 0.1) #t > (in-range? 4.95 5.0 0.01) ;; not anymore! #f > (in-range? 5.0 4.95 0.1) ;; works both ways #t > (in-range? 5.0 5.95 0.1) #f > (in-range? 5.5 5.95 0.5) #t
I have provided check-equal? expressions for all of these examples in your template file.
[template file]
; -------------------
; ----- [4] -----
; -------------------
(define in-range?
(lambda (actual desired epsilon)
#f
))
; replace the #f with your code
(check-equal? (in-range? 4.95 5.0 0.1) #t)
(check-equal? (in-range? 4.95 5.0 0.01) #f)
;; not anymore!
(check-equal? (in-range? 5.0 4.95 0.1) #t)
;; works both ways
(check-equal? (in-range? 5.0 5.95 0.1) #f)
(check-equal? (in-range? 5.5 5.95 0.5) #t)
E.Write a Racket function named body-mass-index to compute BMI values. This function takes two arguments, a height in inches and a weight in pounds. It returns the corresponding BMI value. For example:
> (body-mass-index 78 237) 27.3878810806232 > (body-mass-index 81 215) 23.03921698562725
Write check-equal? tests for these three examples.
[template file]
; -------------------
; ----- [5] -----
; -------------------
(define body-mass-index
(lambda (height weight)
0
))
; replace the 0 with your code
; write your own check-equal? tests for the two examples
given
; plus at least one more test of your own design
; ----- end -----
Solution by an expert tutor
