ch 6

¡Supera tus tareas y exámenes ahora con Quizwiz!

2. Which of the following for-loop control headers results in equivalent numbers of iterations: a) for ( int q = 1; q <= 100; q++ ) b) for ( int q = 100; q >= 0; q-- ) c) for ( int q = 99; q > 0; q -= 9 ) d) for ( int q = 990; q > 0; q -= 90 ) a) a) and b) b) c) and d) c) a) and b) have equivalent iterations and c and d have equivalent iterations d) None of the loops have equivalent iterations Answer: b 3. Which of the following will count down from 10 to 1 correctly? a) for ( int j = 10; j <= 1; j++ ) b) for ( int j = 1; j <= 10; j++ ) c) for ( int j = 10; j > 1; j-- ) d) for ( int j = 10; j >= 1; j-- )

Answer: d

4. Which of the following statements about the continue statement is true? a) The continue statement is used to exit a repetition statement early and continue execution after the loop. b) The continue statement is used to continue after a switch statement. c) The continue statement does not alter the flow of control. d) A continue statement proceeds with the next iteration of the immediately enclosing while, for, do...while statement.

Answer: d

2. The rule says that any rectangle (action) in an activity diagram can be replaced by two rectangles with round edges. a) nesting b) selection c) stacking d) None of the above.

Answer: c

3. Which of the following is syntactically incorrect? a) for (int i = 1; i < 10; ) b) for ( ; i == 3; ) c) for (i == 3) d) None of the above.

Answer: c

3. Which of the following statements about the break statement is false? a) The break statement is used to exit a repetition statement early and continue execution after the loop. b) A break statement can only break out of an immediately enclosing while, for, do...while or switch statement. c) 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. d) Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch.

Answer: c

4. The header for (int i = 0; i <= 10; i++) will cause i to be incremented: a) before the body begins execution b) after the body begins to execute, but before it finishes c) after the entire body executes d) None of the above.

Answer: c

5. Consider the following two C# code segments: Segment 1 Segment 2 int i = 0; for (int i=0; i <= 20; i++) while ( i < 20 ) { { Console.WriteLine ( i ); i++; } Console.WriteLine ( i ); } Which of the following statements is true? a) The output from these segments is not the same. b) The scope of the control variable i is different for the two segments. c) Both (a) and (b) are true. d) Neither (a) nor (b) is true. Answer: c 1. Which of the following is an infinite loop? a) for (int i = 20; i >= 10; i--) b) for (int i = 1; i <= 10; i++) c) for (int i = 10; i <= 20; i--) d) for (int i = 20; i >= 50; i++)

Answer: c

5. Which case of the following would warrant using the boolean logical inclusive OR (|) rather than the conditional OR (||)? a) Testing if two conditions are both true. b) Testing if at least one of two conditions is true. c) Testing if at least one of two conditions is true when the right operand has a required side effect. d) Testing if at least one of two conditions is true when the left operand has a required side effect.

Answer: c

1. The first line of the for statement is sometimes called the: a) for statement header b) increment header c) repetition header d) None of the above.

Answer: a

1. The statement, when executed in a while loop, skips the remaining statements in the body of the statement and begins the next iteration of the loop. a) continue b) break c) next d) None of the above.

Answer: a

1. Which of the following operators ensures that at least one out of multiple conditions is true? a) || b) && c) == d) ^

Answer: a

2. What occurs when an empty case matches the controlling expression? a) fall through b) syntax error c) infinite loop d) None of the above.

Answer: a

4. Suppose variable gender is MALE and age equals 60, how is the expression ( gender == FEMALE ) && ( age >= 65 ) evaluated? a) The condition ( gender == FEMALE ) is evaluated first and the evaluation stops immediately. b) The condition ( age >= 65 ) is evaluated first and the evaluation stops immediately. c) Both conditions are evaluated, from left to right. d) Both conditions are evaluated, from right to left.

Answer: a

1. A case can be labeled as to execute in the event that none of the pro¬vided cases are equivalent to the controlling expression. a) general b) default c) case * d) None of the above.

Answer: b

1. Control-statement stacking is the process of: a) placing control statements within each other b) placing control statements one after another c) reducing the number of statements required by combining statements d) None of the above.

Answer: b

1. Counting loops should be controlled with values. a) double b) int c) char d) None of the above.

Answer: b

1. Which of the following is not a control statement in C#? a) do...while b) loop c) switch d) for

Answer: b

2. A common logic error known as a(n) occurs when the programmer incor¬rectly specifies a conditional operator, such as < instead of <=. a) fatal error b) off-by-one error c) syntax error d) None of the above.

Answer: b

2. The loop body of a do...while statement always executes __________. a) zero times b) at least once c) more than once d) undeterminable

Answer: b

2. The statement, when executed in a for loop, will terminate the loop. a) continue b) break c) next d) None of the above.

Answer: b

3. Consider the code segment below. if ( gender == 1 ) { if ( age >= 65 ) ++seniorFemales; } // end if This segment is equivalent to which of the following? a) if ( gender == 1 || age >= 65 ) ++seniorFemales; b) if ( gender == 1 && age >= 65 ) ++seniorFemales; c) if ( gender == 1 AND age >= 65 ) ++seniorFemales; d) if ( gender == 1 OR age >= 65 ) ++seniorFemales;

Answer: b

3. What is the Windows key sequence for typing the end-of-file indicator in Command Prompt window? a) <Alt> z b) <Ctrl> z c) <Windows>z d) <Shift>z

Answer: b

3. Which statement below is false? a. Structured programming produces programs that are easier to test. b. Structured programming requires four forms of control. c. Structured programming produces programs that are easier to modify d. Structured programming promotes simplicity.

Answer: b

4. Which of the following is equivalent to the following code segment? Segment: int total = 0; for ( int i = 0; i <= 20; i += 2 ) total += i; a) int total = 0; for ( int i = 20; i < 0; i += 1 ) total += i; b) int total = 0; for ( int i = 0; i <= 20; total += i, i += 2 ) c) int total = 0; for ( int i = 0, i <= 20, total += i; i += 2 ) d) int total = 0; for ( int i = 2; i < 20; total += i, i += 2 )

Answer: b

5. Some compilers will automatically remove from loops body statements that do not need to be executed multiple times through a process known as . a) classification b) optimization c) interpretation d) None of the above.

Answer: b

6. Which is equivalent to if ( ! ( grade == sentinelValue ) )? a) if ( grade !== sentinelValue ) b)if ( grade != sentinelValue ) c) if ( grade == sentinelValue ) d) if ( grade !== sentinelValue )

Answer: b

1. The do...while repetition statement tests the condition the body of the loop executes. a) before b) while c) after d) None of the above.

Answer: c

2. Assuming a is a bool with a value of false, which of the following eval¬uates to true? a) !(!a) b) a c) !a d) None of the above.

Answer: c


Conjuntos de estudio relacionados

Chapter 3 Quiz: Medical, Legal, and Ethical Issues

View Set

Quiz 2 Music 101 Loyola Chp: 4,5

View Set

Ch. 20 Caring for Clients with Upper Respiratory Disorders

View Set

U.S. History Fall Final Exam Review

View Set

ECON136B chapter 15 mc questions

View Set