Deck 5: Looping

ملء الشاشة (f)
exit full mode
سؤال
The while loop is a(n) ________ loop, whereas the do-while loop is a(n) ________ loop.

A) finite, infinite
B) infinite, finite
C) simple, complex
D) pretest, post test
E) post test, pretest
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
What will the following code print?
Num = 8;
Cout << --num << " ";
Cout << num++ << " ";
Cout << num;

A) 7 7 8
B) 7 8 8
C) 8 7 7
D) 8 7 8
E) None of these
سؤال
An initialization expression may be omitted from the for loop if no initialization is required.
سؤال
The ++ operator

A) is a unary operator.
B) adds one to the value of its operand.
C) can operate in prefix or postfix mode.
D) All of the above.
E) Both B and C, but not A.
سؤال
In a for statement, the ________ expression is executed only once.

A) initialization
B) test
C) repeat
D) validate
E) update
سؤال
A for statement contains three expressions: initialization, test, and

A) repeat.
B) validate.
C) update.
D) quit.
E) increment.
سؤال
A while loop is somewhat limited, because the counter can only count up, not down.
سؤال
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.
سؤال
The statements in the body of a do-while loop are executed

A) exactly once.
B) at least once.
C) only if the test condition is initially True.
D) until the test condition becomes True.
E) forever until the user hits the break key.
سؤال
A variable that keeps a running total of data values is called a(n)

A) total.
B) sum.
C) accumulator.
D) counter.
E) loop control variable.
سؤال
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.
سؤال
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.
سؤال
For data validation, it is best to use a(n)

A) if statement.
B) while loop.
C) for loop.
D) nested loop.
E) switch statement.
سؤال
The while loop has two important parts: a condition that is tested and a statement or block of statements that is

A) repeated as long as the condition is True.
B) repeated until the condition becomes True.
C) done once if the condition is True.
D) always done at least once, then repeated if the condition is True.
E) always skipped.
سؤال
When a loop is nested inside another loop, the outer loop goes through all its iterations for each iteration of the inner loop.
سؤال
________ are C++ operators that change their operands by one.

A) + and -
B) ++ and --
C) binary and unary
D) arithmetic and relational
E) conditional and relational
سؤال
A sentinel is a special value that

A) is used for data validation.
B) must be Boolean.
C) marks the end of a list of values.
D) must be a negative number.
E) is all of the above.
سؤال
You may define a(n) ________ in the initialization expression of a for loop.

A) new data type
B) new keyword
C) constant
D) variable
E) operator
سؤال
A while loop may have a semicolon after the test expression and before the body of the loop, but it is not required.
سؤال
To decrement a number means to increase its value.
سؤال
The ideal type of loop to use if you want a user to enter exactly 20 values is a(n) ________ loop.

A) do-while
B) for
C) sentinel controlled
D) infinite
E) nested
سؤال
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.
سؤال
When a loop is nested inside another loop, the inner loop goes through all its iterations for each iteration of the outer loop.
سؤال
To ________ a value means to increase it.

A) decrement
B) increment
C) add up
D) accumulate
E) total
سؤال
A while loop is somewhat limited because the counter can only be incremented or decremented by one each time through the loop.
سؤال
If nothing within a while loop ever causes the condition to become false, a(n) ________ may occur.

A) null value
B) infinite loop
C) unexpected exit
D) compiler error
E) system crash
سؤال
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.
سؤال
What will the following code print?
Num = 5;
Cout << num++ << " ";
Cout << num-- << " ";
Cout << --num;

A) 5 4 3
B) 5 5 4
C) 5 6 4
D) 5 6 5
E) 6 5 4
سؤال
The ideal type of loop to use for repeating a menu is a(n) ________ loop.

A) do-while
B) for
C) sentinel controlled
D) infinite
E) nested
سؤال
A(n) ________ is a variable that is regularly incremented or decremented each time a loop iterates.

A) counter
B) accumulator
C) sentinel
D) total
E) loop control variable
سؤال
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.
سؤال
The statements in the body of a do-while loop are executed

A) only if the test condition is initially True.
B) at least once.
C) until the test condition becomes True.
D) until an exit statement is encountered.
E) forever until the user presses the break key.
سؤال
The ________ statement causes a loop to terminate early.

A) stop
B) break
C) quit
D) terminate
E) continue
سؤال
A(n) ________ is a variable that controls the number of times a loop iterates.

A) counter
B) accumulator
C) sentinel
D) total
E) loop control variable
سؤال
Before beginning to add value to it, an accumulator should be initialized to 1.
سؤال
A(n) ________ is a special value that marks the end of a list of values.

A) counter
B) accumulator
C) sentinel
D) total
E) loop control variable
سؤال
If a while loop has no braces around the body of the loop

A) there is no loop body.
B) the loop body ends when the endwhile statement is encountered.
C) the loop body contains just one statement.
D) the program will not compile.
E) the program will compile, but not run.
سؤال
The -- operator

A) is a unary operator.
B) subtracts one from the value of its operand.
C) must have an lvalue, such as a variable, as its operand.
D) can be used in either prefix or postfix mode.
E) All of the above are True.
سؤال
The do-while loop is a(n) ________ loop, whereas the while loop is a(n) ________ loop.

