This preview shows page 1. Sign up to view the full content.
Unformatted text preview: tion 5. ;; Data for examples
(define h3 (makecard 3 ‘hearts))
(define h4 (makecard 4 ‘hearts))
(define c3 (makecard 3 ‘clubs))
(define hand (cons h3 (cons c3 (cons h4 empty))))
;;suitcount: (listof card) symbol > nat
;;Purpose: Produces the sum of the values of the cards in the loc that
have a suit that matches s.
;; Examples:
;; (suitcount hand ‘hearts) > 7
;; (suitcount hand ‘diamonds) > 0
;; (suitcount empty ‘hearts) > 0
(define (suitcount loc s)
...) 7. Suppose the following helper function has been written for you. Do not write this helper function but do read the contract and purpose carefully. ;;isperfect?: nat > boolean
;;Purpose: Produces true when value is a perfect square and false
otherwise.
;;Examples: ;;(isperfect? 0) > true
;;(isperfect? 4) > true
;;(isperfect? 5) > false
(define (isperfect? Value)
...)
Using the helper function isperfect?, complete a function perfectsquares that consumes a list of integers and produces a list that contains all elements from the original list that are perfect squares. Note that negative integers cannot be perfect squares. ;;perfectsquares: (listof int) > (listof nat)
;;Purpose: Produces a list of integers containing the elements from
original that are perfect squares.
;;Examples:
;;(perfectsquares (cons 1 (cons 0 (cons 1 (cons 2 (cons 3 (cons 4
empty))))))) > (cons 0, (cons 1 (cons 4 empty)))
;;(perfectsquares (cons 5 empty)) > empty
(define (perfectsquares original)
...) 8. Zoos record information about every type of animal in the zoo: the kind of animal (e.g. zebra), how many of this animal live at the zoo and which of the four zones is home to the animal (Desert, Forest, Arctic or Ocean) The Waterloo co
op student working at the zoo writes the following structure definition and data definition: (definestruct animalinfo (kind howmany zone))
;; An animalinfo is a (makeanimalinfo k h z) structure where
;; k is a string representing the kind of animal
;; h is a natural number representing the number of animals of this kind
;; z is a symbol ‘Desert, ‘Forest, ‘Arctic, or ‘Ocean a. What is the advantage of defining this structure instead of working with strings, numbers and symbols separately? b. List the names of the functions that are automatically generated when the structure definition is entered i...
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