Deck 5: Looping
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
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/38
Play
Full screen (f)
Deck 5: Looping
1
A for loop is considered a(n)_ loop.
A)infinite
B)pretest
C)sentinel controlled
D)multi test
E)post test
A)infinite
B)pretest
C)sentinel controlled
D)multi test
E)post test
B
2
The ++ operator
A)adds one to the value of its operand.
B)can operate in prefix or postfix mode.
C)is a unary operator.
D)All of the above.
E)Both B and C, but not A.
A)adds one to the value of its operand.
B)can operate in prefix or postfix mode.
C)is a unary operator.
D)All of the above.
E)Both B and C, but not A.
D
3
A for statement contains three expressions: initialization, test, and
A)update.
B)increment.
C)repeat.
D)quit.
E)validate.
A)update.
B)increment.
C)repeat.
D)quit.
E)validate.
A
4
A sentinel is a special value that
A)marks the end of a list of values.
B)must be Boolean.
C)is used for data validation.
D)must be a negative number.
E)is all of the above.
A)marks the end of a list of values.
B)must be Boolean.
C)is used for data validation.
D)must be a negative number.
E)is all of the above.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
5
To use files in a C++ program you must include the header file.
A)fstream
B)iostream
C)file
D)Both A and B are needed.
E)Both B and C are needed.
A)fstream
B)iostream
C)file
D)Both A and B are needed.
E)Both B and C are needed.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
6
To a value means to increase it.
A)add up
B)accumulate
C)increment
D)total
E)decrement
A)add up
B)accumulate
C)increment
D)total
E)decrement
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
7
The statements in the body of a do-while loop are executed
A)only if the test condition is initially true.
B)forever until the user hits the break key.
C)at least once.
D)until the test condition becomes true.
E)until an exit statement is encountered.
A)only if the test condition is initially true.
B)forever until the user hits the break key.
C)at least once.
D)until the test condition becomes true.
E)until an exit statement is encountered.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
8
The while loop is a(n)loop, whereas the do-while loop is a(n)loop.
A)simple, complex
B)finite, infinite
C)post test, pretest
D)pretest, post test
E)infinite, finite
A)simple, complex
B)finite, infinite
C)post test, pretest
D)pretest, post test
E)infinite, finite
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
9
In a for statement, the expression is executed only once.
A)validate
B)initialization
C)test
D)update
E)repeat
A)validate
B)initialization
C)test
D)update
E)repeat
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
10
The ideal type of loop to use for repeating a menu is a(n)_ loop.
A)for
B)do-while
C)nested
D)infinite
E)sentinel controlled
A)for
B)do-while
C)nested
D)infinite
E)sentinel controlled
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
11
In order for a C++ program to read data from a file,
A)the program must open the file.
B)the file must already exist.
C)the program must define a file stream object that can "point to" (i.e., reference)the file.
D)All of the above are required..
A)the program must open the file.
B)the file must already exist.
C)the program must define a file stream object that can "point to" (i.e., reference)the file.
D)All of the above are required..
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
12
A(n)is a variable that controls the number of times a loop iterates.
A)total
B)accumulator
C)sentinel
D)counter
E)loop control variable
A)total
B)accumulator
C)sentinel
D)counter
E)loop control variable
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
13
A variable that keeps a running total of data values is called a(n)
A)sum.
B)loop control variable.
C)total.
D)accumulator.
E)counter.
A)sum.
B)loop control variable.
C)total.
D)accumulator.
E)counter.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
14
The ideal type of loop to use if you want a user to enter exactly 20 values is a(n)loop.
A)sentinel controlled
B)do-while
C)infinite
D)nested
E)for
A)sentinel controlled
B)do-while
C)infinite
D)nested
E)for
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
15
For data validation, it is best to use a(n)
A)switch statement.
B)if statement.
C)for loop.
D)nested loop.
E)while loop.
A)switch statement.
B)if statement.
C)for loop.
D)nested loop.
E)while loop.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
16
The statement causes a loop to terminate early.
A)stop
B)break
C)continue
D)terminate
E)quit
A)stop
B)break
C)continue
D)terminate
E)quit
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
17
The while loop has two important parts: a condition that is tested and a statement or block of statements that is executed
A)as long as the condition is true.
B)until the condition becomes true.
C)at least once.
D)exactly once.
E)Both A and C are true, but B and D are not.
A)as long as the condition is true.
B)until the condition becomes true.
C)at least once.
D)exactly once.
E)Both A and C are true, but B and D are not.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
18
The while loop has two important parts: a condition that is tested and a statement or block of statements that is
A)done once if the condition is true.
B)repeated as long as the condition is true.
C)always skipped.
D)repeated until the condition becomes true.
E)always done at least once, then repeated if the condition is true.
A)done once if the condition is true.
B)repeated as long as the condition is true.
C)always skipped.
D)repeated until the condition becomes true.
E)always done at least once, then repeated if the condition is true.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
19
A(n)is a special value that marks the end of a list of values.
A)counter
B)loop control variable
C)accumulator
D)sentinel
E)total
A)counter
B)loop control variable
C)accumulator
D)sentinel
E)total
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
20
are C++ operators that change their operands by one.
A)++ and --
A)binary and unary
B)+ and -
B)conditional and relational
C)arithmetic and relational
A)++ and --
A)binary and unary
B)+ and -
B)conditional and relational
C)arithmetic and relational
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
21
The do- while loop is a(n)loop, whereas the while loop is a(n)loop.
A)post test, pretest
B)infinite, finite
C)simple, complex
D)pretest, post test
E)finite, infinite
A)post test, pretest
B)infinite, finite
C)simple, complex
D)pretest, post test
E)finite, infinite
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
22
If a while loop has no braces around the body of the loop
A)the loop body contains just one statement.
B)there is no loop body.
C)the loop body ends when the endwhile statement is encountered.
D)the program will not compile.
E)the program will compile, but not run.
A)the loop body contains just one statement.
B)there is no loop body.
C)the loop body ends when the endwhile statement is encountered.
D)the program will not compile.
E)the program will compile, but not run.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
23
An initialization expression may be omitted from the for loop if no initialization is required.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
24
A(n)is a variable that is regularly incremented or decremented each time a loop iterates.
A)accumulator
B)total
C)sentinel
D)loop control variable
E)counter
A)accumulator
B)total
C)sentinel
D)loop control variable
E)counter
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
25
You may define a(n)in the initialization expression of a for loop.
A)variable
B)constant
C)new data type
D)operator
E)new keyword
A)variable
B)constant
C)new data type
D)operator
E)new keyword
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
26
To decrement a number means to increase its value.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
27
The -- operator
A)subtracts one from the value of its operand.
B)must have an lvalue, such as a variable, as its operand.
C)can be used in either prefix or postfix mode.
D)is a unary operator.
E)All of the above are true.
A)subtracts one from the value of its operand.
B)must have an lvalue, such as a variable, as its operand.
C)can be used in either prefix or postfix mode.
D)is a unary operator.
E)All of the above are true.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
28
A while loop is somewhat limited because the counter can only be incremented or decremented by one each time through the loop.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
29
You can nest a for loop inside another for loop, but cannot nest a while loop inside another while loop or a do-while loop inside another do-while loop.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
30
When a loop is nested inside another loop, the inner loop goes through all its iterations for each iteration of the outer loop.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
31
When a loop is nested inside another loop, the outer loop goes through all its iterations for each iteration of the inner loop.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
32
The statements in the body of a do-while loop are executed
A)forever until the user hits the break key.
B)exactly once.
C)until the test condition becomes true.
D)at least once.
E)only if the test condition is initially true.
A)forever until the user hits the break key.
B)exactly once.
C)until the test condition becomes true.
D)at least once.
E)only if the test condition is initially true.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
33
The block of code in the body of a while statement can contain an unlimited number of statements, provided they are enclosed in a set of braces.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
34
To use an output file in a C++ program you must
A)make sure the file already exists.
B)create a file stream object that will "point to" (i.e. reference)the file.
C)open the file.
D)do all of the above.
E)do B and C, but not A.
A)make sure the file already exists.
B)create a file stream object that will "point to" (i.e. reference)the file.
C)open the file.
D)do all of the above.
E)do B and C, but not A.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
35
To use files in a C++ program you must include the header file.
A)file
B)iostream
C)fstream
D)Both A and B.
E)Both B and C.
A)file
B)iostream
C)fstream
D)Both A and B.
E)Both B and C.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
36
A while loop is somewhat limited, because the counter can only count up, not down.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
37
A while loop may have a semicolon after the test expression and before the body of the loop, but it is not required.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
38
If nothing within a while loop ever causes the condition to become false, a(n)may occur.
A)infinite loop
B)null value
C)compiler error
D)unexpected exit
E)system crash
A)infinite loop
B)null value
C)compiler error
D)unexpected exit
E)system crash
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck