CSci 1301: Problem Set 7

Due: Wednesday, December 6 at 11:59pm by e-mail

You are required to write signatures and descriptions for all functions, and also descriptions of all your structures. Additionally, functions, except the world problems, must be tested using check-expect. Write your tests before you write a function (but feel free to add more after it's been writen).

The quality of your tests will be graded. Make sure to have enough test cases to demonstrate that the function is correct. I may take points off for a lack of testing (in addition to those taken off for incorrect behavior) if your function doesn't work on particular expected data and there is no test for it. It's much better to leave a test that fails (perhaps in comments) that shows that the function doesn't work on given data and you don't know how to fix it.

Self-referential structure (15 points total)

  1. Given the family tree structure in defined in Section 19.1, write a function ft-has-color? that takes a family tree and a color and returns true if that family tree has a person with that color of eyes, and false otherwise.
  2. Define a function that consumes a family tree and returns the year of birth of the oldest person in the tree.
    Note: In order to handle the case of no-parent you may want to return a very small age (0 would work) so that it's impossible for a no-parent structure to be older than a real person.
  3. Define a function that consumes a family tree and returns the child stucture corresponding to the oldest person in the tree.
    Note: Here you would need to handle a comparison of age very carefully: if one of the structures is no-parent, it should not be older than a real person.

CSci 1301 course web site.