$19
• You and your partner must submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept no email submissions.
• You must use the language specified at the top of this page.
• Your code must conform to the guidelines outlined in the style guide on the course website. The style guide will be updated as the semester progresses, so revisit it before submitting each assignment. (You can resubmit as many times as you like until the due date without penalty.)
• Unless otherwise stated, every function and data definition that you design, including helper functions, must follow all steps of the design recipe.
Failure to comply with these expectations will result in deductions and possibly a 0 score.
Finger Exercises: HtDP/2e: 63, 65, 66, 67
Notes: to find the finger exercises, you’ll need to read the textbook and search for them by number. Also note the “2e” in the name: the exercise numbers changed substantially between the first and second editions. Make sure you’re reading the more recent edition. Finally, some of the finger exercises we recommend above rely on earlier exercises for context: you may need to scroll backwards in the textbook to figure out where the overall exercise starts.
Graded Exercises:
Exercise 1 Look at the following structure type definitions:
• (define-struct book [title author year])
• (define-struct date [day month year])
• (define-struct holiday [title date is-observed])
For each definition, write down:
• The names of the functions (constructors, selectors, and predicates) that each definition introduces
• A reasonable data definition
• An interpretation
• Three examples
• The function template for that data definition
Exercise 2
In HW2, we learned how to represent the time of day using DayMinute. However, a DayMinute, which is a number, is a clumsy representation. It is far more natural to think of time as a structure type definition.
a. Design a new data definition called Time, which represents the time of day in hours and minutes. Ensure you follow all steps of the data design recipe. You must use define-struct.
b. Design a function that consumes a Time, t, and produces a Time that represents the next minute immediately after t.
(require 2htdp/image)
(require 2htdp/universe)
(define CLOCK-HOUR-HAND
(above (rectangle 3 20 "solid" "black")
(rectangle 3 20 "solid" "transparent")))
(define CLOCK-MINUTE-HAND
(above (rectangle 2 30 "solid" "blue")
(rectangle 2 30 "solid" "transparent")))
(define CLOCK-FACE (circle 40 "outline" "red"))
c. Using the definitions above, design a function that consumes a Time and uses big-bang to draw an animated clock that runs starting from the given time. Note: you do not have give check-expects for this function.
Exercise 3
a. A hotel review website, such as Yelp, lists a lot of information about each hotel, including its name, luxury rating (in stars), and a summary of its price (in dollar signs). Design a new data definition called Hotel, which contains these three pieces of information about a hotel. Assume that hotels are rated with one to five stars, and their price is rated using one to four "$"s.
Hint: You will need auxiliary data definitions to define Hotel.
b. Finding a hotel that’s not too costly can be tricky. Design a function called in-budget? that takes a Hotel and a price rating, and produces #true if the Hotel is no more expensive than the price rating you’re willing to spend.
c. The hotel business is tough these days, and less-expensive options are certainly more attractive than pricey ones... Design a function called make-cheaper that consumes a Hotel, called h, and produces a Hotel that has one fewer "$" than h, adds the string "Cheaper " to the beginning of the hotel name, and has the same star rating. However, if the price of h is exactly "$", the function should produce h itself.
d. The Yelp website summarizes each hotel by displaying a little panel, such as the following screenshot from the Yelp website:
You can use the 2htdp/image library to draw a similar panel, such as the following image that we produced:
Design a function that draws a panel that is approximately the same as the example above. (It does not have to be pixel-for-pixel identical to this example.)