Quiz 3 Name:
_____________________
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 |
(1010 = 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;
7 or Seven (no partial credit)
FOR N:= 1 DOWNTO 3 DO
BEGIN
Write(N,
‘ ‘); { there is a space
between those single quotes }
END;
There is no output = 5 points
If they said 1 2 3 or 3 2 1 give them 1 point
If they leave the question blank (i.e. there is nothing written here) give them 1 point for the benefit of the doubt.
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;
Run this and check it, it should be 3 2 1 6 4 2 9 6 3
If they have something consistent like 1 2 3 2 4 6 3 6 9 give them 5 points, check with the other TA’s to make sure you are consistent.
Give them 2 points if they wrote anything (involving numbers).
N := 0;
_WHILE__ (N < ___7___) DO { a while loop }
BEGIN
_N_ := _N_ + _2_ ; or N := 2 + N
_Write_ ( N, ‘ ‘ ); zero points if they put WriteLN
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;
0 0 1 point for each number and 1
point for
3 1 writing it as a grid ( -1 point for each extra number to a
max of –4, if they also had the correct answer)
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);
data1.txt = 2 points
(if they said file1 give them only 1 point)
data3.txt
= 2 points (if they said file3 give
them only 1 point)
1
point if they wrote anything and
none of what they wrote was file2 or data2.txt
PROGRAM CashRegister;
CONST
RATE = _0.06_ ; only give them ONE point for .06 – it doesn’t work
WIDTH = 6; { field width for money amounts }
VAR
price, bill
: _real______; { Blank 2 is to the
left }
number :
___integer_____; { Blank 3 is to the left
}
PROCEDURE Total(var N : integer; var P, B : real);
BEGIN
____B__ := _N__ * ( P +
RATE * P); { Blanks 4 and 5 are
to the left }
END; { Total }
BEGIN { main }
Writeln(‘Enter the price: ’);
Readln( _price_ );
{ Blank 6 is to the left }
Writeln(‘Enter the number of items: ’);
Readln( _number_
); { Blank 7 is to the
left }
{ Call the procedure Total }
Total(
number, __price_
, _bill_); { Blanks 8, 9 are to the left }
Writeln( number, ‘ items at $’, price : WIDTH:2);
Writeln(‘Total Bill $’, __bill__ : WIDTH:2, ‘ with tax.’);
END.