This assignment gives you your first chance to write and us higher-order functions in Racket. Download the file homework03.rkt and use it as a template for your submission. Please use the name homework03.rkt for your file!
To solve these problems, you do not need any Racket features beyond the things we have learned in class and the things discussed in this assignment.
- Do not use a let expression in any function.
- Do not use an internal define in any function.
- You may not use explicit recursion or looping for in any function. Your solutions to Problems 3, 4, and 5 should use higher-order functions such as map and apply to do their jobs.
You will find these Racket primitives useful on this assignment:
- string->number converts a string that contains a number into the equivalent number.
- exact->inexact converts an exact number (an integer or a fraction) into the equivalent floating-point number.
- You may pass a two-argument function to map. If you do, then you must pass two list arguments, not one. map will pass the corresponding items in each list to the function at the same time:
> (map + '(1 3) '(2 7)) '(3 10)
> ((candy-temperature-at 5280) 302) ;; Denver 291.44 > (define temp-in-cf ;; Cedar Falls (candy-temperature-at 959)) > (temp-in-cf 240) ;; Cedar Falls fudge! 238.082I have provided check-= expressions for these examples. Write at least two more check-= expressions to test your solution.
> ((in-range-of? 0.1) 4.95 5.0) #t > ((in-range-of? 0.1) 5.0 4.95) ;; works both ways #t > (define within-0.01? (in-range-of? 0.01)) > (within-0.01? 4.95 5.0) ;; not anymore! #f > (within-0.01? 5.0 4.99) #tI have provided check-true and check-false expressions for these examples. You do not have to write any more tests for this problem.
( (76 . 195) (81 . 212) (79 . 225) (78 . 206) ... )We would like to know the average height of the people in the group.
> (average-height '((79 . 225))) 79.0 > (average-height '((70 . 150) (62 . 100))) 66.0Assume that we have already written a variable-arity function named average. It is defined in your template file. You may write other helper functions if you like, but you do not have to.
( (2 -7) (-4 -20) (7 8) (-13 2) ... )The first item in this list says that his program predicted Team 1 would win by 2 points, but it lost by 7 points (so, Team 2 won by 7). For that game, his program was off by abs(2 - (-7)) == abs(9) == 9 points. The third item says that his program predicted that Team 1 would win by 7 points and that it won by 8 points, so his program was off by abs(7 - 8) == abs(-1) == 1 point. The list can contain any number of these pairs.
> (define example '((2 -7) (-4 -20) (7 8) (-13 2))) > (total-error example) 41I have provided a check-equal? expression for this example. Write at least three more check-equal? expressions to test your solution.
'(("Dept" "Number" "Section" "Class Nbr" "Capacity" "Enrollment") ("CS" "1000" "1" "11546" "30" "30") ("CS" "1025" "1" "11547" "30" "30") ("CS" "1120" "1" "11557" "30" "15") ("CS" "1130" "1" "11548" "30" "18") ... )The dean and provost frequently ask me for various summary data, such as total enrollments or remaining capacity.
> (define example '(...)) ; the data shown above > (max-open-seats example) 15CS 1120 has 30-15 = 15 open seats. The other classes have 0, 0, and 12 open seats each.
By the due time and date, submit the following files electronically:
Be sure that your submission follows all submission requirements.
Be sure to use the specified names for your file! This enables an autograder to find and run your code.