A) finite, infinite
B) infinite, finite
C) simple, complex
D) pretest, post test
E) post test, pretest
سؤال
In order for a C++ program to read data from a file,

A) the file must already exist.
B) the program must define a file stream object that can "point to" (i.e., reference) the file.
C) the program must open the file.
D) All of the above are required.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 5: Looping
1
The while loop is a(n) ________ loop, whereas the do-while loop is a(n) ________ loop.

A) finite, infinite
B) infinite, finite
C) simple, complex
D) pretest, post test
E) post test, pretest
D
2
What will the following code print?
Num = 8;
Cout << --num << " ";
Cout << num++ << " ";
Cout << num;

A) 7 7 8
B) 7 8 8
C) 8 7 7
D) 8 7 8
E) None of these
A
3
An initialization expression may be omitted from the for loop if no initialization is required.
True
4
The ++ operator

A) is a unary operator.
B) adds one to the value of its operand.
C) can operate in prefix or postfix mode.
D) All of the above.
E) Both B and C, but not A.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
In a for statement, the ________ expression is executed only once.

A) initialization
B) test
C) repeat
D) validate
E) update
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
A for statement contains three expressions: initialization, test, and

A) repeat.
B) validate.
C) update.
D) quit.
E) increment.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
A while loop is somewhat limited, because the counter can only count up, not down.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
The statements in the body of a do-while loop are executed

A) exactly once.
B) at least once.
C) only if the test condition is initially True.
D) until the test condition becomes True.
E) forever until the user hits the break key.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
A variable that keeps a running total of data values is called a(n)

A) total.
B) sum.
C) accumulator.
D) counter.
E) loop control variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
For data validation, it is best to use a(n)

A) if statement.
B) while loop.
C) for loop.
D) nested loop.
E) switch statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
The while loop has two important parts: a condition that is tested and a statement or block of statements that is

A) repeated as long as the condition is True.
B) repeated until the condition becomes True.
C) done once if the condition is True.
D) always done at least once, then repeated if the condition is True.
E) always skipped.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
When a loop is nested inside another loop, the outer loop goes through all its iterations for each iteration of the inner loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
________ are C++ operators that change their operands by one.

A) + and -
B) ++ and --
C) binary and unary
D) arithmetic and relational
E) conditional and relational
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
A sentinel is a special value that

A) is used for data validation.
B) must be Boolean.
C) marks the end of a list of values.
D) must be a negative number.
E) is all of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
You may define a(n) ________ in the initialization expression of a for loop.

A) new data type
B) new keyword
C) constant
D) variable
E) operator
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
A while loop may have a semicolon after the test expression and before the body of the loop, but it is not required.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
To decrement a number means to increase its value.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
The ideal type of loop to use if you want a user to enter exactly 20 values is a(n) ________ loop.

A) do-while
B) for
C) sentinel controlled
D) infinite
E) nested
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
When a loop is nested inside another loop, the inner loop goes through all its iterations for each iteration of the outer loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
To ________ a value means to increase it.

A) decrement
B) increment
C) add up
D) accumulate
E) total
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
A while loop is somewhat limited because the counter can only be incremented or decremented by one each time through the loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
If nothing within a while loop ever causes the condition to become false, a(n) ________ may occur.

A) null value
B) infinite loop
C) unexpected exit
D) compiler error
E) system crash
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
What will the following code print?
Num = 5;
Cout << num++ << " ";
Cout << num-- << " ";
Cout << --num;

A) 5 4 3
B) 5 5 4
C) 5 6 4
D) 5 6 5
E) 6 5 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
The ideal type of loop to use for repeating a menu is a(n) ________ loop.

A) do-while
B) for
C) sentinel controlled
D) infinite
E) nested
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
A(n) ________ is a variable that is regularly incremented or decremented each time a loop iterates.

A) counter
B) accumulator
C) sentinel
D) total
E) loop control variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
The statements in the body of a do-while loop are executed

A) only if the test condition is initially True.
B) at least once.
C) until the test condition becomes True.
D) until an exit statement is encountered.
E) forever until the user presses the break key.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
The ________ statement causes a loop to terminate early.

A) stop
B) break
C) quit
D) terminate
E) continue
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
A(n) ________ is a variable that controls the number of times a loop iterates.

A) counter
B) accumulator
C) sentinel
D) total
E) loop control variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
Before beginning to add value to it, an accumulator should be initialized to 1.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
A(n) ________ is a special value that marks the end of a list of values.

A) counter
B) accumulator
C) sentinel
D) total
E) loop control variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
If a while loop has no braces around the body of the loop

A) there is no loop body.
B) the loop body ends when the endwhile statement is encountered.
C) the loop body contains just one statement.
D) the program will not compile.
E) the program will compile, but not run.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
The -- operator

A) is a unary operator.
B) subtracts one from the value of its operand.
C) must have an lvalue, such as a variable, as its operand.
D) can be used in either prefix or postfix mode.
E) All of the above are True.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
The do-while loop is a(n) ________ loop, whereas the while loop is a(n) ________ loop.

A) finite, infinite
B) infinite, finite
C) simple, complex
D) pretest, post test
E) post test, pretest
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
In order for a C++ program to read data from a file,

A) the file must already exist.
B) the program must define a file stream object that can "point to" (i.e., reference) the file.
C) the program must open the file.
D) All of the above are required.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.