Chapter 6 Quizzes

8 September 2022
4.7 (114 reviews)
36 test answers

Unlock all answers in this set

Unlock answers (32)
question
for statements cannot be represented as while statements. True. False.
answer
False
question
Modifying the control variable of a for statement in the body can cause errors. True. False.
answer
True
question
Which of the following statements is false? When a decimal variable is initialized to an int value, the int value must be cast to decimal. C# treats whole-number literals like 7 and 1000 as type int. Unlike double values, int values can be assigned to decimal variables. C# treats numeric literals like 0.05 as type double.
answer
When a decimal variable is initialized to an int value, the int value must be cast to decimal.
question
Which of the following statements about the break statement is false? The break statement is used to exit a repetition statement early and continue execution after the loop. A break statement can only break out of an immediately enclosing while, for, do while or switch statement. The break statement, when executed in a while, for or do while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop. Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch.
answer
The break statement, when executed in a while, for or do while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
question
The initialization expression, condition and increment expression in a for statement's header must be separated with commas. True. False.
answer
False
question
The C# operator ^ can be used for exponentiation. True. False.
answer
False. C# does not have an exponentiation operator, the Math.Pow method can be used for this purpose.
question
A default case must be provided for every switch statement. True. False.
answer
False
question
Some compilers will automatically remove from loops body statements that do not need to be executed multiple times through a process known as . classification optimization interpretation None of the above.
answer
optimization
question
It's possible to specify that a constant is of type decimal by appending the letter m to the constant. True. False.
answer
True
question
Which of the following operators ensures that at least one out of multiple conditions is true? || && == ^
answer
||
question
Which of the following is not a control statement in C#? dowhile loop switch for
answer
loop
question
The stacking and nesting rules must be applied in a specific order. True. False
answer
False. These rules may be applied as often as the programmer likes and in any order.
question
1 and 2
answer
Which of the following forloop control headers results in equivalent numbers of iterations: 1: for (int q = 1; q <= 100; q++) 2: for (int q = 100; q >= 1; q--) 3: for (int q = 99; q > 0; q = 9) 4: for (int q = 990; q > 0; q = 90) 1 and 2 3 and 4 1 and 2 have equivalent iterations and 3 and 4 have equivalent iterations None of the loops have equivalent iterations
question
Which of the following is equivalent to this code segment? Segment: int total = 0; for (int i = 0; i <= 20; i += 2) { total += i; } int total = 0; for (int i = 20; i < 0; i += 1) { total += i; } int total = 0; for (int i = 0; i <= 20; total += i, i += 2); int total = 0; for (int i = 0, i <= 20, total += i; i += 2); int total = 0; for (int i = 2; i < 20; total += i, i += 2);
answer
int total = 0; for (int i = 0; i <= 20; total += i, i += 2);
question
The _________ rule says that any rectangle (action) in an activity diagram can be replaced by two rectangles with round edges. nesting selection stacking None of the above.
answer
stacking
question
Braces are normally included with dowhile statements even when unnecessary to avoid confusion with the while statement. True. False.
answer
true
question
A control variable that's declared in a for statement header is not accessible outside of the body of the for statement. True. False.
answer
true
question
Infinite loops are caused when the loop continuation condition in a while, for or dowhile statement never becomes true. True. False
answer
false
question
It's possible to specify that a constant is of type decimal by appending the letter m to the constant. True. False.
answer
true
question
A common logic error known as a(n) _________ occurs when the programmer incorrectly specifies a conditional operator, such as < instead of <=. fatal error off-by-one error syntax error None of the above.
answer
off-by-one error
question
A default case must be provided for every switch statement. True. False.
answer
false
question
Which case of the following would warrant using the boolean logical inclusive OR (|) rather than the conditional OR (||)? Testing if two conditions are both true. Testing if at least one of two conditions is true. Testing if at least one of two conditions is true when the right operand has a required side effect. Testing if at least one of two conditions is true when the left operand has a required side effect.
answer
Testing if at least one of two conditions is true when the right operand has a required side effect.
question
The continue statement is used to undo the effects of the break statement. True. False.
answer
false
question
The initialization and increment expressions in a for statement can be commaseparated lists that enable you to use ________. multiple initialization expressions multiple increment expressions multiple initialization expressions and/or multiple increment expressions neither multiple initialization expressions nor multiple increment expressions
answer
multiple initialization expressions and/or multiple increment expressions
question
The stacking and nesting rules must be applied in a specific order. True. False.
answer
false
question
A case with no statements is called an empty case, and requires only the break statement. True. False.
answer
false
question
What occurs when an empty case matches the controlling expression? fall through syntax error infinite loop None of the above.
answer
fall through
question
A case can be labeled as _________ to execute in the event that none of the provided cases are equivalent to the controlling expression. general default case * None of the above.
answer
default
question
Compressing statements before and in a for statement into the for header can reduce the readability of a program True. False.
answer
true
question
The header for (int i = 0; i <= 10; ++i) will cause i to be incremented: before the body begins execution after the body begins to execute, but before it finishes after the entire body executes None of the above.
answer
after the entire body executes
question
Countercontrolled repetition requires only a control variable, an initial value for the control variable and an increment or decrement. True. False
answer
false
question
The dowhile repetition statement tests the condition _________ the body of the loop executes. before while after none of the above
answer
after
question
Unary operators (such as ++) cannot be used in conditions. True. False
answer
False
question
What is the Windows key sequence for typing the endoffile indicator in Command Prompt window? z z z z
answer
z
question
Controlstatement stacking is the process of: placing control statements within each other placing control statements one after another reducing the number of statements required by combining statements none of the above
answer
placing control statements one after another
question
Assuming a is a bool with a value of false, which of the following evaluates to true? !(!a) a !a None of the above.
answer
!a