Deck 4: Control Statements, Part 2

Full screen (f)
exit full mode
Question
Which of the following is a parameterized stream manipulator used to format output?

A) setw
B) right
C) left
D) fixed
Use Space or
up arrow
down arrow
to flip the card.
Question
Which of the following is a poor programming practice?

A) Indenting the statements in the body of each control structure.
B) Using floating-point values for counters in counter-controlled repetition.
C) Nesting multiple repetition structures.
D) Placing vertical spacing above and below control structures.
Question
Which of the following data types can be used to represent integers?

A) char
B) long
C) short
D) All of the above.
Question
In a switch structure:

A) A break is required after each case.
B) Multiple actions in a case do not need to be enclosed in braces.
C) A default case is required.
D) A break is required after the default case.
Question
Which of the following for headers is not valid?

A) for int i = 0; i < 10; i++ )
B) int i = 0; for ; i < 10; i++ )
C) for int i = 0; int j = 5; ; i++ )
D) All of the above.
Question
Which of the following statements about the for statement is false?

A) The three expressions in the for statement are optional.
B) The initialization and increment expressions can be comma-separated lists.
C) You must declare the control variable before the for statement.
D) A for statement can always be used to replace a while statement, and vice versa.
Question
An operator that associates from right to left is:

A) !=
B) ,
C) )
D) ?:
Question
If a variable is declared in the initialization expression of a for statement, then:

A) It is automatically reinitialized to zero once the loop is finished.
B) The scope of the variable is restricted to that for loop.
C) It retains its final value after the loop is finished.
D) It can not be used in any structures that are nested in that for structure.
Question
What will the following program segment do?
Int counter = 1;
Do
{
Cout << counter << " ";
} while ++counter <= 10 );

A) Print the numbers 1 through 11.
B) Print the numbers 1 through 10.
C) Print the numbers 1 through 9.
D) Cause a syntax error.
Question
Float and double variables should be used:

A) To perform monetary calculations.
B) As counters.
C) To store true/false values.
D) As approximate representations of decimal numbers.
Question
A switch statement should be used:

A) As a single-selection structure.
B) As a double-selection structure.
C) As a multiple-selection structure.
D) To replace all if…else statements.
Question
The OR ||) operator:

A) Has higher precedence than the AND &&) operator.
B) Stops evaluation upon finding one condition to be true.
C) Associates from right to left.
D) Is a ternary operator.
Question
Which of the following does counter-controlled repetition require?

A) An initial value.
B) A condition that tests for the final value.
C) An increment or decrement by which the control variable is modified each time through the loop.
D) All of the above.
Question
Consider the execution of the following for loop
For int x = 1; x < 5; increment )
Cout << x + 1 << endl;
If the last value printed is 5, which of the following might have been used for increment?

A) x++
B) x += 1
C) ++x
D) Any of the above.
Question
Which of the following is false?

A) The effects of break and continue statements can be achieved by structured programming techniques.
B) break and continue statements can make a program perform faster than with the corresponding structured techniques.
C) Many programmers feel that break and continue violate structured programming.
D) You should always try to write the fastest, smallest code possible before attempting to make it simple and correct.
Question
In C++, the condition 4 > y > 1 ):

A) Evaluates correctly and could be replaced by 4 > y && y > 1 ).
B) Does not evaluate correctly and should be replaced by 4 > y && y > 1 ).
C) Evaluates correctly and could not be replaced by 4 > y && y > 1 ).
D) Does not evaluate correctly and should not be replaced by 4 > y && y > 1 ).
Question
Switch can be used to test:

A) int constants.
B) float constants.
C) string constants.
D) all types of constants.
Question
Which of the following is correct when labeling cases in a switch structure?

A) case1
B) Case1
C) case 1
D) Case 1
Question
Which of the following is false?

A) break and continue statements alter the flow of control.
B) continue statements skip the remaining statements in the current iteration of the body of the loop in which they're embedded.
C) break statements exit from the loop in which they're embedded.
D) continue and break statements may be embedded only within repetition statements.
Question
If a do…while structure is used:

A) An infinite loop cannot take place.
B) Counter-controlled repetition is not possible.
C) The body of the loop will execute at least once.
D) An off-by-one error cannot occur.
Question
Which of the following is not one of the C++ control structures?

A) if
B) switch
C) select
D) do…while
Question
An example of a unary operator is:

A) The < relational operator.
B) The = assignment operator.
C) The % arithmetic operator.
D) The ! logical operator.
Question
Of the following, which is not a logic error?

A) Not placing curly braces around the body of an if that contains two statements.
B) Using == to assign a value to a variable.
C) Failing to initialize counter and total variables before the body of a loop.
D) Using commas instead of the two required semicolons in a for header.
Question
The ____________, __________ and ____________ are the only three forms of control necessary.

A) switch, if, else.
B) sequence, selection, repetition.
C) break, continue, if…else.
D) for, while, do…while.
Question
Consider the following code, assuming that x is an int with an initial value of 12
If x = 6 )
Cout << x;
What is the output?

A) 6
B) 12
C) Nothing.
D) A syntax error is produced.
Question
Which of the following is not one the rules for forming structured programs?

A) Begin with the "simplest activity diagram."
B) Any transition arrow can be reversed.
C) Any action state can be replaced by two action states in sequence.
D) Any action state can be replaced by any control statement.
Question
Variables are also known as:

A) lvalues, but can be used as rvalues.
B) lvalues, and cannot be used as rvalues.
C) rvalues, and cannot be used as lvalues.
D) Constant variables.
Question
The expression if num != 65 ) cannot be replaced by:

