CS2500: Problem Set 4

Due: Tuesday, February 9 at 11:59 PM

Please note: This assignment is to be completed with your partner


Assignment goals:


  1. Evaluate the following expressions step by step and write down next to each step whether it is (1) “arithmetic” (of any form—not just on numeric data), (2) “plugging” (function application) or (3) “cond” (a conditional step):

    1. (define (ev-quad a b c x)
        (+ (* a (sqr x)) (* b x) c))
      (ev-quad 2 -3 4 2)
    2. (define-struct quad (a b c))
      (define (ev-quad2 q x)
        (ev-quad (quad-a q) (quad-b q) (quad-c q) x))
      (ev-quad2 (make-quad 0 4 -20) 5)
    3. (define (signum x)
          [(positive? x) 1]
          [(negative? x) -1]
          [else          0]))
      (define (my-abs x)
        (* x (signum x)))
      (my-abs -8)

    As a sanity check, you can run each program and make sure your stepping result agrees with DrScheme’s result. Please write the steps in the same style we used in class, and don’t forget to label each arrow with one of “arithmetic,” “plugging,” or “cond”.

  2. In preparation for this year’s baseball season, the commissioner has hired you to develop a data representation for game results. Each game result record must keep track of the following information: the name of the home team, the name of the away team, the home team’s score, and the away team’s score.

    Design a data definition and provide an interpretation for these records. Design a function get-winner that returns the name of the winning team, or false in the case of tie.

    (Hint: Think carefully about the data definition for the return value of the function, because String won’t do.)

  3. A library needs to keep track of their inventory. The library carries two kinds of media:

    • books, which have a title, author, and year of publication
    • videos, which have a title, director, year of release, and length in minutes

    Design a data definition and provide an interpretation for these records. Design a function item-title that, given a library item, returns the title.

  4. The library from Problem 3 keeps item records in a computer (using DrScheme), but they also maintain a card catalogue. Here are sample card catalogue entries for a book and a movie:

    Fred Brooks: "The Mythical Man-Month" (1975).
    "The Mythical Man-Month Movie" (Dir. Ron Howard), 95 minutes (2011).

    Design a function catalogue-entry that, given a library item record, returns the text of the card catalog entry.

    (Hint: To make a string with the double quotation mark " in it, writing """ won’t work. You need to escape the double quote with a backslash, like "\"". The backslash tells DrScheme that the next double quote is part of the string rather than the end of it.)

  5. The aforementioned library also needs to keep track of which books and films are checked out. In particular, they need check-out records that associate with an item (represented as in Problem 3) the name of the patron who checked it out and the number of days until it’s due. (Use negative numbers for overdue items.)

    • Design a data definition and provide an interpretation for these records.
    • Design a function checkout that, given a library item and the name of the person checking it out, returns the check-out record for that item. (Books are checked out for 14 days and videos for 7 days.)
    • Design a function next-day for the library to use at midnight every day to update the remaining days in a check-out record, by returning the same record but with one fewer day remaining.
    • Design a predicate function item-overdue? that determines whether the given checked-out item is overdue.
  6. HTDP/2e, Exercise 91

Turn In

Please follow the electronic homework submissions instructions.

CS2500 Home

Last updated 31 January 2010.

Valid XHTML 1.1 Valid CSS!