Deck 5: Control Statements, Logical Operators
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/31
Play
Full screen (f)
Deck 5: Control Statements, Logical Operators
1
Switch can be used to test:
A) int constants.
B) float constants.
C) string constants.
D) all types of constants.
A) int constants.
B) float constants.
C) string constants.
D) all types of constants.
A
2
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.
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.
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.
A) char
B) long
C) short
D) All of the above.
D
4
Which of the following is false?
A) The three expressions in the for structure are optional.
B) The initialization and increment expressions can be comma-separated lists.
C) You must declare the control variable outside of the for loop.
D) A for loop can always be used to replace a while loop, and vice versa.
A) The three expressions in the for structure are optional.
B) The initialization and increment expressions can be comma-separated lists.
C) You must declare the control variable outside of the for loop.
D) A for loop can always be used to replace a while loop, and vice versa.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following is false?
A) There are representational errors, when precise decimal dollar amounts and interest rates are stored as doubles.
B) There are many currencies worldwide, with different conventions for thousands separators, decimal separators, currency symbols, and more.
C) C++11's long long type supports values in the range -2,147,483,647 to 2,147,483,647 as a minimum.
D) C++11's int64_t type supports the exact range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
A) There are representational errors, when precise decimal dollar amounts and interest rates are stored as doubles.
B) There are many currencies worldwide, with different conventions for thousands separators, decimal separators, currency symbols, and more.
C) C++11's long long type supports values in the range -2,147,483,647 to 2,147,483,647 as a minimum.
D) C++11's int64_t type supports the exact range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
6
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
7
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following is true?
A) You can initialize data members of a class only in the class's constructor.
B) C++11 allows you to provide a default value for a data member when you declare it in the class declaration.
C) You cannot initialize data members of a class.
D) None of the above
A) You can initialize data members of a class only in the class's constructor.
B) C++11 allows you to provide a default value for a data member when you declare it in the class declaration.
C) You cannot initialize data members of a class.
D) None of the above
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following is correct when labeling cases in a switch structure?
A) case1:
B) Case1:
C) case 1:
D) Case 1:
A) case1:
B) Case1:
C) case 1:
D) Case 1:
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
10
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
11
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 iteration.
C) Nesting multiple iteration structures.
D) Placing vertical spacing above and below control structures.
A) Indenting the statements in the body of each control structure.
B) Using floating-point values for counters in counter-controlled iteration.
C) Nesting multiple iteration structures.
D) Placing vertical spacing above and below control structures.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
12
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following does counter-controlled iteration 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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following for headers produces the values from 27 through 3, decrementing by 3?
A) for (unsigned int i{27}; i <= 3; i += 3)
B) for (unsigned int i{27}; i >= 3; i -= 3)
C) for (unsigned int i{27}; i > 3; i -= 3)
D) All of the above.
A) for (unsigned int i{27}; i <= 3; i += 3)
B) for (unsigned int i{27}; i >= 3; i -= 3)
C) for (unsigned int i{27}; i > 3; i -= 3)
D) All of the above.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
15
In a switch statement:
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following is a parameterized stream manipulator used to format output?
A) setw
B) right
C) left
D) fixed
A) setw
B) right
C) left
D) fixed
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following is false?
E) break and continue statements alter the flow of control.
F) continue statements skip the remaining statements in current iteration of the body of the loop in which they are embedded.
G) break statements exit from the loop in which they are embedded. h. continue and break statements may be embedded only within iteration statements.
E) break and continue statements alter the flow of control.
F) continue statements skip the remaining statements in current iteration of the body of the loop in which they are embedded.
G) break statements exit from the loop in which they are embedded. h. continue and break statements may be embedded only within iteration statements.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
18
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
19
If a do…while structure is used:
A) An infinite loop cannot take place.
B) Counter-controlled iteration is not possible.
C) The body of the loop will execute at least once.
D) An off-by-one error cannot occur.
A) An infinite loop cannot take place.
B) Counter-controlled iteration 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 31 flashcards in this deck.
Unlock Deck
k this deck
20
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
21
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
22
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following is not one of the C++ control structures?
A) if
B) switch
C) break
D) do…while
A) if
B) switch
C) break
D) do…while
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
24
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).
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 31 flashcards in this deck.
Unlock Deck
k this deck
25
The ____________, __________ and ____________ are the only three forms of control necessary.
A) switch, if, else.
B) sequence, selection, iteration.
C) break, continue, if…else.
D) for, while, do…while.
A) switch, if, else.
B) sequence, selection, iteration.
C) break, continue, if…else.
D) for, while, do…while.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
26
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))
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 31 flashcards in this deck.
Unlock Deck
k this deck
27
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
28
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck
29
An example of a unary operator is:
A) The < relational operator.
B) The = assignment operator.
C) The % arithmetic operator.
D) The ! logical operator.
A) The < relational operator.
B) The = assignment operator.
C) The % arithmetic operator.
D) The ! logical operator.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
30
An operator that associates from right to left is:
A) !=
B) ,
C) ()
D) ?:
A) !=
B) ,
C) ()
D) ?:
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
31
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.
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 31 flashcards in this deck.
Unlock Deck
k this deck