This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ure message
0 <= t < 10
10 <= t < 20
20 <= t
;; examples: ( weather-message 15 “raining” ) → “ warm and raining”
( weather-message -10 “sunny” ) → “cold and sunny”
( define ( weather-message t current ) Question 3. [ 22 marks ] Using Structures
Recall the structure bill from assignment 3:
;; A bill is a structure ( make-bill n c ) where n is a string ( for a person's name ) and
;; c is a non-negative number ( for the outstanding charge )
( define-struct bill ( name charge ) )
a) [ 2 marks ] Define a constant my-bill, of type bill, for “Li” with a charge of 9.99 b) [ 10 marks ] Create a function owes-more that consumes two bills and produces the name of the
person with the higher charge on their bill. If both people owe the same amount, the function can
produce either name.
;; owes-more: bill bill → string
;; produces the name of the person with the higher charge
;; example: ( owes-more ( make-bill “A” 10.65 ) ( make-bill “B” 8.21 ) ) → “A”
( define ( owes-more bill1 bill2 ) c) [ 10 marks ] Create a function reduce-bill which consumes a bill and a non-negative integer, and
produces a new bill for the same person with the charge reduced by the indicated amount. If the
consumed number is larger than the charge owing, then the new bill should have a charge of 0.
;; reduce-bill : bill num → bill
;; produces a new bill with the char...
View Full Document
- Fall '08