Chapter 5 Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

update.

A for statement contains three expressions: initialization, test, and Answers: update. validate. quit. increment. repeat.

marks the end of a list of values.

A sentinel is a special value that Answers: is used for data validation. must be Boolean. marks the end of a list of values. must be a negative number. All of these

accumulator

A variable that keeps a running total of data values is called a(n) Answers: accumulator. counter. total. loop control variable. sum.

loop control variable

A(n) ________ is a variable that controls the number of times a loop iterates. Answers: accumulator loop control variable total counter sentinel

while loop.

For data validation, it is best to use a(n) Answers: while loop. switch statement. if statement. nested loop. for loop.

the loop body contains just one statement.

If a while loop has no braces around the body of the loop Answers: the program will compile, but not run. the loop body contains just one statement. the program will not compile. the loop body ends when the endwhile statement is encountered. there is no loop body.

infinite loop

If nothing within a while loop ever causes the condition to become false, a(n) ________ may occur. Answers: infinite loop unexpected exit system crash null value compiler error

initialization

In a for statement, the ________ expression is executed only once. Answers: update initialization repeat validate test

All of these are required.

In order for a C++ program to read data from a file, Answers: the file must already exist. the program must define a file stream object that can "point to" (i.e., reference) the file. the program must open the file. All of these are required.

All of these

The ++ operator Answers: is a unary operator. adds one to the value of its operand. can operate in prefix or postfix mode. All of these Both adds one to the value of its operand and can operate in prefix or postfix mode, but not is a unary operator

break

The ________ statement causes a loop to terminate early. Answers: break quit stop terminate continue

posttest, pretest

The do- while loop is a(n) ________ loop, whereas the while loop is a(n) ________ loop. Answers: infinite, finite pretest, posttest finite, infinite simple, complex posttest, pretest

do-while

The ideal type of loop to use for repeating a menu is a(n) ________ loop. Answers: nested infinite sentinel controlled do-while for

for

The ideal type of loop to use if you want a user to enter exactly 20 values is a(n) ________ loop. Answers: do-while sentinel controlled nested infinite for

at least once.

The statements in the body of a do-while loop are executed Answers: at least once. until an exit statement is encountered. only if the test condition is initially true. until the test condition becomes true. forever until the user presses the break key.

repeated as long as the condition is true

The while loop has two important parts: a condition that is tested and a statement or block of statements that is Answers: always skipped. done once if the condition is true. repeated as long as the condition is true. repeated until the condition becomes true. always done at least once, then repeated if the condition is true.

pretest, posttest

The while loop is a(n) ________ loop, whereas the do-while loop is a(n) ________ loop. Answers: simple, complex pretest, posttest posttest, pretest infinite, finite finite, infinite

increment

To ________ a value means to increase it. Answers: increment total add up decrement accumulate

fstream

To use files in a C++ program you must include the ________ header file. Answers: file iostream fstream Both file and iostream Both iostream and fstream

5 6 4

What will the following code print? Answers: 5 6 4 5 5 4 5 4 3 6 5 4 5 6 5

7 7 8

What will the following code print? num = 8; cout << --num << " "; cout << num++ << " "; cout << num; Answers: 7 7 8 7 8 8 8 7 7 8 7 8 None of these


Set pelajaran terkait

12 Chapter Quiz: Informative Speaking

View Set