CS 1101 - C-term 11
Homework 6 - Higher-Order Functions; Descendant Trees
Due: Thursday, February 24 at 5pm
Read the expectations on homework.
Assignment Goals
- To make sure you can use filter and map to simplify the development of
certain list problems.
- To make sure you can write data definitions for variable-width (i.e.descendant) trees.
- To make sure you can write programs over variable-width trees.
The Assignment
There are two parts to this assignment. In Part 1, you will use map
and filter
to re-write some of the list functions we developed a
couple of weeks ago. In Part 2, you will define data and functions for a
descendant family tree.
Problems
Part 1
A week or so ago we developed several functions that were designed to process a
list of courses in the WPI Registrar's data base. As you solve the following problems, you may refer to and use any of the
answers to the list-of-course problems. Start by copying and pasting the data definitions and templates for course
and
list-of-course
from the handout to your DrRacket Definitions window.
- Using map and/or filter, redefine the function
multi-sect-course
, that has the following contract and purpose:
;; multi-sect-course: list-of-course -> list-of-course
;; consumes a schedule and produces list of courses with more than 1 section
- Using map and/or filter, redefine the function
courses-in-term
, that has the following contract and purpose:
;; courses-in-term: symbol symbol list-of-course -> list-of-number
;; consumes dept name, term, and schedule, and returns list of course numbers offered in that term
;; by that dept
- Using map and/or filter, redefine the function
upper-level-courses
, that has the following contract and purpose:
;; upper-level-courses: schedule symbol -> schedule
;; consumes a schedule and a department and returns a list of all
;; courses in the department at the 3000- or 4000 level.
Part 2
Suppose we're keeping track of people and their children, using a descendant
family tree. We're particularly interested in the education levels of the
people in the family tree. So, one of the pieces of information we want to keep track of for
each person is his or her academic record. A person's academic record consists of a
list of yearly records. Each yearly record consists of the grade level,
the year the person
attended,
and whether or not the person
passed the grade level in that year. (For example, a person could attend
4th grade in 1991 (didn't pass) and in 1992 (passed)).For each person, we need to record the person's name, age,
academic record, and list of children.
- Provide data definitions for the following: yearly-record, academic-record, and person. Provide an example of a descendant family tree that starts with a
single person and consists of at least two levels below that person (so there
should be information about the person's grandchildren in your example).
- Provide the templates for your data definitions.
- Develop a function
older-than
that consumes a person and a number. The function produces a list of the names of each person in the given
tree who is older than the given age.
- Develop a function
increase-age
that consumes a person and
produces a person. The function adds one to the age of each person in the
tree.
- Develop a function
remove-failures
that consumes a person and
produces a person. The family tree that is produced is the same as the
original, except that each person's academic record now contains only those
yearly records that indicate the person passed. You should use filter to
produce the updated academic record for each person.
What to Turn In
Here is the grade sheet that the TAs will use
when they grade this assignment.
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.