Assignment 5
Due Date: Tuesday the 13th at 9:00pm (Week 6)
Purpose Further practice with lists and structs.
Exercise 1 HtDP Exercise 167
Exercise 2 HtDP Exercise 170
Exercise 3 Work through section 10.3, and do HtDP Exercise 172 (this is a long problem, but useful practice)
Exercise 4 Consider the following data definition:
(define-struct contact [name phone]) ; A Contact is a (make-contact String Number) ; An AddressBook is one of: ; - '() ; - (cons Contact AddressBook) ; INTERPRETATION: A list of contacts, with their names and addresses ; A MaybeNumber is one of ; - #false ; - Number ; INTERPRETATION: Represents maybe having a number Write the function find-contact that accepts a String representing the name of a contact and an AddressBook, and returns a MaybeNumber: either the first Number in the AddressBook for a Contact with that name, or if such a contact does not exist, find-contact should return #false.
Graded Exercises
Exercise 5 Consider the following data defintion:
; A Size is one of: ; - "small" ; - "medium" ; - "large" (define-struct drip-coffee [cream size]) (define-struct latte [size]) (define-struct cortado [size]) ; A Coffee is one of: ; - (make-drip-coffee Boolean Size) ; - (make-latte Size) ; - (make-cortado Size) ; INTERPRETATION: Represents three possible coffee orders. Each order ; has a size; drip coffee might also have cream in it. ; A CoffeeOrder is a List-of-Coffee ; INTERPRETATION: The list of coffee orders at a local coffee shop ; A MaybeCoffee is one of ; - #false ; - Coffee ; INTERPRETATION: Represents maybe having a Coffee Design the function last-latte that accepts a CoffeeOrder and returns a Coffee representing the last latte order (i.e., a (make-latte ...)) in the list. If there are no lattes in the CoffeeOrder, it returns #false.
Hint: follow the design recipe carefully here. Be careful with your signatures and templates, and they will help guide your implementation.
Exercise 6 The goal of this problem is to develop a camera-roll program such as you may have on your smart phone. The camera-roll starts with the first photo and displays the next photo if the right arrow is pressed.
Here are the updated data definitions you should use:
; NELoImg (Non-Empty List-of-Image) is one of: ; – (cons Image '()) ; – (cons Image NELoImg) (define-struct cr (index images)) ; A CR (Camera Roll) is a (make-cr PositiveNaturalNumber NELoImg) ; intepretation: ; The index represents the position of the current image. ; The index must be between 0 and the number of images in NELoImg. Create a world program to display images from a CR and allow the user to scroll through the photos back and forth using the left and right arrow keys:
Design the function display-photo, which consumes a CR and returns the current image.
Design the function change-photo, which allows a user to change the current photo with the left and right arrow keys. If the current photo is the first photo, then pressing the left arrow should not change the photo. Likewise, if the current photo is the last photo, pressing the right arrow should have no effect.
Note: You will need to use several helper functions.