Student ID:
  1. Name the five steps to top-down problem solving as described in the text.
    (It's okay if you can't remember the exact wording;
    the concepts are more important.)
    ___________ ___________ ___________ ___________ ___________
  2. Name the five computer hardware abstractions described in the text. (Again, concepts are more important than exact wording.)
    ___________ ___________ ___________ ___________ ___________
  3. Write "yes" or "no" next to each of the following six strings to indicate if it is a legal Modula-2 identifier.
    numApples ______ sockeye-salmon ______ 95percent ______
    DO ______ L337_hAX0rz ______ Module ______
  4. Evaluate each of the following four Boolean expressions, or if they give an error, indicate why.
    ~(CAP('q') <> 'Q') _________________________
    (5 / 11 = 2) OR NOT FALSE AND FALSE _________________________
    0#0&~0/0<0 _________________________
    (6 REM 4 > 2) AND (2 REM 0 = 2) _________________________
  5. Given the following declarations:
    	card1, card2 : CARDINAL;
    	int1, int2 : INTEGER;
    	real1, real2 : REAL;	
    Indicate whether each of the following five statements is "okay", "expression incompatible", or "assignment incompatible". A statement cannot be both expression and assignment incompatible; the first error returned is expression incompatibility. Assume all the variables have been initialized already.
    int1 := int2 - 56; _______________________
    int1 := card2 DIV 7; _______________________
    real1 := real2 + 23; _______________________
    int1 := VAL(CARDINAL, 52.3); _______________________
    real1 := TRUNC(real2); _______________________
  6. What is wrong with this loop? How would you fix it?
    MODULE BuggyLoop;
    	counter : CARDINAL;
    	counter := 1;
    	REPEAT				(* count up to 10 by twos *)
    		statement sequence;
    		counter := counter + 2;
    	UNTIL counter = 10;
    END BuggyLoop.
  7. In the space below, write pseudocode for a function procedure GetReal that does robust interactive user input:

    The procedure should prompt the user to enter a positive real value, which is then passed back to the calling context via one of GetReal's parameters. If the user does not enter a positive value, print an error message and prompt the user again. Another parameter should specify how many times to keep trying before giving up. The function should also return TRUE if the user eventually typed a good value, or FALSE if it had to give up.

  8. On a separate sheet of paper, write a complete Modula-2 module, declaring the procedure GetReal. The body of the module should invoke GetReal a few times to test it out.

    Hints: What parameters does GetReal need? Call-by-value or call-by-reference? What return type should it use? Be careful to choose different names for formal parameters and actual parameters.

    Please try to indent and format your code properly so it can be read easily. You are not required to comment your code on this exam, however if your code is incorrect, your comments may earn you partial credit if they show good design thinking. Little partial credit will be given for uncommented incorrect code.