Ch 5 Multiple Choice

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

A statement that may be used to stop a loop's current iteration and begin the next one is 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

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

D

The condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon.

F

The increment and decrement operators can be used in mathematical expressions; however, they cannot be used in relational expressions.

F

It is possible to define a file stream object and open a file in one statement.

T

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 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. coutobject 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. 12345 b. 1 1 ... and on forever c. 123456 d. 1234 e. 2345

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

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

C

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

A

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

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

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. 012345 b. 01234 c. 0 1 2 3 4 d. This is an infinite loop

B

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

C

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

D

To write information to a file, use the a. coutobject 21 c. d. an infinite number of times b. penobject c. outputobject d. stream insertion operator e. None of these

D

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++) a. b. c. d. cout << "Hello world!" << endl; 20 19 21 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; int x = 0; x = number--; cout << x << endl;

A

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

A

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 must be __________ before data can be written to or read from it. a. opened b. closed c. named d. buffered e. initialized

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

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 a. c. variable d. sentinel e. None of these

D

A while loop is somewhat limited because the counter can only be incremented by one each time through the loop.

F

The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop.

F

You may nest while and do-while loops but you may not nest for loops.

F

You may not use both break and continue statements within the same set of nested loops.

F

You may not use the break statement in a nested loop.

F

A while loop's body can contain multiple statements, as long as they are enclosed in braces.

T

An initialization expression may be omitted from the for loop if no initialization is required.

T

An output file is a file that data is written to.

T

If you want to stop a loop before it goes through all of its iterations, the break statement may be used.

T

In C++ 11 you can pass a string object as an argument to a file stream object's open member function.

T

Multiple relational expressions cannot be placed into the test condition of a for loop.

T

The update expression of a for loop can contain more than one statement, for example: for(i = 5; i <= 10; i++, total+= sales)

T

string objects have a member function named c_str that returns the contents of the object formatted as a null-terminated C-string.

T


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

History review : quiz questions from chapters 4-7

View Set

ServSafe 6th Edition Coursework _Ch 6 Key Terms & Summary

View Set

BOC: Microbiology, Success in CLS Ch. 6 Bacteriology (360 q.)

View Set

Module 1- Week 2 Chapter 23 Written Communications

View Set

Core Curriculum - Ch 17 The Infant at Risk

View Set

SU 5: PLANNING INSTRUCTIONAL ACTIVITY

View Set

Unit 6: Inferences for Categorical Data: Proportions

View Set

Hospitality Marketing Chapter 12

View Set

ISV Technical Enablement & AppExchange Operations

View Set