6.6

Homework 3

home work!

Programming Language BSL

Due Date: Thursday 05/14 at 10pm

Purpose: To design World programs; to practice designing and using structured data

Expectations

Failure to comply with these expectations will result in deductions and possibly a 0 score.

Exercise 1 Consider the following structure definitions:
(define-struct lecture-hall (number capacity))
(define-struct automobile (year make model))
(define-struct football-player (name position number))
(define-struct shirt (material size color))

  1. What are the names of the constructors and the selectors that each of the structures adds to Racket?

  2. Provide data definitions for the structure definitions above. Make appropriate assumptions about what data goes with which field.

  3. Develop templates for functions that consume the structures above.

Exercise 2 Here is a data definition for measuring time:
(define-struct time (hours minutes))
; A Time is a (make-time Hour Minute)
; interpretation: (make-time h m) is the time  
; expressed in h hours and m minutes
; 
;  An Hour is a NaturalNumber between 0 and 11
;  A Minute is a NaturalNumber between 0 and 59

  1. Design the function tock, which adds one minute to the given time.

  2. Design the function time->text, which converts a time to a text. The text should look like the display of a common alarm clock, i.e., it should separate the minutes from the hours with a colon. Hint: a text is an image, not a string, but you will need a string version of the time, too. See the HelpDesk for more on the text function.

  3. After you have developed these functions, add a main function, which launches a big-bang program to animate the time.