Computer Science I Quiz 5

25 July 2022
4.7 (114 reviews)
20 test answers

Unlock all answers in this set

Unlock answers (16)
question
A file must be ________ before data can be written to or read from it. A)closed B)opened C)buffered D)initialized E)none of these
answer
B)opened
question
A for statement contains three expressions: initialization, test, and: A)update B)reversal C)null D)validation E)none of these
answer
A)update
question
A loop that is inside another loop is called: A)an infinite loop B)a pre-test loop C)a post-test loop D)a nested loop E)none of these
answer
a nested loop
question
Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile? A)write (outFile, number); B)outFile >> number; C)outFile << number; D)number >> outFile;
answer
C)outFile << number;
question
How many times will the following loop display "Hello"? for (int i = 0; i < 20; i++) cout << "Hello!" <
answer
A)20
question
Look at the following statement. while (x++<10) Which operator is used first? A)++ B)< C)Neither. The expression is invalid
answer
B)<
question
In a for statement, this expression is executed only once. A)test B)null C)initialization D)validation E)none of these
answer
C)initialization
question
If you want a user to enter exactly 20 values, which loop would be the best to use? A)do-while B)for C)while D)infinite E)none of these
answer
B)for
question
How many times will the following loop display "Hello"? for (int i = 0; i <= 20; i++) cout << "Hello!" <
answer
C)21
question
The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop. True False
answer
False
question
The do-while loop is considered a(n) ________ loop. A)pre-test B)post-test C)infinite D)limited E)none of these
answer
B)post-test
question
The while loop has two important parts: an expression that is tested for a true or false value, and: A)a statement or block that is repeated as long as the expression is true B)a statement or block that is repeated only if the expression is false C)one line of code that is repeated once, if the expression is true D)a statement or block that is repeated once, if the expression is true
answer
A)a statement or block that is repeated as long as the expression is true
question
This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop. A)do-while B)while C)for D)infinite E)none of these
answer
C)for
question
This statement causes a loop to terminate early. A)stop B)break C)null D)terminate E)none of these
answer
B)break
question
This statement may be used to stop a loop's current iteration and begin the next one. A)break B)terminate C)re-iterate D)continue E)None of these
answer
D)continue
question
What is the output of the following code segment? n = 1; for (; n <= 5;) cout << n << ' '; n++; A)1 2 3 4 5 B)1 1 1 ... and on forever C)2 3 4 5 6 D)1 2 3 4 E)2 3 4 5
answer
B)1 1 1 ... and on forever
question
What will the following code display? int x = 0; for (int count = 0; count < 3; count ++) x + =count; cout << x <
answer
D)3
question
What will the following loop display? int x = 0; while (x < 5) { cout << x << endl; x++; } A)0 1 2 3 4 5 B)0 1 2 3 4 C)0 1 2 3 4 D)The loop will display numbers starting at 0, for infinity.
answer
B)0 1 2 3 4
question
You may nest while and do-while loops, but you may not nest for loops. True False
answer
False
question
You may not use the break and continue statements within the same set of nested loops. True False
answer
False