211 S '05
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: 1/25 @ 4:30 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 the date on an electronic calendar (which we know is a computer with a display attached to it):

(define-struct calendar (year month))
;; Calendar = (make-calendar Number Number)
;; Constraints: 
;; The first number is always positive for the current year
;; The second number is always between 1 and 12 for the current month. 
;; Examples:
(make-calendar 2000 1) ; Jan 2000
(make-calendar 1979 2) ; Feb 1979

Develop the function next, which advances to the next month Keep in mind you may have to change year as well.

Modify the data definition so that Calendar also keeps track of days. Then modify next. The new constraint is that day must be greater than 0 and no greater than the number of days in the current month.

Optional: Take into account leap year!

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 5 pixels per tick; the bird flies horizontally at the same rate:

(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.)


Please explain any problems you had completing this assignment in no more than 30 words.

last updated on Wednesday, April 13th, 2005 3:57:37pmgenerated with PLT Scheme -- (Source)