|
|
|||||||||||||||
|
|
Cpt S 355 Homework Assignment 3Assigned: April 10, 2006Due: April 24, 2006 in classAll answers except drawings must be typed! The textbook problem sets for the later chapters in the book are terrific review for the course. This assignment covers some of the most important topics discussed in the course, but the other problems are well worth your attention. You should consider each of the problems in Chapters 8-14 that touch in any way on things we have covered and try to frame for yourself the issues that are raised. If you can do this you will have a very solid understanding of these topics. Chapter 8 1. Consider the following python code:
def twice(f,x):
try:
return f(f(x))
except "oops", v:
return v
def pred(x):
if x==0:
raise "oops", x
else:
return x-1
def dumb(x):
raise "oops", x
def smart(x):
try:
return 1+pred(x)
except "oops", v:
return 1
What is the result of each of the following expressions?
2. Consider the following python code:
def hd(l):
if null(l): raise "hd"
return l[0]
def tl(l):
if null(l): raise "tl"
return l[1:]
def g(l):
try:
return hd(l)+tl(l)
except "hd":
return []
g([]) is []. Why, given that g does not handle
exception tl? Would the same be true if g handled tl
and not hd? Why?
3. Problem 8.3 from the textbook. 4. Problem 8.5 from the textbook. As noted in the problem this is tricky -- you have to think about what has to be done to set up an exception handler and to get rid of it once the block it protects exits. Chapter 12 5. Problem 12.1 -- objects on the stack, and review of object implementation issues. 6. Problem 12.7 parts (a) and (b) -- You may want to do the experiment to confirm your understanding of the language. If you do, please say what compiler you used as well as stating the results you obtained. 7. Problem 12.11 -- Use Figure 12.3 as a model for how to draw the diagrams for part (a). 8. Note that the parenthetical remark in the third-to-last
paragraph on p. 380 is not correct. I know of one class of counterexamples:
Chapter 13 9. Problem 13.2 (b) and (c) 10. Problem 13.6 (c) - Hint: this not really a Java question at all; refer to Chapter 2. 11. Problem 13.7 (a) and (b) Chapter 14 12. Problem 14.1. Example 14.2 referred to by the problem is on pp. 438-439, but to understand it you must also read example 14.1 on pp. 436-437. |
||||||||||||||
| (c) 2003 Curtis Dyreson, (c) 2004, 2005 Carl H. Hauser E-mail questions or comments to Prof. Carl Hauser | ||||||||||||||||