7.0

Week 4 Set a

home work!

Programming Language BSL

Due Date Monday 9/24 at 9:00pm (Week 4)

Purpose To practice designing programs and begin working with self-referential data.

Finger Exercises

Exercise 1 From HtDP, 123 128

Graded Exercises

Guess My Number

Exercise 2 Design a program which, when launched, randomly generates a number n from 0 to 9. On display should be the word "Guess!". Then, once a person guesses a number, it should display that number as well as either "Nope, higher.", "Nope, lower.", or "You've won!" based on whether n is higher, lower, or equal to the number guessed. The program should end when the correct guess is made and output the number of guesses it took to find the correct number.

Be sure to define your data and follow the design recipe all the way through!

Note: when a function input is ignored, it is called _ by convention. Also, its type in the signature is Any, since we accept any kind of data. Any will be formalized later on in the semester; don’t worry about defining it for now.

Hint: Sometimes, when building a program, it is easier to build a slightly simpler program that is easier to debug. One may want to initially design the program so that the number to be guessed is given to the function as opposed to being randomly generated. Then, once they are sure this version of the program works, modify it to randomly generate the number to be guessed.

Bigliest Word

Exercise 3 As seen in lecture, you are going to create a program that connects to "dictionary.ccs.neu.edu", on port 10000. The messages the server sends are guaranteed to be Strings. The largest string received so far should be displayed (or none if none have been received).

When the program ends, it should output the largest string received (if any). If no strings have been received, the output should clearly indicate that this is the case. Break ties by choosing the most recently received word.

The program should take in a Natural number (0, 1, 2...) and stop after that many words have been received.

Be sure to define your data and follow the design recipe all the way through!

The Tower Of Terror

; 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 4 Define examples of and design the template for a Building.

Exercise 5 Design a function which counts the total number of rooms in a Building.

Exercise 6 Design a function which draws a building. The stories should be of a fixed width, be their own color, and stacked on top of each other. Each story should also consist of horizontally arranged, identically sized rooms, all of which are surrounded by a frame to differentiate between them. The ground story can be represented by the empty-image.

You may find the following data definition and template helpful, and keep in mind all positive integers are instances of natural numbers:

; A Nat is one of:
; - 0
; - (add1 Nat)
 
; nat-temp : Nat -> ?
(define (nat-temp n)
  (cond [(zero? n) ...]
        [(positive? n) (... (nat-temp (sub1 n)))]))