1) Which of the following Pascal code segments are equivalent in terms 	of function?
   FIRST:
	repeat
	  < action>
	until A or B;
   SECOND:
	while not (A or B) do
	  < action>;
   THIRD:
	while not A and not B do
	  < action>;
 A) FIRST and SECOND
 B) SECOND and THIRD
 C) THIRD and FIRST
 D) all are the same
 E) none are the same

2) Which of the following are legal Pascal enumberated type 	definitions?
 A) type data = (a,b,c);
 B) type data = ('a','b','c');
 C) type data = 'a', 'b', 'c';
 D) all of the above are legal
 E) none of the above are legal

3) Which of the following loops repeat while a stated condition is true?
 A) if/then/else
 B) for
 C) repeat
 D) while
 E) case

4) Which is the slowest in a computer?
 A) RAM
 B) cache
 C) ROM
 D) hard drives
 E) CPU
5) All functions:
 A) require at least 1 argument
 B) require exactly 1 argument
 C) return a value
 D) never return a value
 E) both C and D

6) Syntax errors are usually found:
 A) at run time
 B) at compile time
 C) at execution time
 D) by the EMACS editor
 E) by the Pascal editor

7) Pascal is:
 A) a compiler
 B) a debugger
 C) your TA
 D) a text editor
 E) none of the above answers are appropriate

8) In Pascal syntax, which of the following is always legal?
 A) b + a;
 B) c + b;
 C) 4 div a;
 D) if (not d) then goto 70;
 E) none of the above answers are appropriate

9) All procedures:
 A) return a value
 B) can never receive an argument
 C) must receive an argument
 D) A and C
 E) none of the above answers are appropriate
10) A recursive procedure is one that:
 A) never ends
 B) calls a different procedure or function
 C) cannot be done in Pascal
 D) calls itself any number of times
 E) none of the above answers are appropriate

11) The comparison of ((A or B) and (not A)) is equivalent to:
 A) A and B
 B) B
 C) TRUE
 D) FALSE
 E) A xor B

12) In Pascal a loop control variable can be:
 A) an integer
 B) a character
 C) boolean
 D) any of the above
 E) none of the above answers are appropriate

13) gpc finalexam.p -o exam
 A) compiles a program called exam into an object file called finalexam
 B) creates a file called exam.o
 C) creates an a.out file which will run the Pascal code writen in exam
 D) does not work on our UNIX system
 E) none of the above answers are appropriate

14) Arrays in Pascal can be indexed by:
 A) any type of number
 B) any type of number or character
 C) only integers
 D) any ordinal values
 E) any value at all
15) All arrays in Pascal:
 A) have a max size of 64
 B) have a max size of 128
 C) can have a max value of 64
 D) can have a max value of 128
 E) none of the above answers are appropriate

16) Types in Pascal:
 A) are never used
 B) are always used for arrays
 C) are used to define your own data type
 D) can only be used if you are creating and deleteing files
 E) none of the above answers are appropriate

17) Records in Pascal:
 A) do not exist
 B) can only be used with programs using file I/O
 C) are defined in the CONST section of the program
 D) are defined in the VAR section of the program
 E) are defined in the TYPE section of the program

18) Every Pascal program MUST have:
 A) a header and a body
 B) declarations and a body
 C) a header and declarations
 D) a header, variable declarations and a body
 E) a header, type definitions, variable declarations and a body

19) What does the following code produce on the screen?
	for j:=0 downto 5 do
	  writeln('Hello World!');
	writeln('Goodbye!');
 A) 	Nothing
 B) 	Hello World!
 C) 	Goodbye!
 D) 	Hello World! (6 times)
      	Goodbye!
 E) 	Hello World! (5 times)
	Goodbye!
Use the following declarations where applicable:
Answer the next questions by finding the error in each code segment
Circle the error and explain what is wrong.

type	str	= 	packed array [1..100] of char;
	arr	= 	array [1..100] of integer;
	datas	= 	array [1..100] of str;

var	a, b, c		: integer
	x, y, z		: real;
	l, m, n	: char;
	b1, b2	: boolean;
	s1, s2		: str;
	page1		: datas;
	nums		: arr;

   1)	a:=0;
	for a:=1 to 100 do
	    readln(str[a]);

   2)	l:='1';
	for m:=l to '9' do
	    write(nums[m]);

   3)	x:=y;  y:=z;  z:=x;
	write(page1[x]:5:2, page1[y]:5:2, page1[z]:5:2);

   4)	for m:= 'A' to 'Z' do
	    write(nums[ord(m)]:5);
	writeln(b1[ord(m)]);

   5)	for b:= 6 downto 2 do
 	    str:='Hello World!';

   6)    b1 := m = n OR y< z;

   7)    s1:=s2;
	if s1=s2 then writeln("s1 and s2 are equal");
Trace through the following programs writen below.  Assume all
programs compile and run fine.  In the space below each program
write out the output as it would appear if you ran the program.
You may abbreviate when the output become long, as long as you
display at least SOME correct output.

program count(output);

var	i	: integer;
	arr	: array[0..99] of integer;

begin
	for i:=0 to 99 do
		arr[i]:=i*i;
	for i:=99 downto 50 do
		write(i:5, arr[i]:5, 99-i:5, arr[99-i]:5);
end.


program decode(output);
 
var	i	: integer;
	word	: packed array[1..21] of char;

begin
	word:='I   l!imkiew sttoa e';
	for i:=1 to 21 do
		if (i>10) then write(word[(18-i)*2])
		else write(word[i*2-1]);
	writeln;
end.
 

program tri(output);

var 	i, j, k	: integer;

begin
	k:=0;
	for i:=1 to 7 do begin
		for j:=1 to i do begin
			write(k:3);
			k:=k+1;
		end;
	writeln;
	end;
end.