CS 1101 - A-term 11
Homework 6 - Higher-Order Functions; Descendant Trees
Due: Tuesday, October 4 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
In Homework 4 we developed several functions that were designed to process a
list of items in an auction. As you solve the following problems, you may refer to and use any of the
answers to the HW4 problems. Start by copying and pasting the data definitions and templates for item
,
bid
, and
auction
from the given solutions to your DrRacket Definitions window.
- Using map and/or filter, redefine the function
hour-passed
, that has the following contract and purpose:
;; hour-passed: auction -> auction
;; consumes an auction and produces an auction in which the hours left on each biddable item
;; has been decreased by one. If the number of hours left is zero, the number of hours remain
;; at zero
- Using map and/or filter, redefine the function
winning-items
, that has the following contract and purpose:
;; winning-items: string auction -> auction (list-of-item)
;; consumes the name of a person and an auction and produces a list of all items for
;; which the named person currently has the highest bid
- Using map and/or filter, write a function
stuff-won-by-bidder
, that has the following contract and purpose:
;; stuff-won-by-bidder: auction string -> list-of-string
;; consumes an auction and the name of a bidder, and returns a list of the
;; descriptions of the items where the high bidder is the named person, and
;; the time left to bid on the item has expired (is 0)
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 again 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.