CS115W2009M2

# 65 make bill b 821 a define owes more bill1 bill2

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ure message ;; t<0 “cold” ;; 0 <= t < 10 “cool” ;; 10 <= t < 20 “warm” ;; 20 <= t “hot” ;; 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

## This note was uploaded on 10/24/2009 for the course CS 115 taught by Professor Graham during the Fall '08 term at Waterloo.

Ask a homework question - tutors are online