Teaching
211 F '04
 
Assignments
Set 1
Set 2
Set 3
Set 4
Set 5
Set 6
Set 7
Set 8
Set 9
Set 10
Set 11
Set 12
Set 13
Set 14

Problem Set 3

Due date: 9/27 @ 6:00 pm

This problem set is about processing structured forms of data.

HtDP Problems:

6.3.1 (1,3,5), 6.4.1 (1,3,5), 6.5.1 (1,3,5), 6.4.2

Additional Problem 1:

Here is a data definition for keeping track of time on a clock (which we know is a computer with a display attached to it):

(define-struct time (hours minutes))
;; Time = (make-time Number Number)
;; Constraints: 
;; The first number is always between 1 and 12; 
;; the second number is always between 0 and 59. 

Develop the function tick, which adds one minute to the given time.

Modify the data definition so that Time also keeps track of seconds. Then modify tick.

Additional Problem 2:

Here is a data definition for a world that consists of two objects: a rock and a bird. The rock drops at a constant speed of 3 pixels per tick; the bird flies horizontally at the same height:

(define-struct world (bird rock))
;; A World is
;; --- (make-world Number Number)
;; Interpretation: 
;; The first number is the x coordinate of the bird; 
;; the second number is the y coordinate of the rock. 

Develop the function world-next, which creates the next world from a given world.

Develop the function world-draw, which creates a 200 x 200 scene with empty-scence and place-image from the world. Create a first example by hand and use it to test the program. Assume that the bird is always 120 pixels above ground level, and that the rock is always 80 pixels from the left.

After the program is fully developed, use the world.ss teachpack to run it like this:


(define (world-next w) ...)

(define (world-draw w) ...)

;; tests: 

;; --- run program run: 

;; World -> World 
;; run for every tick of the clock 
;; display the given world on the canvas
;;  and produce the next world 
(define (tock w) 
  (update (world-draw w) produce (world-next w)))

(big-bang 200 200 .1 (make-world 1 1))

(on-tick-event tock)


Additional Problem 3:

Develop a program that draws a colored rectangle frame around a small image that occurs in a larger one. If the smaller image does not occur inside the larger one, the program just returns the larger image as is.

Hint: Study the documentation for image.ss in the DrScheme help desk, especially the functions image-inside?, overlay/xy, and find-image. Note that overlaying one picture on another puts the images on top of each other at an imaginary, centered pin-hole. (If you like body piercing, think of this as picture piercing, right smack in the middle.)


last updated on Mon Nov 29 11:44:30 EST 2004generated with PLT Scheme