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?

 

  1. Preconditions and postconditions are examples of invariants.
  2. Postconditions, but not preconditions are examples of invariants.
  3. An invariant may or may not be true, depending on its point in the program.
  4. There are invariants which are neither preconditions nor postconditions.

 

3) In a Reader, when the end of file is reached, the method call

           

int c = Read();

 

returns which one of the following:

 

  1. The Unicode character –1.
  2. The Unicode character ‘-1’.
  3. The end-of-file character.
  4. A status value indicating that the end of file has been reached.

 

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()?