A) if num > 65 || num < 65 )
B) if ! num == 65 ) )
C) if num - 65 )
D) if ! num - 65 ) )
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/28
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: Control Statements, Part 2
1
Which of the following is a parameterized stream manipulator used to format output?

A) setw
B) right
C) left
D) fixed
A
2
Which of the following is a poor programming practice?

A) Indenting the statements in the body of each control structure.
B) Using floating-point values for counters in counter-controlled repetition.
C) Nesting multiple repetition structures.
D) Placing vertical spacing above and below control structures.
B
3
Which of the following data types can be used to represent integers?

A) char
B) long
C) short
D) All of the above.
D
4
In a switch structure:

A) A break is required after each case.
B) Multiple actions in a case do not need to be enclosed in braces.
C) A default case is required.
D) A break is required after the default case.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following for headers is not valid?

A) for int i = 0; i < 10; i++ )
B) int i = 0; for ; i < 10; i++ )
C) for int i = 0; int j = 5; ; i++ )
D) All of the above.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following statements about the for statement is false?

A) The three expressions in the for statement are optional.
B) The initialization and increment expressions can be comma-separated lists.
C) You must declare the control variable before the for statement.
D) A for statement can always be used to replace a while statement, and vice versa.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
7
An operator that associates from right to left is:

A) !=
B) ,
C) )
D) ?:
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
8
If a variable is declared in the initialization expression of a for statement, then:

A) It is automatically reinitialized to zero once the loop is finished.
B) The scope of the variable is restricted to that for loop.
C) It retains its final value after the loop is finished.
D) It can not be used in any structures that are nested in that for structure.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
9
What will the following program segment do?
Int counter = 1;
Do
{
Cout << counter << " ";
} while ++counter <= 10 );

A) Print the numbers 1 through 11.
B) Print the numbers 1 through 10.
C) Print the numbers 1 through 9.
D) Cause a syntax error.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
10
Float and double variables should be used:

A) To perform monetary calculations.
B) As counters.
C) To store true/false values.
D) As approximate representations of decimal numbers.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
11
A switch statement should be used:

A) As a single-selection structure.
B) As a double-selection structure.
C) As a multiple-selection structure.
D) To replace all if…else statements.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
12
The OR ||) operator:

A) Has higher precedence than the AND &&) operator.
B) Stops evaluation upon finding one condition to be true.
C) Associates from right to left.
D) Is a ternary operator.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following does counter-controlled repetition require?

A) An initial value.
B) A condition that tests for the final value.
C) An increment or decrement by which the control variable is modified each time through the loop.
D) All of the above.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
14
Consider the execution of the following for loop
For int x = 1; x < 5; increment )
Cout << x + 1 << endl;
If the last value printed is 5, which of the following might have been used for increment?

A) x++
B) x += 1
C) ++x
D) Any of the above.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following is false?

A) The effects of break and continue statements can be achieved by structured programming techniques.
B) break and continue statements can make a program perform faster than with the corresponding structured techniques.
C) Many programmers feel that break and continue violate structured programming.
D) You should always try to write the fastest, smallest code possible before attempting to make it simple and correct.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
16
In C++, the condition 4 > y > 1 ):

A) Evaluates correctly and could be replaced by 4 > y && y > 1 ).
B) Does not evaluate correctly and should be replaced by 4 > y && y > 1 ).
C) Evaluates correctly and could not be replaced by 4 > y && y > 1 ).
D) Does not evaluate correctly and should not be replaced by 4 > y && y > 1 ).
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
17
Switch can be used to test:

A) int constants.
B) float constants.
C) string constants.
D) all types of constants.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following is correct when labeling cases in a switch structure?

A) case1
B) Case1
C) case 1
D) Case 1
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following is false?

A) break and continue statements alter the flow of control.
B) continue statements skip the remaining statements in the current iteration of the body of the loop in which they're embedded.
C) break statements exit from the loop in which they're embedded.
D) continue and break statements may be embedded only within repetition statements.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
20
If a do…while structure is used:

A) An infinite loop cannot take place.
B) Counter-controlled repetition is not possible.
C) The body of the loop will execute at least once.
D) An off-by-one error cannot occur.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following is not one of the C++ control structures?

A) if
B) switch
C) select
D) do…while
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
22
An example of a unary operator is:

A) The < relational operator.
B) The = assignment operator.
C) The % arithmetic operator.
D) The ! logical operator.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
23
Of the following, which is not a logic error?

A) Not placing curly braces around the body of an if that contains two statements.
B) Using == to assign a value to a variable.
C) Failing to initialize counter and total variables before the body of a loop.
D) Using commas instead of the two required semicolons in a for header.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
24
The ____________, __________ and ____________ are the only three forms of control necessary.

A) switch, if, else.
B) sequence, selection, repetition.
C) break, continue, if…else.
D) for, while, do…while.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
25
Consider the following code, assuming that x is an int with an initial value of 12
If x = 6 )
Cout << x;
What is the output?

A) 6
B) 12
C) Nothing.
D) A syntax error is produced.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following is not one the rules for forming structured programs?

A) Begin with the "simplest activity diagram."
B) Any transition arrow can be reversed.
C) Any action state can be replaced by two action states in sequence.
D) Any action state can be replaced by any control statement.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
27
Variables are also known as:

A) lvalues, but can be used as rvalues.
B) lvalues, and cannot be used as rvalues.
C) rvalues, and cannot be used as lvalues.
D) Constant variables.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
28
The expression if num != 65 ) cannot be replaced by:

A) if num > 65 || num < 65 )
B) if ! num == 65 ) )
C) if num - 65 )
D) if ! num - 65 ) )
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 28 flashcards in this deck.