Chapter Eight



Test Bank for Prelude to Programming Chapter 4

MULTIPLE CHOICE

1. Which of the following is a true statement?

|a. |(15 * 2 30) |

|b. |(15 * 2 30) |

|c. |(15 * 2 > 30) AND (15 – 2 < 30) |

|d. |(15 * 2 < 30) OR (15 – 2 > 30) |

ANS: B

[pic]

2. Given that the variables MyName and YourName are defined as follows, which expression is true?

MyName = “Elizabeth” and YourName = “Mike”

|a. |MyName > YourName |

|b. |MyName = YourName |

|c. |YourName = MyName |

ANS: D

[pic]

3. What will be displayed if code corresponding to the following pseudcode is executed?

Set Number = 4

Repeat

Write 2 * Number

Set Number = Number + 2

Until Number = 8

|a. | 8 |b. | 4 |c. | 8 |d. | 12 |

| |12 | |8 | |12 | |16 |

| |16 | |12 | | | | |

ANS: C

[pic]

4. A counter must be:

|a. |a positive number |

|b. |a real number |

|c. |an integer |

|d. |a variable named Count |

ANS: C

[pic]

5. Given: Count = 23, what is the value of Count after the following statement is executed: Count = Count + 2

|a. |23 |

|b. |25 |

|c. |48 |

|d. |24 |

ANS: B

[pic]

6. Which of the following is not a type of loop?

|a. |While |

|b. |For |

|c. |Repeat |

|d. |all of the above are types of loops |

ANS: D

[pic]

7. What will be displayed after code corresponding to the following pseudocode is run?

Set Count = 10

While Count > 0

Write Count

Set Count = Count – 2

End While

|a. | 10 |b. | 10 |c. | 8 |d. | 8 |

| |8 | |8 | |6 | |6 |

| |6 | |6 | |4 | |4 |

| |4 | |4 | |2 | |2 |

| |2 | |2 | | | |0 |

| | | |0 | | | | |

ANS: A

[pic]

8. What will be displayed after code corresponding to the following pseudocode is run?

Set Count = 2

While Count < 10

Set Count = Count + 2

Write Count

End While

|a. | 2 |b. | 2 |c. | 4 |d. | 4 |

| |4 | |4 | |6 | |6 |

| |6 | |6 | |8 | |8 |

| |8 | |8 | |10 | | |

| |10 | | | | | | |

ANS: C

[pic]

9. If Number = 7, what will be displayed after code corresponding to the following pseudocode is run?

For Count = 5 Step 1 To Number

Write Count, Count * 2

End For

|a. | 5 10 |b. | 5 10 |c. | 5 10 |d. | 5 7 |

| |6 12 | |6 12 | |7 14 | |10 14 |

| |7 14 | | | | | | |

ANS: A

[pic]

10. What will be displayed after code corresponding to the following pseudocode is run?

Write “Loops are fun!”

For Count = 8 Step -2 to 4

Write “Hooray!”

End For

|a. |Loops are fun! |b. |Loops are fun! |

| |Hooray! | |Hooray! |

| |Hooray! | |Hooray! |

| |Hooray! | | |

|c. |Loops are fun! |d. |nothing will display |

ANS: A

[pic]

11. If Apples = 6, what will be displayed after code corresponding to the following pseudocode is run?

While Apples < 0

Write “You can’t eat “, Apples, “at one time!”

End While

Write “Goodbye, apple lover.”

|a. |You can’t eat 6 apples at one time! |

| |Goodbye, apple lover. |

|b. |nothing will display |

|c. |You can’t eat apples at one time! |

|d. |Goodbye, apple lover. |

ANS: D

[pic]

12. If MyNumber = 6.8, what is the value of Int(MyNumber * 4^2)?

|a. |108.8 |

|b. |108 |

|c. |109 |

|d. |this is an illegal operation |

ANS: B

[pic]

13. What is the output of the code corresponding to the following pseudocode?

For I = 2 Step 1 To 3

For J = 1 Step 1 To 3

Write I, “and “ J

End For(J)

End For(I)

|a. | 2 and 1 |b. | 2 and 1 |c. | 1 and 1 |d. | I and J |

