All
material is ©opyright 2002 Brent M. Dingle
DO NOT REDISTRIBUTE THIS. No
full answer key
will be provided.
Feel free to pester the TA’s about specific questions =)
1. |
True or
False |
A compiler can detect syntax and logical errors. |
|
|
|
2. |
True or
False |
In DOS, the character ‘?’ is a wild character. |
|
|
|
3. |
True or
False |
DOS directories are tree structured. |
|
|
|
4. |
True or
False |
Blaise Pascal is the original creator of the Pascal
programming language. |
|
|
|
5. |
True or
False |
A variable name may have spaces in it. |
|
|
|
6. |
True or
False |
A variable of type integer has NO maximum value that it
can contain. |
|
|
|
7. |
True or
False |
A floppy disk is one example of the main memory used in a computer. |
|
|
|
8. |
True or
False |
Every IF statement must have an ELSE following it. |
|
|
|
9. |
True or
False |
The result of 7 MOD 3 is 2. |
|
|
|
10. |
True or
False |
The decimal equivalent of the binary number 1011 is 11. |
Answer 11: |
A |
B |
C |
D |
E |
a. The hard disk on which the program was saved.
b. A printout of the program.
c. A CD-ROM with the source code burned on it.
d. A 3 1/2 inch floppy disk with the program saved on it.
e. A picture of the program's output.
Answer 12: |
A |
B |
C |
D |
E |
a. an order set
b. a solution set
c. a procedure
d. an algorithm
e. an implementation
Answer 13: |
A |
B |
C |
D |
E |
a. 16
b. 8
c. 6
d. 4
e. 2
Answer 14: |
A |
B |
C |
D |
E |
a. sum
b. average
c. next
d. first
e. program
Answer 15: |
A |
B |
C |
D |
E |
PROGRAM Shrug;
VAR
num : integer;
BEGIN
Randomize;
num := Random(100);
Writeln(num);
END.
count := 0;
A := 1;
B := 1;
while (count <= 4) do
BEGIN
count := count + 1;
B := B + 1;
A := A + B - count;
write(A, ' '); { there is a space between those single quotes }
END;
26. |
True or
False |
The body of a repeat-until loop is always executed
at least once. |
|
|
|
27. |
True or
False |
The value
of a boolean variable must be either true or false. |
|
|
|
28. |
True or
False |
A repeat-until loop continues to execute until the
control expression evaluates to false. |
|
|
|
29. |
True or
False |
The control variable of a for loop must always be
of type integer. |
|
|
|
30. |
True or
False |
At the end
of a program using input and output files, only the input file must be
closed. |
|
|
|
31. |
True or
False |
Every CASE statement
must have an ELSE. |
|
|
|
32. |
True or
False |
Every procedure must have at least one parameter. |
|
|
|
33. |
True or
False |
true AND false evaluates to _________ |
|
|
|
34. |
True or
False |
(1011 = 11) OR (0 = 15 MOD 5) evaluates to _________ |
|
|
|
35. |
True or
False |
The value of an actual variable parameter CAN be changed by a procedure. |
a. bottom-up design
b. subjugate and rule design
c. top-down design
d. a & c
e. b & c
Answer 11: |
A |
B |
C |
D |
E |
The next 2 questions refer to the below code
(assume embedded in a working program and number is
type integer):
CASE
number OF
0..3
: Writeln(‘first’);
4 : Writeln(‘second’);
5 : Writeln(‘third’);
6..9
: Writeln(‘fourth’);
ELSE
Writeln(‘odd’);
a. first
b. second
c. third
d. fourth
Answer 12: |
A |
B |
C |
D |
E |
a. first
b. second
c. third
d. fourth
e. odd
Answer 13: |
A |
B |
C |
D |
E |
FOR N:= 1 DOWNTO 3 DO
BEGIN
Write(N,
‘ ‘); { there is a space
between those single quotes }
END;
FOR N:= 1 TO 2 DO
BEGIN
FOR M:= 3 DOWNTO 1 DO
Begin
Write(N
* M, ‘ ‘); { there is a space
between those single quotes }
End;
END;
N := 0;
_________ (N < ___________) DO { a while loop }
BEGIN
______ := N + ___________ ;
______________ ( N, ‘ ‘ );
END;
C, a
B, a
A, a
C, b
B, b
A, b
C, a
You may assume I and K are variables of type char.
I: = ___________;
WHILE ( I < ____________ ) DO
BEGIN
K := ___________;
WHILE ( ___________ >= ‘A’ ) DO
Begin
writeln ( ____________ , ‘, ’, ___________ );
_______ := pred( __________ );
End;
I := ___________ ( I );
END;
writeln ( ‘ _____________
’ ); { notice the single quotes are already there }
PROGRAM CashRegister;
CONST
RATE = ______________ ; { rate = sales tax rate Blank 1 is to the left }
WIDTH = 6; { field width for money amounts }
VAR
price, bill
: ____________; {
Blank 2 is to the left }
number :
______________; {
Blank 3 is to the left }
PROCEDURE Total(var N : integer; var P, B : real);
BEGIN
_________
:= __________ * ( P + RATE * P); {
Blanks 4 and 5 are to the left }
END; { Total }
BEGIN { main }
Writeln(‘Enter the price: ’);
Readln(
________________ ); { Blank 6 is to the left }
Writeln(‘Enter the number of items: ’);
Readln(
_______________ ); {
Blank 7 is to the left }
{ Call the procedure Total }
Total(
number, ____________ ,
_____________); { Blanks
8, 9 are to the left }
Writeln( number, ‘ items at $’, price : WIDTH:2);
Writeln(‘Total Bill $’, __________ : WIDTH:2, ‘ with tax.’);
{
Blank 10 is above }
END.
44. |
True or
False |
Every IF statement must have an ELSE following it |
|
|
|
45. |
True or
False |
A unit can never contain procedures, it may only contain functions. |
|
|
|
46. |
True or
False |
A block of code does NOT always have a parameter list. |
|
|
|
47. |
True or
False |
The default extension to a turbo pascal unit is .unt |
|
|
|
48. |
True or
False |
The body of any while loop is always executed at least once. |
|
|
|
49. |
True or
False |
The parameters of a function are also called the arguments of the function. |
|
|
|
50. |
True or
False |
The interface section of a unit is the public section. |
|
|
|
51. |
True or
False |
Assume m = 3 and y = 56. Then the procedure call: is guaranteed to perform the same as the procedure call: printem(y, m); (or rather the order of parameters in procedure calls does NOT matter). |
|
|
|
52. |
True or
False |
Pascal supports the definition of new data types. |
53. Given the below procedure
declaration:
PROCEDURE alpha( a : real;
VAR b : real);
Which of the following
procedure calls will NOT work (cause an error):
a. alpha( x, y);
b. alpha( 5, y);
c. alpha( y, 5);
d. alpha( y, x);
e. all of the above will work just fine with no errors
Answer 10: |
A |
B |
C |
D |
E |
54. Given the below 4 types of declarations:
a. Constant Declarations
b. Variable Declarations
c. Type Declarations
d. Procedure and Function Declarations
What is the correct order of the declarations according to the book?
Answer 11: |
a, b, c, d |
a, c, b, d |
d, c, b, a |
c, a, b, d |
d, b, a, c |
The next TWO questions refer to the below code:
{Procedure
Swap places the value of U in Z and the value of Z in U}
Procedure
Swap(Var U: integer; z : integer);
Var
temp: Integer;
Begin
temp := U;
U := Z;
Z := Temp;
End;
Begin
X := 10;
Y
:= 20;
Swap(x, y);
writeln(x,
‘ ‘, y);
End.
55. (6 points) What is the output of the above code (assume no syntax errors, X, Y are integers and embedded in a working program)?
56. (8 points) What change(s) must be made to the above code to make it actually swap the values (i.e. correct the parameter list line)
Procedure Swap(
______________________________________________________ );
All
material is ©opyright 2002 Brent M. Dingle
DO NOT REDISTRIBUTE THIS. No
full answer key
will be provided.
Feel free to pester the TA’s about specific questions =)
57. (10 points, 2 per blank) Fill in the blanks below so that the below REPEAT loop would output:
3 , 6 , 9 , 12 (all on the same line)
N := 0;
REPEAT
______ := N + ___________ ;
______________ ( N, ‘ , ‘ );
_________ (N >= ___________) { end of repeat-until loop }
58. (50 points, 5 per blank) The following program should calculate the value of 78 and then 87. Fill in the blanks so the program will properly function.
PROGRAM
p179;
VAR
base :
real;
exp :
integer;
ans :
real;
{ Function Power takes 2 arguments and returns a
type real }
_____________ Power( x :
real; exponent : integer) :
___________;
VAR
product
: real;
count :
integer;
BEGIN
product
:= 1;
count
:= exponent;
_____________ ( __________________ > 0 ) DO
Begin
________________ := product * _____________;
count := count – _____________________;
End; { end of while count
> 0 }
____________ := product; {
set the return value to be = product }
END;
BEGIN
base :=
____________________;
exp :=
8;
ans :=
Power(base, exp);
writeln(base, ‘ raised to the ‘, exp, ‘ = ‘, ans);
ans :=
Power(exp, ___________________);
writeln(exp, ‘ raised to the ‘, base, ‘ = ‘ , ans);
END.
59.
(50 points, 5 per blank)
The following program should display the following output:
x = 5 y = 1 z = 45
x = 1 y = 5 z = 5
a = 5 b = 1 c = 45
x = 5 y = 1 z = 45
x = 1 y = 5 z = 5
a = 1 b = 5 c = 45
Fill in the blanks to make it so it actually works as it should.
PROGRAM
la;
VAR
a, b, c
: integer;
PROCEDURE WriteSwap( ________ x, _____:
_____________; z : integer);
BEGIN
______________('x = ', x, ' y = ', y, ' z = ', z);
z :=
__________; { swap x and y }
x := y;
____________ := z;
Writeln('x = ', x, ' y = ', y, ' z = ', z);
END;
BEGIN
a :=
___________ ;
b := 5;
c :=
____________;
WriteSwap(________, ________, c);
Writeln('a
= ', a, ' b = ', b, ' c = ', c);
WriteSwap(a, b, c);
Writeln('a = ', a, ' b = ', b, ' c = ', c);
END.
60. |
True or
False |
Data type real is an enumerated type. |
|
|
|
61. |
True or
False |
Pascal allows you to declare subrange types. |
|
|
|
62. |
True or
False |
A block of code always has a parameter list. |
|
|
|
63. |
True or
False |
Arrays are collections of values all of different data types. |
|
|
|
64. |
True or
False |
Arrays may be accessed sequentially or randomly. |
For the next 3 questions consider:
65. ( 4 points) Part 1 is referred to as:
a. None of the below
b. Subscript
c. Array Name
d. b and e, the terms are interchangeable
e. Value of the array element
Answer 6: |
A |
B |
C |
D |
E |
66. ( 4 points) Part 2 is referred to as:
a. None of the below
b. Subscript
c. Array Name
d. b and e, the terms are interchangeable
e. Value of the array element
Answer 7: |
A |
B |
C |
D |
E |
67. ( 4 points) Part 3 is referred to as:
a. None of the below
b. Subscript
c. Array Name
d. b and e, the terms are interchangeable
e. Value of the array element
Answer 8: |
A |
B |
C |
D |
E |
68. ( 4 points) Which of the following is NOT an ordinal type:
Answer 9: |
A |
B |
C |
D |
E |
69. ( 7 points) Given
VAR
x : array[-5..20] of char; { yes this really compiles, it’s just a bad way to do it } .
i : integer;
And i is initialized to 20. i.e. there was a line that said i := 20;
Which of the following will COMPILE - circle your answer
a.
x[-10] := ‘e’; compiles
= YES or NO
b.
x[-5] := ‘c’; compiles
= YES or NO
c.
x[2] := ‘g’; compiles
= YES or NO
d.
x[ i ] := ‘m’; compiles
= YES or NO
e.
x[12] := ‘hello’; compiles
= YES or NO
f.
x[54] := ‘q’; compiles
= YES or NO
g. x[ i + 12 ] := ‘k’; compiles = YES or NO
70.
( 7 points) The
below x is NOT the same as the previous question.
Given
VAR
x : array[5..20] of char; { yes this really compiles, it’s just a bad way to do it } .
i : integer;
x and i are the ONLY variables declared.
And i is initialized to 20. i.e. there was a line that said i := 20;
Which of the following will COMPILE AND RUN – circle your answer
a.
x[ i ] := ‘e’; compiles AND
runs = YES or NO
b. x[2] := ‘g’; compiles AND runs = YES or NO
c.
y[ i ] := ‘m’; compiles
AND runs = YES or
NO
d.
x[12] := ‘hello’; compiles
AND runs = YES or
NO
e. x[ i + 12 ] := ‘k’; compiles AND runs = YES or NO
f. x[54] := ‘q’; compiles AND runs = YES or NO
g.
x[ i – 5 ] := ‘z’; compiles
AND runs = YES or
NO
71. (6 points) State the TWO properties of ENUMERATED types as given in class and in the notes.
72.
(2 points) Given:
TYPE
PRIME_COLORS = (red, green, blue);
PRIME_COLORS is obviously an ordinal type but is also an
______________________________ type.
73. (BONUS 2 points) The function call: N := pos(‘be’, ‘dobedobe’); would set N to be what value (assume no errors) ?
74. (5 points) To declare a TYPE that has 5 elements of type real, indexed from 0 to 4 you would finish the below how?
TYPE
ARY_0_TO_4 = array[ _____________ ] of _____________________ ;
75. (2 points) To declare a variable of type ARY_0_TO_4 you would complete the following how?
VAR
x : ____________________________ ;
76.
( 10 points ) Fill in the blanks below so that the below
WHILE loop would output:
3 5
7
i := ______________;
while ( ______ <= _______ ) DO
Begin
write( i, ‘ ‘);
i := ____________ + _______________;
End;
77. ( 6 points ) Fill in the below blanks so
a. the variable infile is associated with the file named in.txt
b. and infile is opened for READING
__________________ ( infile, ‘________________________’ );
__________________ ( infile );
78. ( 6 points ) Fill in the below blanks so
a. the variable outfile is associated with the file named out.txt
b. and outfile is opened for WRITING
__________________ ( outfile, ‘________________________’ );
rewrite ( _______________________ );
79. ( 14 points ) Fill in blanks so the array of integers is initialized to all 0 values.
TYPE
ary0to20 : array[0..20] of _______________ ; { declare an array of integers }
VAR
x : _____________________________ ;
i : _____________________________ ;
BEGIN
{ initialize array named x to be
all zeros }
for ( i := _________________ to ______________ ) do
begin
x[ _____________ ] := _____________;
end;
{ rest
of code continues …}
80. ( 9 points ) Fill in the blanks to the below sorting code PROCEDURE:
Assume everything in all capital letters is declared as needed.
NUM_SHELVES is a constant = the size of the shelf array (the number of shelves)
i and k should be local integer variables.
ContentsLess(item1, item2) returns true if item1 is considered less than item2.
Exchange(item1, item2) switches the values of item1 and item2.
_____________________
SortThem(VAR shelf : WHATS_ON_SHELF_TYPE);
VAR
i, k
: ____________________ ;
BEGIN
__________ i := 1 to NUM_SHELVES ____________
BEGIN
for k := i + _____________ to ___________________________ do
Begin
if (ContentsLess(shelf[ k ], shelf[ i ]) ) ______________
begin
Exchange(_____________________
, shelf [k]);
end
End
{ for k }
________________ { end of for i }
END;
PROGRAM
Quiz;
CONST
MAX_STUD =
10;
TYPE
STUD_REC =
RECORD
name : ___________________ ;
____________ : integer;
____________ : ___________________ ;
END;
STUD_ARY = array [1.. ______________________ ] of _____________;
VAR
Student : __________________________________ ;
PROCEDURE ToUpper(VAR str : string);
VAR
index : ____________ ;
BEGIN
for index := 1 to length(___________) do
Begin
_______[___________] := _________(str[index]);
End;
END;
All
material is ©opyright 2002 Brent M. Dingle
DO NOT REDISTRIBUTE THIS. No
full answer key
will be provided.
Feel free to pester the TA’s about specific questions =)