CS 365 Homework 2 Answers
- 17
- The arrays "x" and "m" have to be put in separate procedures so that
one is active only when the other is not.
- 24
-
Example code:
case ThisMonth of
Sep, Apr, Jun, Nov: days := 30;
Feb: days := 28;
Jan, Mar, May, Jul, Aug, Oct, Dec: days := 31;
end;
The last case arm could be handled by an otherwise clause, or all
the months could be written as separate cases.
- 25
-
Suppose there are N cases. Sequential test takes at least one test, at
most N tests, and an average of N/2 tests.
A jump table takes constant time.
Binary search takes average time proportional to log_2(N).
The key parameter is the number of cases.
- End of chapter, 15
-
This is one of many possible ways to write it:
< case statement > ::= case < expression > of
< case clause > [; < case clause >]*
[otherwise < statement >] end
It is OK to make the otherwise clause mandatory.
Return to MacLennan's home page
Send mail to Bruce MacLennan / MacLennan@cs.utk.edu
Last updated: Mon Feb 11, 2002
Fri Mar 8 09:56:02 EST 2002