CS2500: Problem Set 5

Due: Tuesday, February 16 at 11:59 PM

Please note: This assignment is to be completed with your new partner, not your partner from Problem Sets 2–4.


Assignment goals:


  1. Recall your data definitions from Problem Set 4.

    1. Let’s call the data definition for items from Problem 3 Item, and the data definition for check-out items from Problem 5 CheckedOut. That is, you should have data definitions of the form:

      ;; An Item is . . .
      ;; A CheckedOut is . . .

      Copy these data definitions (yours, not ours) into your file for Problem Set 5. (If you used different names, that’s okay—we’re sure you can still follow along with our names, or you can update your names to match. If you aren’t sure about your solutions, email them to the instructor for confirmation.)

    2. The library needs to keep track of their collection, including multiple items or checkout records at once, so add the following data definitions:

      ;; An ItemCollection is one of:
      ;; -- empty
      ;; -- (cons Item ItemCollection)
      ;; A CheckedOutList is one of:
      ;; -- empty
      ;; -- (cons CheckedOut CheckedOutList)
    3. Make two examples of ItemCollection and two examples of CheckedOutLists.

    4. Write templates (in comments) for processing ItemCollectionss and CheckedOutLists.

  2. Design a function count-collection that counts the number of items in an ItemCollection.

  3. Design a function total-time that, given an ItemCollection, computes the total running time of all the videos in the collection.

  4. Design a function find-overdue that, given a CheckedOutList, returns a CheckedOutList containing only the CheckedOuts that are overdue. (You may—indeed, should—reuse code from Problem Set 4.)

  5. 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 (in->cm in)
        (* in 2.54))
      (define (cm->in cm)
        (/ cm 2.54))
      (in->cm (cm->in 12))
    2. An expression that applies count-collection to an ItemCollection containing two items representing:

      1. Tracy Kidder: “The Soul of a New Machine” (1981).
      2. “Purple Rain” (Dir. Albert Magnoli), 114 minutes (1984).

    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”.

  6. In this exercise, we will design a card catalogue browser. The world will be an ItemCollection representing a stack of cards. The browser displays the stack of cards and allows the user to discard the top card to see the next card by clicking the mouse.

    1. A catalogue card is white, 375 pixels wide by 225 pixels high, with a red line running horizontally across it, 50 pixels from the top. The information from the displayed Item is formatted nicely. Here are two catalogue cards:

      Donald Knuth: “The Art of Computer Programming” (1965). “Six-String Samurai” (Dir. Lance Mungia), 91 minutes (1998).

      Design a function render-card that creates an Image from an Item as in the two example cards. (Don’t worry if some of the text is too long to fit across the card.)

    2. Design a function render-card-stack that renders a stack of cards in a 500-by-300 scene. Here’s my rendering of a stack of three cards:

      A stack of three cards

      The top card shows and the remaining cards are hidden. (Don’t worry if there are two many cards to fit in the scene.)

    3. Design a mouse event handler function handle-mouse that responds to mouse clicks by removing the first card from the collection. Other mouse events should be ignored. If the collection is empty already, it should remain empty.

    4. Design a function run-catalogue that, given an ItemCollection, starts the catalogue browser using big-bang and allows the user to browse through the stack of cards by clicking the mouse.

    5. Bonus! Our catalogue browser would be a lot more useful if we could move in both directions. Modify your program so that pressing the right arrow on the keyboard moves down through the stack of cards as the mouse clicks do, and the left arrow moves back up by returning the most recently removed card to the top of the stack.

Turn In

Please follow the electronic homework submissions instructions.

CS2500 Home

Last updated 31 January 2010.

Valid XHTML 1.1 Valid CSS!