CS115W2009M2

CS115W2009M2

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ge reduced by the specified amount ;; if the payment exceeds the amount owing, the charge is set to 0. ;; example: ( reduce-bill ( make-bill “A” 10.99 ) 8.24 ) ) → ( make-bill “A” 2.75 ) ;; example: ( reduce-bill ( make-bill “A” 10.99 ) 12.00 ) ) → ( make-bill “A” 0 ) ( define ( reduce-bill a-bill amt ) Question 4. [ 10 marks ] Understanding Lists Answer questions (a)-(d) about the following list. ( define mylist-1 ( cons 45 ( cons “hello” ( cons true ( cons 59 empty ) ) ) ) ) a) [ 1 mark ] What is the value of ( length mylist-1 )? b) [ 1 mark ] What is the value of ( rest ( rest mylist-1 ) )? c) [ 1 mark ] What is the result of ( rest ( rest ( rest ( rest ( rest mylist-1 ) ) ) ) ) ? d) [ 3 marks ] Write a Scheme expression to add the two numbers in mylist-1, your solution must make reference to mylist-1 and use the functions first and rest. Answer questions (e)-(f) about the following list. ( define mylist-2 ( list ( make-posn 1 2 ) ( make-posn 3 4 ) ( make-posn 5 6 ) ) ) e) [ 1 mark ] What is the value of ( first ( rest mylist-2 ) ) ? f) [ 3 marks] Write a Scheme expression to add together the x and y fields of the first posn in mylist-2. Your solution must make reference to mylist-2 and use the posn selector functions, as well as the function first. Question 5. [ 30 marks ] Basic List Functions These questions all deal with a list of string values. a) [ 10 marks ] Create a function count-start-Aa...
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