Name: __________________
Student ID: __________________
  1. Explain all the differences between assignment
    compatibility and expression compatibility.
    Give examples.

  2. Explain all the differences between the built-in string concatenation operator (+) and the standard library function Strings.Concat().

  3. Explain the advantages and disadvantages of FOR versus WHILE.
    Be specific (not just "one is more flexible").

  4. The following module will not compile. What is wrong? How would you fix it?
    MODULE BuggyReadVector;
    	(* user inputs values to initialize a vector *)
    	myVector : ARRAY [1 .. 11] OF CARDINAL;
    	count, counter : CARDINAL;
    	FOR count := 1 TO 10
    			counter := count;
    			ReadCard (count);
    			myVector [counter] := count;
    	myVector [counter + 1] := 11;
    END BuggyReadVector.

  5. In the remainder of this exam, you will be writing up a library and test-suite for generating pseudorandom numbers: Your library should provide a Random() function, which returns a new random real between 0 and 1 each time it is invoked. There should also be a way to seed the random number generator. The default seed (if the user does not manually set it) should be 0.
    1. Write a complete Modula-2 DEFINITION file for your library (call it PseudoRandom). In comments after each procedure declaration, define brief preconditions and postconditions for that procedure.
    2. Write a brief user manual for your PseudoRandom library. Your target audience is a fellow Modula-2 programmer who doesn't know how your library works, but wants to use it in his/her own program. Include a short abstract at the beginning of the user manual: one or two sentences summarizing the purpose of this library. Include a couple examples of how to use your library.
    3. Write pseudocode for each procedure in your library. You may wish to design additional helper functions for internal use within your library, as appropriate; if you do, then write pseudocode for them, too.
    4. List all libraries and library items you need to import.
    5. List any variables (and their types) you will declare in the scope of the library implementation module. Also, for each procedure in your library (including helper functions), list any variables (and their types) local to that procedure.
    6. Write a complete Modula-2 IMPLEMENTATION file for your library.
    7. Write a separate test suite (test harness, test framework) for your library -- a complete Modula-2 program module that imports from your library. This program should produce 1,000 random CARDINALS between 0 and 9,999 and save them into a file of the user's choosing. The numbers should be formatted ten per row, in columns: e.g.,
      	9472 3930 4876  239 1029   12 7349 1920    0 2382
      	3390 1528    3 5867 9999 8821 2002   77 1103  902