{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS 115 – SOS Review Package – Midterm

# Cond 3 4 2 2 5 4 a2 else a3

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: tion 5. ;; Data for examples (define h3 (make-card 3 ‘hearts)) (define h4 (make-card 4 ‘hearts)) (define c3 (make-card 3 ‘clubs)) (define hand (cons h3 (cons c3 (cons h4 empty)))) ;;suit-count: (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: ;; (suit-count hand ‘hearts) -> 7 ;; (suit-count hand ‘diamonds) -> 0 ;; (suit-count empty ‘hearts) -> 0 (define (suit-count 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. ;;is-perfect?: nat -> boolean ;;Purpose: Produces true when value is a perfect square and false otherwise. ;;Examples: ;;(is-perfect? 0) -> true ;;(is-perfect? 4) -> true ;;(is-perfect? 5) -> false (define (is-perfect? Value) ...) Using the helper function is-perfect?, complete a function perfect-squares 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. ;;perfect-squares: (listof int) -> (listof nat) ;;Purpose: Produces a list of integers containing the elements from original that are perfect squares. ;;Examples: ;;(perfect-squares (cons -1 (cons 0 (cons 1 (cons 2 (cons 3 (cons 4 empty))))))) -> (cons 0, (cons 1 (cons 4 empty))) ;;(perfect-squares (cons 5 empty)) -> empty (define (perfect-squares 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: (define-struct animal-info (kind how-many zone)) ;; An animal-info is a (make-animal-info 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

{[ snackBarMessage ]}