Ch 5 Loops and Files

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

A file must be __________ before data can be written to or read from it. a. opened b. closed c. named d. buffered e. initialized

A

A for statement contains three expressions: initialization, test, and a. update b. reversal c. null d. validation e. None of these

A

A statement that causes a loop to terminate early is a. break b. terminate c. re-iterate d. continue e. None of these

A

How many times will the following loop display "Hello world!"? for (int i = 0; i < 20; i++) cout << "Hello world!" << endl; a. 20 b. 19 c. 21 d. an infinite number of times

A

How many times will the following loop display "Looping!"? for (int i = 20; i > 0; i--) cout << "Looping!" << endl; a. 20 b. 19 c. 21 d. an infinite number of times

A

The __________ loop is a good choice when you do not want the loop to iterate if the condition is false in the beginning. a. while b. infinite c. switch d. do-while e. post-test

A

The statements in the body of a while loop may never be executed while the statements in the body of a do-while loop will be executed a. at least once b. at least twice c. never d. as many times as the user wishes e. None of these

A

The two important parts of a while loop are the 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

A

This operator increments the value of its operand and then uses the value in context. a. prefix increment b. postfix increment c. prefix decrement d. postfix decrement e. None of these

A

What will the following code display? int number = 6; cout << number++ << endl; a. 6 b. 5 c. 7 d. 0

A

What will the following code display? int number = 6; int x = 0; x = number--; cout << x << endl; a. 6 b. 5 c. 7 d. 0

A

A variable that is regularly incremented or decremented each time a loop iterates is a a. constant b. counter c. control d. null terminator e. None of these

B

If you want a user to enter exactly 20 values, which loop would be the best to use? a. while b. for c. switch d. do-while e. None of these

B

In the following statement, which operator is used first? while (x++ < 10) a. ++ b. < c. neither; the expression is invalid d. cannot tell without the rest of the code

B

Something within a while loop must eventually cause the condition to become false or a(n) __________ results. a. null value b. infinite loop c. unexpected exit d. compiler error e. None of these

B

The __________ loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop. a. while b. for c. switch d. do-while e. pre-test

B

The do-while loop is considered a. a pre-test loop b. a post-test loop c. an infinite loop d. a counter-controlled loop e. None of these

B

The while loop is a __________ loop. a. post-test b. pre-test c. infinite d. limited e. None of these

B

These are operators that add and subtract one from their operands. a. plus and minus b. ++ and -- c. binary and unary d. conditional and relational e. binary and ternary

B

This is a control structure that causes a statement or group of statements to repeat. a. decision statement b. loop c. cout object d. selection structure e. None of these

B

This means to increase a value: a. decrement b. increment c. modulus d. parse e. None of these

B

To write read data from a file, you define an object of the __________ data type. a. inputFile b. ifstream c. fstream d. ofstream

B

What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++; a. 1 2 3 4 5 b. 1 1 ... and on forever c. 1 2 3 4 5 6 d. 1 2 3 4 e. 2 3 4 5

B

What will the following code display? int number = 6; int x = 0; x = --number; cout << x << endl; a. 6 b. 5 c. 7 d. 0

B

What will the following code display? int x = 0; while (x < 5) { cout << x << " "; x++; } a. 0 1 2 3 4 5 b. 0 1 2 3 4 c. 0 1 2 3 4 d. This is an infinite loop

B

When the increment operator precedes its operand, as ++num, the expression is in __________ mode. a. postfix b. prefix c. preliminary d. binary e. None of these

B

A file __________ is a small holding section of memory that file-bound information is first written to. a. name b. number c. buffer d. segment e. None of these

C

Assuming dataFile is a file stream object, the following statement: dataFile.close(); a. is illegal in C++ b. needs a filename argument to execute correctly c. closes a file d. is legal but risks losing valuable data e. None of these

C

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;

C

How many times will the following loop display "Looping again!"? for (int i = 0; i <= 20; i++) cout << "Looping again!" << endl; a. 20 b. 19 c. 21 d. an infinite number of times

C

If you place a semicolon after the test expression in a while loop, it is assumed to be a(n) a. pre-test loop b. post-test loop c. null statement d. infinite loop e. None of these

C

In a for statement, this expression is executed only once: a. the test b. null c. initialization d. validation e. None of these

C

To allow file access in a program, you must use __________ in the header file. a. #include file b. #include fileaccess c. #include fstream d. #include cfile

C

What will the following code display? int number = 6; ++number; cout << number << endl; a. 6 b. 5 c. 7 d. 0

C

What will the following code display? int number = 6; cout << ++number << endl; a. 6 b. 5 c. 7 d. 0

C

What will the following code display? int number = 6; number++; cout << number << endl; a. 6 b. 5 c. 7 d. 0

C

You may define a __________ in the initialization expression of a for loop. a. constant b. function c. variable d. new data type e. None of these

C

A loop that is inside another loop is called a(n) a. infinite loop b. pre-test loop c. post-test loop d. nested loop e. None of these

D

A special value that marks the end of a list of values is a a. constant b. counter c. variable d. sentinel e. None of these

D

A statement that may be used to stop a loop's current iteration and begin the next one is a. break b. terminate c. re-iterate d. continue e. None of these

D

The __________ loop is ideal in situations where you want the loop to iterate at least once. a. while b. for c. switch d. do-while e. pre-test

D

To write data to a file, you define an object of the __________ data type. a. outputFile b. ifstream c. fstream d. ofstream

D

To write information to a file, use the a. cout object b. pen object c. output object d. stream insertion operator e. None of these

D

What will the following code display? int x = 0; for (int count = 0; count < 3; count++) x += count; cout << x << endl; a. 0 1 2 b. 0 c. 6 d. 3

D


संबंधित स्टडी सेट्स

PrepU Maternity and Peds Chapter 10

View Set

Sociology: A Global Perspective test 2

View Set

sociology test chp. 10, sociology test chp. 11, sociology test chp. 12, sociology test chp. 13, sociology test chp. 14

View Set

The Princess Bride/Othello Characters

View Set