Computer Science 61A - Fall 1999 - Harvey - Midterm 2

Computer Science 61A - Fall 1999 - Harvey - Midterm 2 - CS...

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

View Full Document Right Arrow Icon
CS 61A, Midterm #2, Fall 1999 CS61A Fall 1999 Midterm #2 Problem #1 (3 Points) What will Scheme print in response to the following expressions? If an expression produces an error message, you may just say "error"; you don't have to provide the exact text of the message. If the value of an expression is a procedure, just say "procedure"; you don't have to show the form in which Scheme prints procedures. Also, draw a box and pointer diagram, of the value produced by each expression . (cons (cons 3 4) (list 3 4)) (append '((3 4)) '(5 6)) (list 3 (list 4 5)) Problem #2 (4 Points) Consider this object class: (define-class (echoer) (instance-vars (last 'first-time)) (method (echo it) (let ((result last)) (set! last it) result))) (a) Demonstrate what this class does by filling in the blanks in the following interaction: > (define e (instantiate echoer)) > (ask e 'echo 'foo) __________________________________ file:///C|/Documents%20and%20Settings/Jason%20Raft. ..-%20Fall%201999%20-%20Harvey%20-%20Midterm%202.htm (1 of 7)1/27/2007 4:07:35 PM
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 61A, Midterm #2, Fall 1999 > (ask e 'echo 'baz) __________________________________ (b) Create a new class called rewarder with an instantiation variable secret-word , with echoer as its parent class. A rewarder should handle echo messages just like an echoer, except that if the argument to the message is the secret word, it should instead return the sentence (You win $50) . Your solution must not copy the body of the echo method from the echoer class, but must instead rely on inheritance from its parent class. Problem #3 (4 points) In this question we want a simulation of automobiles (class auto ) and junkyards (class junkyard ). (a) An auto is either wrecked or not wrecked. When instantiated, the auto is not wrecked. Write a wreck method that tells the car to become wrecked, and a wrecked? method that returns #T if the car is wrecked, or #F if not. (Once a car is wrecked, it stays wrecked forever.) An auto also should have
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This test prep was uploaded on 04/20/2008 for the course CS 61A taught by Professor Harvey during the Fall '08 term at Berkeley.

Page1 / 7

Computer Science 61A - Fall 1999 - Harvey - Midterm 2 - CS...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online