CIS 114 Quiz (Chapter 7)

profileProTutor11
question-2060.doc

Quiz 7 Fall 2013 1111.doc

Name:____________________________

CIS 114

Quiz (Chapter 7)

(10 Points)

The following algorithm prints the sum of the 5 consecutive integers starting at 1:

Reference Line Program Statements

Line 1 ……………….. LET sum = 0

Line 2 ……………….. LET num = 1

Line 3 ……………….. DO WHILE num <= 5

Line 4 ……………….. LET sum = sum + num

Line 5 ……………….. LET num = num + 1

Line 6 ……………….. LOOP

Line 7 ……………….. OUTPUT sum

Write the Line number from the above program that best applies to each of the statements below. A Line could be used more than once but only one Line can be used per question. (.25 points) each)

1) _____ Accumulate the sum of consecutive integers?

2) _____ Assigns the initial value to variable sum?

3) _____ Determines the starting integer to be summed?

4) _____ Increments the value of variable num to the next consecutive integer?

5) _____ Tests the condition that terminates the loop?

6) _____ Causes the condition to become false when the loop is processed one more

time?

7) _____ Causes the condition to be true the first time through the loop?

8) _____ Marks the top of the loop?

9) _____ Marks the bottom of the loop?

10) _____ Displays the result of the variable sum?

Part 2: Simple Programming—Quick Check/Desk Check

The order of the statements in a program can change the output of a program. Determine the value of the variable sum to be OUTPUT for each set of statements below by using the quick check approach. (2 points each)

11.

12.

Part 3: Pseudo Code

13. Write an IF statement that assigns the text “False” to the variable answer when variable x=0; otherwise assign answer to “True”. Write an equivalent statement that has the same outcome but uses the opposite condition x <> 0. (2 points)

14. Fill in the blanks in the program below to produce the following output:

(1.5 points)

-8, -4, 0, 4, 8, 12, 16

LET n = ______

DO WHILE n <= _____________

OUTPUT _____________

LET ____ = ______ + ______

LOOP

The Value of sum is

LET num = 1

LET sum = 0

DO WHILE num <= 5

LET sum = sum + num

LET num = num + 1

LOOP

OUTPUT sum

The Value of sum is

LET num = 1

LET sum = 0

DO WHILE num <= 5

LET num = num + 1

LET sum = sum + num

LOOP

OUTPUT sum

Equivalent IF statement

Original IF statement