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).

 

Part I  - True or False, Circle your answer  ( 20 points, 2 points per question)

 

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 _________
(circle what would correctly fill in the blank)

 

 

 

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.

 

 

 

 

 

 

 

 

 

 

 

 

Part II  - Multiple Choice, (12 points, 4 points per question)

    Select the best answer by circling A, B, C, D, or E in the boxes.

 

  1. When designing an algorithm, the method of breaking down the main task into subtasks is called:

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’);

 

  1. What is the output if number is initialized to 2 ?

a.       first

b.      second

c.       third

d.      fourth

    1. odd

 

Answer 12:

A

B

C

D

E

 

 

  1. What is the output if number is initialized to 69 ?

a.       first

b.      second

c.       third

d.      fourth

e.       odd

 

Answer 13:

A

B

C

D

E

 

 

Part III  - Short Answer  ( 18 points, point values vary), Circle your answers.

 

  1.  (6 points) What is the output (if any) of the following code segment
    (assume embedded in a working program and N is type integer)

 

            FOR N:= 1 DOWNTO 3 DO

            BEGIN

                        Write(N, ‘ ‘);       { there is a space between those single quotes }

           END;

 

 

 

 

 

  1. (12 points) What is the output (if any) of the following code segment
    (assume N and M are type integer and the code is in a working program)

 

            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;

 

 

 

 

 

Part IV  - Programming  ( 50 points, point values vary)

     Be as ‘brief’ as you think possible. Use GOOD coding style!
     (comments are optional, for this)

 

  1. (6 points) Fill in the blanks below so that the below WHILE loop would output:
    2 4 6 8    (all on the same line)

 

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.

 

 

  1. (40 points, 4 per blank) Fill in the blanks below so that the following output will be produced:

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 }

 

 

 

 

 

 

 

 

  1.  (40 points, 4 points per blank) Complete the following program by filling in the blanks so that the below program will follow the below guidelines:

 

 

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.