map
and filter
to re-write some of the list functions we developed a
couple of weeks ago.
Assume that for each river, measurements of the river's pH and DO (dissolved oxygen) levels are available. Such measurements are taken at the confluence of the rivers (the point at which the tributaries converge). pH levels can range from 0 (most acidic) to 14 (most alkaline). The normal range for bodies of water are 6.5 - 8.5. DO is measured in parts per million (ppm), and can range (at sea level) from 0 ppm (the lowest amount of dissolved oxygen) to 12ppm (saturation point).
lower-ph-than
that consumes a river system and a
number. The function produces a list of the names of each river in the given
system that has a pH value lower than the given pH.
healthy?
that consumes a river system and
produces a boolean. The function returns true if every river in the system
has a pH between 6.5 and 8.5, and a DO of at least 6ppm.
lower-all-ph
that consumes a river system and
produces a river system. The river system that is produced is the same as the original,
except that the pH of all the rivers in the system have been lowered
by 0.1.
(define-struct volunteer-org (type name age consent? license? training hours languages)) ;; a VolunteerOrg is a (make-volunteer-org String String Natural Boolean Boolean Natural ListOfString) ;; interp: ;; VolunteerOrg represents information about a volunteer organization, where ;; type is the type of organization, such as animal shelter or nursing home ;; name is the name of the organization ;; age is the minimum age required for volunteering ;; consent? is true if parental consent is required for volunteers under age 18 ;; license? is true if a valid driver's license is required of volunteers ;; training is the number of hours of training required prior to volunteering ;; hours is the minimum number of volunteer hours required per week ;; languages is a list of the languages spoken by clients of the organization ;; an ListOfVolunteerOrg is one of ;; empty, or ;; (cons VolunteerOrg ListOfVolunteerOrg)Start by copying and pasting the data definitions for
VolunteerOrg
and
ListOfVolunteerOrg
to your DrRacket Definitions window.
list-license-training
that you wrote for Homework 4,
that has the following signature and purpose:
;; list-license-training: ListOfVolunteerOrg Natural -> ListOfVolunteerOrg ;; consumes a ListOfVolunteerOrg and produces only those items in the list that require a driver's license and ;; less than the specified number of hours of training
names-by-age
with the following signature and purpose:
;; names-by-age: ListOfVolunteerOrg Natural -> ListOfString ;; consumes a list of volunteer organizations and the age of a volunteer and produces a list of the ;; names of all organizations that will accept volunteers of the given age
need-spanish-speakers
that you wrote for Homework 4,
that has the following signature and purpose:
;; need-spanish-speakers: ListOfVolunteerOrg -> ListOfVolunteerOrg ;; consumes a list of volunteer organizations and returns a list of those organizations that have clients who speak Spanish
Using web-based turnin, turn in a single file containing all code and documentation for this assignment. Name your file according to the naming conventions for files. Make sure both partners' names and wpi login names appear in a comment at the top of the file.