| |3 and 1 | |2 and 2 | |2 and 2 | |I and J |

| | | |2 and 3 | |3 and 3 | |I and J |

| | | |3 and 1 | | | | |

| | | |3 and 2 | | | | |

| | | |3 and 3 | | | | |

ANS: B

[pic]

14. What statements are in the body of the following loop?

Set Number = 12

For I = 1 Step 1 To 15

Write “Enter a number: “

Input Number

Write “That’s a good number.”

End For

Write “Bye bye.”

|a. |Set Number = 12 |

| |Write “Bye bye.” |

|b. |Write “Enter a number: “ |

| |Write “That’s a good number.” |

|c. |Write “Enter a number: “ |

| |Write “That’s a good number.” |

| |Write “Bye bye.” |

|d. |Write “Enter a number: “ |

| |Input Number |

| |Write “That’s a good number.” |

ANS: D

[pic]

15. If N = 5, what is displayed when the following pseudocode is coded and run?

Set A = 2

For B = 1 Step 1 To N

Set A = A + 2 * B

End For

Write A

|a. | 22 |b. |16 |c. |32 |d. |18 |

ANS: C

[pic]

TRUE/FALSE

1. True/False: If Number = 7, then the following statement is true:

(Number * Number) = YourName)

4.

ANS: T

4. True/False: If one For Loop is nested within another, then the limit value for the two loops must be different.

ANS: F

5. True/False: Two non-overlapping loops can be nested within a third loop.

ANS: T

6. True/False: If the following statement is the first line of a For loop, on the first pass through the loop, X will have the value of 2.

For X = 1 Step 2 to 10

ANS: F

7. True/False: If the following statement is the first line of a For loop, N is the limit value.

For X = 1 Step 3 to N

ANS: T

8. True/False: The body of a post-test loop is always executed at least once.

ANS: T

9. True/False: The body of a pre-test loop is always executed at least once.

ANS: F

10. True/False: In a pre-test loop the test condition is at the bottom, while it is at the top in a post-test loop.

ANS: F

11. True/False: In the following statement, X is the initial value:

For X = N Step 2 to Y

ANS: F

12. True/False: A step value in a loop can be either a positive or a negative number.

ANS: T

13. True/False: Is the following statement true or false? Int(6.89) = 6.

ANS: T

14. True/False: Is the following statement true or false? (50 12).

ANS: F

15. True/False: There are six relational operators.

ANS: T

[pic]

SHORT ANSWER

1. If the increment of a For loop is negative, then the body of the loop will not be executed if the initial value is __________ than the limit value.

ANS: less

2. To __________ data means to ensure that the data are in the proper range.

ANS: validate

3. If Number1 = 19.86 and Number2 = 2.04, then:

a. Int(Number1) + Int(Number2) = __________.

ANS: 21

4. If Number1 = 19.86 and Number2 = 2.04 then:

a. Int(Number1 + Number2) = __________. .

ANS: 21

5. If a loop contains a test condition that can never be met, it is called a(n) __________ loop.

ANS: infinite

6. For readability, most programs __________ the body of a loop.

ANS: indent

7. A loop that is executed a fixed number of times, where that number is known before entering the loop for the first time, is known as a(n) __________ __________ loop.

ANS: counter controlled

8. A variable that keeps track of the number of passes through a loop is known as a(n) __________.

ANS: counter

9. The number of passes through a loop is known as the number of loop __________.

ANS: iterations

10. When a loop counter is set to its first value, it is said to be __________.

ANS: initialized

11. When the step value in a loop is positive, the counter is said to be __________.

ANS: incremented

12. One way to force a loop to end is to have the user enter a special item, called a(n) ___________ __________ which acts as a signal that input is complete.

ANS: sentinel value

13. A sentinel value is also known as a(n) __________ marker.

ANS: end-of-data

14. The type of loop that uses two input values (one before the loop is entered and one within the loop) to validate data is a(n) __________-test loop.

ANS: pre

15. One way to break out of a loop early, when, for example, a user has entered an incorrect value or entered a specified response, is to use a(n) __________ structure within the loop.

ANS: If-Then-Else

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download