Assignment 5
Due Date: Friday May 24th at 10:00pm
Purpose Further practice with lists and structs.
This assignment and all future ones require adherence to the design recipe. Failure to do so will result in severe loss of points.
Exercise 1 HtDP Exercise 167
Exercise 2 HtDP Exercise 168
Exercise 3 HtDP Exercise 169
Exercise 4 HtDP Exercise 170
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 (List-of-Coffee) is one of: ; - '() ; - (cons Coffee CoffeeOrder) ; 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 Consider the following data definition:
(define-struct dinner-check [food drink tax tip]) ; A DinnerCheck is a (make-dinner-check Number Number Number Number) ; INTERPRETATION: Represents the bill for a table in a restaurant, ; with numbers representing the cost of the food, drink, tax, and tip. ; An OrderBook (List-of-DinnerCheck) is one of: ; - '() ; - (cons DinnerCheck OrderBook) Design the function flag-anomalous that accepts an OrderBook and returns an OrderBook consisting only of DinnerChecks that are anomalous. A DinnerCheck is considered anomalous if the tax amount is not exactly 10% of the sum of the food and drink amounts, or if the tip amount is greater than 50% of the sum of the food, drink, and tax amounts (or both).
Exercise 7 This problem concerns the following data definitions that represent the seat assignments on a flight:
(define-struct seat [number is-empty passenger-name]) ; A Seat is a (make-seat String Boolean String) ; INTERPRETATION: A seat assignment on a plane, consisting of a ; seat number ("34B"), whether or not it is empty, and the name of the ; passenger if it is not empty. If a seat assignment is empty, the ; passenger name should be the empty string (""). ; A Flight (List-of-Seat) is one of: ; - '() ; - (cons Seat Flight) ; INTERPRETATION: Represents the seats present in a given flight. ; (The seats are not guaranteed to be ordered by seat number; it's just a ; set of seats.) Design the function seat-member?, which accepts a seat number (a String) and a Flight, and returns a Boolean representing whether or not that seat number appears in the flight (regardless of whether it is empty or not).