This preview shows page 1. Sign up to view the full content.
Unformatted text preview: for each of the following applications of the function myfun? Answer Yes or No. a. (myfun “hello” ‘hello)
b. (myfun “hello” ‘hello 5)
c. (myfun “” 3.4)
d. (myfun “123” 123)
Is the contract satisfied for each of the following possible produced values of the function my
fun? Answer Yes or No. e. true
f. (cons true (cons 6 empty))
g. empty
h. (cons false empty)
4. The function numvowels consumes a string and produces the number of characters in the string that are values (a, e, i, o, u). If the string does not contain any vowels, then it produces ‘vowelfree. The function header is: (define (numvowels astring)…) a. Give a contract of num
vowels b. Give a purpose for num
vowels c. Give examples for num
vowels 5. Recall the structure and data definitions of a card.
(definestruct card (value suit))
;;A card is a structure (makecard v s), where v is an integer in the
rang from 1 to 10 and s is a symbol from the set ‘hearts, ‘diamonds,
‘spades, and ‘clubs. When comparing two cards to determine if one is larger than the other, we first consider the values of the cards. However, if the values of the cards are the same, then we use the suit of the card to determine which card is larger. The suits are ranked in the following order: spades is greater than hearts, hearts is greater than diamonds, and diamonds is greater than clubs. a. Complete the function highersuit. Suggestion: Carefully consider the order in which you check the suits of the cards ;;highersuit: symbol symbol > boolean
;;Purpose: Consumes s1 and s2 representing different suits of
cards. Produces true when s1 is greater than s2 and false
otherwise.
;;Examples: (highersuit ‘spades ‘clubs) > true
;; (highersuit ‘diamonds ‘hearts) > false
(define (highersuit s1 s2)
...) b. Complete the function card>? that consumes two cards card1 and card2 (that do not both have the same value and same suit) and produces true when card1is greater than card2. Use highersuit from part (a) in your solution. ;;card>?: card card > boolean
;;Purpose: Produces true when card1 is greater than card2 and false
otherwise.
;;Examples:
;;(card>? (makecard 3 ‘spades) (makecard 4 ‘diamonds)) > false
;;(card>? (makecard 6 ‘hearts) (makecard 6 ‘clubs)) > true
(define (card>? card1 card2)
...) c. Write two tests for that test different situations. Do not repeat the situations from the two provided examples. 6. Complete the function suitcount that consumes a list of card structures and a suit and produces the total value of the cards in the list that match the given suit. Refer to the card structure and data definitions in ques...
View
Full
Document
This note was uploaded on 01/19/2014 for the course CS 115 taught by Professor Troyvasiga during the Fall '13 term at University of Waterloo, Waterloo.
 Fall '13
 TroyVasiga
 Computer Science

Click to edit the document details