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 |
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, ‘ ‘ );
END;
Do only ONE of the following – either problem 17
or 18 NOT BOTH. If you do both we will grade both and take the lower score.
Clearly indicate here
_________________________________________
which problem you wish to have graded, 17 or 18.
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 = ______ ;
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.’);
END.