{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs61a_final_sp01

cs61a_final_sp01 - CS 61A Spring 2001 Final exam cfw\bf...

This preview shows pages 1–3. Sign up to view the full content.

CS 61A Spring 2001 Final exam {\bf Question 1 - Santa's at Club Med (Recursion and HOFs) (6 points):} Santa wants to take a vacation this coming year and asks for you to fill in for him. You realize you'll need a way to store the names of all the little boys and girls so that later you can decide who has been naughty and who has been nice. You decide to store the names in a sentence, and convert each name into a single word by sticking a dash -'' in between. For example, cindy brady'' would be encoded as {\tt cindy-brady}. (Assume nobody has a dash in their first or last names.) You write the constructor {\tt make-name} as follows: (define (make-name firstname lastname) (word firstname '- lastname)) a) Using recursion, write {\tt last-name} which takes a name and returns the last name. {\bf Do not write any auxiliary functions}, and assume {\tt name} is the return value from a valid call to {\tt make-name}. b) What type of process was evident in {\tt last-name}? Circle one. RECURSIVE ITERATIVE c) Finally, write a function {\tt make-filterer} that takes in a name predicate {\tt good-child?} and returns a function that, when applied to a sentence of names, only keeps the names of children who are good''. {\bf Use no explicit recursion.} Here's an example: > (define (good-kids? name) (equal? 'brown (last-name name))) > (define keep-good-kids (make-filterer good-kids?)) > (keep-good-kids '(bart-simpson charlie-brown eric-cartman bobby-brown)) '(bart-simpson charlie-brown eric-cartman bobby-brown calvin-hobbes)) (charlie-brown bobby-brown) (define (make-filterer good-child?) {\bf Question 2 - Hal, open the pot doors... (Concepts) (1 point)} A few years ago, NASA lost a spacecraft in the atmosphere of Mars, because they didn't realize that certain crucial information needed for the calculation of the descent to the red planet was provided to NASA in pounds and not in kilograms as expected. They used the data in pounds as if they were kilograms and the miscalculation led to the burning of the spacecraft in the Mars' atmosphere. Which concept introduced in CS61A would have prevented this problem? {\bf Check one.} $\smdash$ memoization

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
$\smdash$ local state $\smdash$ type-tagged data $\smdash$ higher-order functions $\smdash$ streams $\smdash$ recursion $\smdash$ hierarchical data {\bf Question 3 - What all of us do on the beach... (Scoping) (4 points)} For each of the following expressions, indicate what a lexically scoped Scheme will return and what a dynamically scoped Scheme will return. If the evaluation results in an error, just write the word {\tt error}. (Note: this is the first thing you type into the Scheme session) > (let ((f (lambda (y) (+ x y))) (x 100)) (f 25)) $\dash$ in lexical scope, $\dash$ in dynamic scope > (define z 100) > (define (change z) (set! z 7)) > (change z) > z $\dash$ in lexical scope, $\dash$ in dynamic scope {\bf Question 4 - {\it verdad o mentira} (Miscellaneous True or False) (5 points)} For each of the following, circle {\tt true} or {\tt false} and explain why {\bf in fewer than 15 words}.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 12

cs61a_final_sp01 - CS 61A Spring 2001 Final exam cfw\bf...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online