5.2 Q1: Which of the following does counter-controlled repetition require?
Answer: Counter-controlled repetition requires all of the above.
5.2 Q2: The statement while ( --counter >= 1 ) counter % 2 ? cout << "A" : cout << "B"; cannot be rewritten as:
Answer: while ( counter >= 1 ) if ( counter % 2 ) cout << "A"; else cout << "B";. --counter;
5.2 Q3: Which of the following is a bad programming practice?
Answer: Using floating-point values for counters in counter-controlled repetition.
5.3 Q1: If a variable is declared in the initialization expression of a for structure, then:
Answer: The scope of the variable is restricted to that particular for loop.
5.3 Q2: Which of the following is not true?
Answer: You must declare the control variable outside of the for loop.
5.3 Q3: 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?
Answer: Any of the above.
5.4 Q1: Which of the following for headers is not valid?
Answer: for ( int i = 0; int j = 5; ; i++ ).
5.4 Q2: float and double variables should be used:
Answer: As imprecise representations of decimal numbers.
5.4 Q3: Which of the following is a parameterized stream manipulator used to format output?
Answer: setw.
5.5 Q1: If a do...while structure is used:
Answer: The body of the loop will execute at least once.
5.5 Q2: What will the following program segment do? int counter = 1; do { cout << counter << " "; } while ( ++counter <= 10 );
Answer: Print the numbers 1 through 10.
5.6 Q1: A switch statement should be used:
Answer: As a multiple-selection structure.
5.6 Q2: In a switch structure:
Answer: Multiple actions do not need to be enclosed in braces.
5.6 Q3: Which of the following is correct when labeling cases in a switch structure?
Answer: case 1.
5.6 Q4: switch can be used to test:
Answer: int constants. 5.6 Q5: Which of the following data types can be used to represent integers? Answer: All of the above.
5.7 Q1: Which of the following is false?
Answer: continue and break statements may be embedded within all C++ structures.
5.7 Q2: Which of the following is false?
Answer: You should always try to write the fastest, smallest code possible before attempting to make it simple and correct.
5.8 Q1: In C++, the condition ( 4 > y > 1 ):
Answer: Does not evaluate correctly and should be replaced by ( 4 > y && y > 1 ).
5.8 Q2: The OR (||) operator:
Answer: Stops evaluation upon finding one condition to be true.
5.8 Q3: An operator that associates from right to left is:
Answer: ?:.
5.8 Q4: The expression if ( num != 65 ) cannot be replaced by:
Answer: d. if ( !( num - 65 ) ).
5.8 Q5: An example of a unary operator is:
Answer: The ! logical operator.
5.9 Q1: Variables are also known as:
Answer: lvalues, but can be used as rvalues.
5.9 Q2: 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?
Answer: 6.
5.9 Q3: Of the following, which is not a logic error?
Answer: Using commas instead of the two required semicolons in a for header.
5.10 Q1: The ____________, __________ and ____________ are the only three forms of control necessary.
Answer: sequence, selection, repetition.
5.10 Q2: Which of the following is not one of the C++ control structures?
Answer: main.
5.10 Q3: Which of the following is not one the rules for forming structured programs?
Answer: Any transition arrow can be reversed.
5.11 Q1: Which of the following is not a part of a UML state diagram?
Answer: Fractions beside each state indicating the likelihood of entering that state.
5.11 Q2: An activity diagram for modeling the actions involved in executing a balance inquiry transaction using the BalanceInquiry object should not include:
Answer: Receiving the user's main menu input indicating a desire to inquire the amount of his or her balance.