| Due date: 3/19 @ 6pm
This problem set continues the study of complex data and first class
functions. Some of the problems cover functions that process two
arguments from classes with complex (self-referential) data
definitions, others deal with functions that take functions as
arguments.
--- You must follow the design recipe. The graders will
look for data definitions, contracts, purpose statements, tests, and
properly organized function definitions. For the latter (as before),
you must design templates. You do not need to include the templates
with your homework, however. If you do, comment them out.
HtDP Problems:
Do not use equal? for these problems, you will not get points
if you do.
17.8.4: Assume that the lists do not contain duplicates
17.8.7, 17.8.8: Use the definitions
of BT/BST from Sect. 14.2 (~pg. 199).
19.1.5, 19.1.6, 19.2.2, 19.2.4
Problem A1:
Scheme has lots of great abstract functions for processing
lists (pg. 313, Sect. 21.2).
Given the following data definitions:
;; A Grade is: (make-grade Symbol Number)
(define-struct grade (letter num))
;; The Symbol in a Grade represents
;; 'A >= 90
;; 'B >= 80
;; 'C >= 70
;; 'D >= 60
;; 'F < 60
;; A (listof Grades) ...
(define grades
(list (make-grade 'D 62) (make-grade 'C 79) (make-grade 'A 93) (make-grade 'B 84)
(make-grade 'F 57) (make-grade 'F 38) (make-grade 'A 90) (make-grade 'A 95)
(make-grade 'B 82) (make-grade 'A 91) (make-grade 'A 94) (make-grade 'B 84)
(make-grade 'C 71) (make-grade 'F 58) (make-grade 'F 42) (make-grade 'B 86)
(make-grade 'A 95) (make-grade 'F 53) (make-grade 'F 43) (make-grade 'F 52)
(make-grade 'C 76) (make-grade 'A 90) (make-grade 'F 55) (make-grade 'C 74)
(make-grade 'A 92) (make-grade 'B 86) (make-grade 'F 43) (make-grade 'C 73)))
Design the requested functions to
manipulate Grades. You must use the given list as
one of your tests. Use the Intermediate Student language in
DrScheme.
Note: if you do not use the Scheme function
mentioned, you will not recieve credit for the sub-problem!
- Design the function log->lon that converts
a (listof Grade) into a (listof Number) that
contains just the numerical grade, using the Scheme
function map.
- Using foldr, design the function best-grade
that finds the highest Grade in a (listof
Grade).
- Design a function just-As that returns a list of only
the 'A grades, using filter.
- Use andmap to design the
function all-pass? that checks to see if all the
Grades in a given list are not 'F. (** Return
a Boolean!)
- Finally design the function bonus that adds 5
to all of the Grades in a given list, and updates the letter
portion of the Grade if it changes. Use map to
design it your function... it must return a (listof
Grade)!
|