CISC chapter 5

Ace your homework & exams now with Quizwiz!

Look at the following statement: while (x++ < 10) Which operator is used first?

++

int x = 0; while (x < 5) { cout << x << ' '; x++; }

0 1 2 3 4

What is the output of the following code segment? n = 1; for ( ; n <= 5; ) cout << n << ' '; n++;

1 1 1 ... and on, forever

How many times will the following loop display "Hello!"? for (int i = 0; i < 20; i++) cout << "Hello!" << endl;

20

What will the following code display? int number = 6; int x = 0; x = --number; cout << x;

5

What will the following code display? int number = 6; int x = 0; x = number--; cout << x;

6

What will the following code display?

7

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

False

You may not use the break statement in a nested loop

False

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

True

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

True

The while loop has two important parts: an expression that is tested for a true or false value, and:

a statement or block that is repeated as long as the expression is true

The statements in the body of a while loop may never be executed, whereas the statements in the body of a do-while loop will be executed

at least once

This statement causes a loop to terminate early.

break

Assuming dataFile is a file stream object, the statement: dataFile.close();

closes a file

This is a variable that is regularly incremented or decremented each time a loop iterates

counter

This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop

for

Something within a while loop must eventually cause the condition to become false, or a(n) __________ results

infinite loop

The while loop contains an expression that is tested for a true or false value, and a statement or block that is repeated as long as the expression _________________.

is true

If you place a semicolon after the test expression in a while loop, it is assumed to be a(n)

null statement

To write data to a file, you define an object of this data type

ofstream

Assuming outFile is an output file stream object, and number is a variable, which statement writes the contents of number to the file associated with outFile?

outFile << number;

The do-while loop is considered a(n) _________ loop

post-record

When the increment operator precedes its operand, as in ++num1, the operator is in this mode

prefix

You may define a __________ in the initialization expression of a for loop.

variable


Related study sets

Elsevier Urinary, and Reproductive Systems EAQ

View Set

Cognitive Psych Ch. 12 (Problem Solving) Book Questions

View Set

Starting Out with Python, 3e Ch 9

View Set

Antigens and antigen presenting cells

View Set

CompTIA Network + 1.2 (Network Topologies and types)

View Set