Name: __________________________
Student ID: __________________________
  1. Name the five steps to top-down
    problem solving as described in the text. [5]
    ___________ ___________ ___________ ___________ ___________
  2. Describe the five program structure/flow abstractions in the text. [5]

    ___________ ___________ ___________ ___________ ___________
  3. Fill in the blank [20]:
    1. "Computers are t________s, and computing scientists are t___________s."
    2. The ___________________ function is used to determine how many LOCs are used to store an item in memory.
    3. A procedure that returns a value is called a _______________ procedure.
    4. Express 4AH in decimal: _________, octal: ____________, and binary: ________________________
    5. Before using the value of a variable for the first time in a program, we need to ________________________ and ___________________________ it.
    6. The four loop structures in Modula-2 are _____________________, _____________________, _____________________, and _____________________.
    7. A new type made from a sequence of consecutive values of an existing type is called a _______________________ of the host type.
    8. A procedure that invokes itself is called a ______________________ procedure.
    9. The function that evaluates natural logarithms on real numbers is found in the ________________________ standard library.
    10. True or False (circle one): The word FUNCTION is a legal identifier.
    11. 4GB = _______________ kilobit. (You may express it as a power of 2.)
  4. In the space provided, evaluate each of the following four Boolean expressions, or if they give an error, indicate why. [8]
    1. 'X' >= 'A' AND 'X' <= 'Z'
    2. (5 / 12 = 2) OR NOT FALSE AND FALSE
    3. (1#1)&~(1/1<1)
    4. (6 REM 4 > 2) AND (2 REM 0 = 2)
  5. Name the 3 standard I/O libraries used to open/close files, and the differences among them. Name at least two procedures from each library. [9]






  6. What is wrong with this loop, intended to count down from 100 by threes? How would you fix it? You may fix the code directly in the space below. [4]
    MODULE CountDown;
    VAR
    	counter : INTEGER;
    BEGIN
    	counter := 100;
    	REPEAT
    		statement sequence;
    		DEC (counter, 3);
    	UNTIL counter = 0;
    END CountDown.
    
  7. Rewrite the following FOR loop code snippet as a general LOOP. Don't worry about the rest of the module (IMPORT, VAR, etc.). [5]
    FOR idx := 0 TO LENGTH (name) DO
    	WriteCard (ORD (name [idx]));
    END;
    





  8. Tell me everything you know about Modula-2 records. [5]
  9. In your own words, describe what inheritance means in object-oriented programming. [5]






  10. Write a complete declaration for each of the following data types: [11]
    1. A string type:


    2. A type defining three exceptions, goodEx, badEx, and uglyEx:




    3. A type for only the lowercase letters:



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



    5. A doubly-linked (bidirectional) list of reals:





  11. Draw a diagram illustrating a doubly-linked (bidirectional) list with three nodes. Include all relevant pointers and indicate if any are NIL. [4]




  12. On a separate paper, write a Modula-2 procedure to delete a node from a doubly-linked list. A complete module is not necessary. You may assume any necessary IMPORTs have been done. You may assume type declarations given above. Pseudocode/design is not necessary to show, but is good for partial credit. [10] You may assume the user won't ask to delete the first or last node (you can ignore the tricky special cases at the end-conditions)
  13. Fill in the following grid with moves for a knight's tour. The first two positions are filled in for you. You may want to do your scratch work separately and copy just your final solution here. Partial credit for showing backtracking work.

    1   
      2 
        
  14. Consider the following binary search tree [13]:
    1. Which node is the root?

      __________________
    2. What is the depth of the tree?

      ____________
    3. Name all the leaves in this tree:





    4. Do a post-order traversal of this binary tree.
    5. Using the algorithm discussed in class, insert a node, "Cortland", into this BST and diagram the result.
    6. From the original BST, delete the node, "Gala", using the algorithm discussed in class, and diagram the result.