This assignment gives you your first chance to write Racket functions. Download the file homework02.rkt and use it as a template for your submission. Please use the name homework02.rkt for your file!
This file includes a require expression at the top. It "imports" the rackunit module and enables you to use to write test cases for your solutions [ example code ]. The template file contains several test cases for you. Problems 3 and 5 ask you to write your own test cases.
You do not need any advanced Racket features to solve these problems, only simple expressions.
- Do not use a let expression in any function.
- Do not use an internal define in any function.
You may find the Racket primitives sqrt, expt, and abs useful on this assignment.
For Problem 5, I ask you to write Racket functions to compute the Body Mass Index for a person. Before starting work on that problem, please read the short selection below on Body Mass Index.
According to the Centers for Disease Control, the Body Mass Index (BMI) is a reliable indicator of body fat content for most people. BMI does not measure body fat directly; we calculate it indirectly from a person's height and weight. Even so, research has shown that BMI correlates well to direct measures of body fat, such as weighing a person underwater and using dual energy x-ray absorptiometry. Those diagnostic tests are quite expensive. BMI is a cost-effective, easy-to-perform method of screening for weight categories that may lead to health problems.
To formula for is
BMI = weight / height2where height is expressed in meters and weight is expressed in kilograms.
For example, one of my favorite UNI men's basketball players of recent years, Marvin Singleton, was listed as 6'-6" tall and 237 pounds. After we convert those values to metric, we find that Singleton had a BMI of 27.4.
> (inches->meters 39.3701) 1.0 > (inches->meters 78) 1.9811989301525776 > (pounds->kilograms 2.20462) 1.0 > (pounds->kilograms 237) 107.50151953624662I have provided check-equal? expressions for all of these examples in your template file.
> (ladder-height 10 6) 8 > (ladder-height 13 5) 12 > (ladder-height 20 3.5) ; that's steep... be careful!! 19.691368667515217I have provided check-equal? expressions for all of these examples in your template file.
> (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.802Write check-equal? expressions for these three examples.
> (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) #tI have provided check-equal? expressions for all of these examples in your template file.
> (body-mass-index 78 237) 27.3878810806232 > (body-mass-index 81 215) 23.03921698562725Write check-equal? tests for these three examples.
By the due time and date, submit the following files:
Be sure that your submission follows all of the submission requirements. Use Save Interactions As Text... to create the file of interactions that you submit, and change the file extension to txt.