Please note: This assignment is to be completed with your new partner, not your partner from Problem Sets 2–4.
Assignment goals:
Recall your data definitions from Problem Set 4.
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.)
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)
Make two examples of ItemCollection
and two examples of CheckedOutList
s.
Write templates (in comments) for processing ItemCollections
s
and CheckedOutList
s.
Design a function count-collection
that counts the
number of items in an ItemCollection
.
Design a function total-time
that, given an
ItemCollection
, computes the total running time of all
the videos in the collection.
Design a function find-overdue
that,
given a CheckedOutList
, returns a
CheckedOutList
containing only the
CheckedOut
s that are overdue.
(You may—indeed, should—reuse code from Problem Set 4.)
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):
(define (in->cm in) (* in 2.54)) (define (cm->in cm) (/ cm 2.54)) (in->cm (cm->in 12))
An expression that applies count-collection
to an ItemCollection
containing two items representing:
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”.
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.
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:
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.)
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:
The top card shows and the remaining cards are hidden. (Don’t worry if there are two many cards to fit in the scene.)
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.
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.
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.
Please follow the electronic homework submissions instructions.
Last updated 31 January 2010.