6.10

Assignment 6b

home work!

Programming Language BSL

Due Date: Thursday at 9:00pm (Week 6)

Purpose To practice designing functions on lists, and extending and refining earlier programs.

Finger Exercises

Exercise 1 HtDP2e Exercise 168

Exercise 2 HtDP2e Exercise 169

Exercise 3 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.
 
; A OrderBook is a List-of-DinnerCheck

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).

Graded Exercises

Exercise 4 These two problems concern 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 is a List of Seat
; 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.

Exercise 5 Design the function seat-dupes, which accepts a Flight and returns a list of Strings representing all the seat numbers that appear more than once in the flight. For example:

(check-expect (seat-dupes (list (make-seat "2A" #true "")
                                (make-seat "2B" #true "")
                                (make-seat "2C" #false "Wilson, C")
                                (make-seat "2D" #true "")
                                (make-seat "2A" #false "Mislove, A")
                                (make-seat "2B" #true "")
                                (make-seat "2C" #false "Naji, N")))
              (list "2A" "2B" "2C"))

(Reminder: we introduced the list shorthand notation in Lab 4 Recursion, With A Twist.)

Hint: When designing seat-dupes, you will likely need to implement a helper function or two. Remember, make wishes for these helper functions first, then go and use the design process for each of them. You are welcome to use any other functions that you have already created when designing this program.