CSE143 – Miniquiz #6
02/04/2003
Name:
Section:
Directions: Answer each of the following questions. Question 4 is optional and may be discussed during section.
Questions:
1) Name one reasonable precondition of the function: divide(int a, int b)that returns the value a/b.
2) Which of the following are true about invariants?
3) In a Reader, when the end of file is reached, the method call
int
c = Read();
returns which one of the following:
4) Optional Question: Consider the following code fragment for a function:
public int foo(){
int retVal = 0;
int value = bar();
assert
value < 3 && !(value <= 0);
if(value
< 2)
retVal = value;
return
retVal;
}
Assuming that the function bar()returns
a value of type int, then what are the only possible value(s) that could be
returned by foo()?