8.10

Homework 3b

home work!

Programming Language BSL

Due Date Thu at 9:00pm (Week 3)

Purpose Practice with self-referential data

Exercises

The Tower Of Terror

In this tower, all rooms are the same size, but some floors are taller than others, and may be bigger (or smaller) than other floors, depending on how many rooms they have.

; A Building is one of:
; - "ground"
; - (make-story Number PosInt String Building)
(define-struct story [height rooms color below])
; and represents either the ground story,
; or a story with a height, number of rooms, color, and
;   the rest of the building beneath it

Exercise 1 Design a function "num-rooms" which counts the total number of rooms in a Building.

Exercise 2 Design a function "max-rooms" which returns the maximum number of rooms in one floor within a Building.

Exercise 3 Design a function "first-floor" that returns either the first floor above "ground" or "#f" if no such floor exists.

Exercise 4 Design a function "unbalanced?" which returns a "#t" if there is a higher story that has more rooms than a lower story, and "#f" otherwise.