Name: __________________
Student ID: __________________
  1. Describe the five program structure/flow
    abstractions mentioned in the text.

    ___________ ___________ ___________ ___________ ___________
  2. Fill in the blank:
    1. "Computers are t________s, and computing scientists are t___________s."
    2. A procedure that returns a value is called a ____________ procedure.
    3. Before using the value of a variable for the first time in a program, we need to ________________ and ___________________ it.
    4. True or False (circle one): The word FUNCTION is a legal identifier.
    5. The three loop structures in Modula-2 are _______________, _______________, and ______________.
    6. A new type made from a sequence of consecutive values of an existing type is called a ________________ of the host type.
    7. What English part of speech should a variable generally be? ___________
    8. The ______ function is used to determine how far a real/integer is from zero.
    9. The function that evaluates natural logarithms on real numbers is found in the _______________ standard library.
    10. Redirection of the standard input/output channels is handled by the ______________ library.
    11. A procedure that invokes itself is called a _________________ procedure.
  3. Explain all the differences between the following, and give examples of each:
    1. reserved words:


    2. standard identifiers:


    3. standard library items:


  4. Write a complete declaration for each of the following data types:
    1. A string type:



    2. An enumeration type representing the months of the year:




    3. A type holding one string for each month of the year:



    4. A type for only the uppercase letters:



    5. A type for an m by n matrix of booleans:



  5. Evaluate each of the following expressions, or if it produces an error, describe the error. Assume all necessary IMPORTs have been done. Assume the following declaration and initialization:
    	myApple : ARRAY [0..5] OF CHAR;
    	myApple := "granny smith";		
    1. 11 REM 0
    2. 12.2 MOD 5
    3. WriteFixed (23.468, 4, 8); (show output, including any spaces)
    4. ~(3<5)&~3#5
    5. LENGTH(myApple)
    6. (LENGTH(myApple) > 0) AND (CAP(myApple[0]) = 'G')
    7. Strings.Compare (myApple, "Granny Smith")
    8. 'C' > 'A'
    9. 'C' - 'A'
    10. ORD ('C') - ORD ('A')
    11. 'C' + 'A'
    12. ORD (March) (using the enumeration type you defined above)
  6. Show the results (output and/or errors) both with and without the VAR in the formal parameter list and explain.
    MODULE SwapTest;
    FROM SWholeIO IMPORT
    	WriteCard;
    
    PROCEDURE Swap (VAR a, b: CARDINAL);
    VAR
    	tmp : CARDINAL;
    BEGIN
    	tmp := a;
    	a := b;
    	b := tmp;
    END Swap;
    
    VAR
    	a, b: CARDINAL;
    BEGIN
    	a := 2;
    	b := 5;
    	Swap (a, b);
    	WriteCard (a, 0);
    	WriteCard (b, 0);
    END SwapTest.
    



  7. Consider the following procedure:
    PROCEDURE SumPlus1 (VAR a, b: CARDINAL): CARDINAL;
    	(* returns a+b+1 *)
    BEGIN
    	INC (a);
    	RETURN a + b;
    END SumPlus1;
    
    Assume there is a global variable x := 5. If we invoke SumPlus1 (x, x), we might expect the result to be 11, but it is not. What is returned instead, and why? How would you fix this?