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.)
Name the five computer hardware abstractions described in the text.
(Again, concepts are more important than exact wording.)
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 ||______
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
| (6 REM 4 > 2) AND (2 REM 0 = 2)
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);
What is wrong with this loop? How would you fix it?
counter : CARDINAL;
counter := 1;
REPEAT (* count up to 10 by twos *)
counter := counter + 2;
UNTIL counter = 10;
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
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.
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.