CPSC 110 ID:
________________________
(c)opyright 2002 Brent M. Dingle Section:
____________________
TA:
________________________
INSTRUCTIONS:
All answers should be PRINTED. If I am not able to easily
read the answer, you will NOT receive any credit for it. Please use a PENCIL
and an eraser (if/when needed).
1. |
True or
False |
The body of a repeat-until loop is always executed
at least once. |
|
|
|
2. |
True or
False |
The value of a boolean variable
must be either true or false. |
|
|
|
3. |
True or
False |
A repeat-until loop continues to execute until the
control expression evaluates to false. |
|
|
|
4. |
True or
False |
The control variable of a for loop must always be
of type integer. |
|
|
|
5. |
True or
False |
At the end of a program using input
and output files, only the input file must be closed. |
|
|
|
6. |
True or
False |
Every CASE
statement must have an ELSE. |
|
|
|
7. |
True or
False |
Every procedure must have at least one parameter. |
|
|
|
8. |
True or
False |
true AND false evaluates to _________ |
|
|
|
9. |
True or
False |
(1011 = 11) OR (0 = 15 MOD 5) evaluates to _________ |
|
|
|
10. |
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 |
The
next two questions refer to the procedure declaration:
PROCEDURE
Example(var A: integer; B: integer);
a. modular parameters
b. actual parameters
c. initial parameters
d. formal parameters
Answer 14: |
A |
B |
C |
D |
E |
Answer 15: |
A |
B |
C |
D |
E |
PRODECURE Stuff( X, Y: integer; var Z: integer);
Which of the following would be a valid procedure call? (Assume A and B are
variables of type integer and the call is made in a working program at an
appropriate place)
a. Stuff(4, A, 4 + B);
b. Stuff(A, 4 + B, B);
c. Stuff(A, B, 4);
d. All of the above
e. None of the above
Answer 16: |
A |
B |
C |
D |
E |
FOR N := -1 to 5 DO
Begin
Writeln(N);
End;
FOR N:= 1 DOWNTO 3 DO
BEGIN
Write(N,
‘ ‘); { there is a space
between those single quotes }
END;
FOR N:= 1 TO 3 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, ‘ ‘ );
END;
FOR N:= 0 TO 5 DO
Begin
IF (N MOD 3 = 0) THEN
Writeln(N, ‘ ‘, N DIV 3); { there is a space between the single quotes }
End;
Assume the code is embedded in a working program with no syntax errors.
assign(file1, 'data1.txt');
rewrite(file1);
assign(file2, 'data2.txt');
reset(file2);
assign(file3, 'data3.txt);
append(file3);
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.