1. (25 points) Write a program that computes the average score of your home works. The following parameters apply:

    The program should look like this:
        Score for HW 1: 95
        Score for HW 2: 80
        Score for HW 3: 86
        Score for HW 4: 92
        Score for HW 5: 93
        Score for HW 6: 91
        Score for HW 7: 88
    
        Your average is: 89.3
    
    Note: items in bold italics are entered by the user.

    Hints, hints, hints:


  2.     PROGRAM Average;
        
        { Program to average HWs. There are 7 HWs during semester. }
        
        USES Crt;
        VAR total	: real;
           hw, grade	:  integer;
        
        CONST prompt = 'Score for HW ';
           numHW     =  7;
        
        BEGIN
        
           ClrScr;
        
           { Initialize accumulator }
        
           total := 0;
        
           { Loop through HWs and compute total sum }
        
           FOR hw := 1 TO numHW DO
           BEGIN
              write(prompt, hw, ': ');
              readln(grade);
              total := total + grade;
           END;
        
           writeln;
           
           { Can display result (with 1 decimal digit of precision) }
        
           writeln('Your average is: ', (total / numHW):0:1);
           
        END.
    

  3. (25 points) Zorro has entered the information age and he wants to use a computer to produce his famous Z. Of course the program should be flexible enough to produce outputs of different sizes. Here's how the output would look like:
        How many lines ? 6
    
        ZZZZZZ
            Z
           Z
          Z
         Z
        ZZZZZZ
    
    Note: items in bold italics are entered by the user.

    Hints, hints, hints:


  4.     PROGRAM Zorro;
        
        { Zorro's Z program: print a Z as big as desired. }
        
        USES Crt;
        
        VAR index, lines :  integer;
        
        BEGIN
        
           ClrScr;
        
           write('How many lines ? ');
           readln(lines);
        
           { Write top of 'Z' }
        
           FOR index := 1 TO lines DO
           BEGIN
              write('Z');
           END;
           writeln;
        
           { Write slash }
        
           FOR index := lines-1 DOWNTO 2 DO
           BEGIN
              writeln('Z':index);
           END;
        
           { Write bottom of 'Z' }
        
           FOR index := 1 TO lines DO
           BEGIN
              write('Z');
           END;
           writeln;
        END.
    

  5. (20 points) What does the following code produce ?
        PROGRAM Test;
        VAR ind1, ind2, ind3, line : integer;
        BEGIN
           line := 1;
           FOR ind1 := 1 DOWNTO -1 DO
              FOR ind2 := 0 TO 2 DO
    	  BEGIN
    	     FOR ind3 := ind2 TO (2 + ind1) DO
    	        write('*');
    	     writeln('.');
    	     line := line + 1;
    	  END;
        END.
    
  6.     ****.
        ***.
        **. 
        ***.
        **.
        *. 
        **.
        *.
        . 
    

  7. (15 points) The following code contains 5 syntax errors. Identify the line number and the error.
      1.  PROGRAM Flawed;
      2.  VAR value : integer;
      3.      index : real;
      4.  CONST limit : 5;
      5.  BEGIN
      6.     value := 1.0;
      7.     FOR index = 1 TO limit DO
      8.        value := value + index;
      9.     value := value / limit;
      10. END.
    
    1. Line: 4__    Error: Initialize CONST with "=", not ":"
    2. Line: 6__    Error: Type mismatch, value declared as integer
    3. Line: 7__    Error: Expected ordinal, index decalred as real
    4. Line: 7__    Error: Initialize control variable with ":=", not "="
    5. Line: 8__    Error: Type mismatch, right hand side yields real ("/")

  8. (15 points)
    1. How many times does the following loop execute ? 6___
          FOR index := -2 TO 3 DO
      

    2. What is the value of variable a after the following assignment ? 1356
          a := 13 * (1357 DIV 13) + (1357 MOD 13 - 1);
      

    3. What is the value of variable a after the following assignment ? 'a'_
          a := pred(chr(ord('a') + ord('1') - ord('0')));
      

    4. Assume that you have the following input:
          1 20 5
          31
      
      What is the value of variable c after the following statements ? 31__
          VAR a, b, c : integer
          ...
             read(a);
             readln(b);
             readln(c);
      

    5. Assume that you have the following input:
          1 20 5
          31
      
      What is the value of variable d after the following statements ? 0___
          VAR a, d : integer;
              b, c : char;
          ...
             read(a);
             read(b);
             read(c);
             readln(d);