COP 3014 Chapter 5

Ace your homework & exams now with Quizwiz!

To allow file access in a program, you must use

#include fstream

these are operators that add and subtract one from their operands

++ and --

These are operators that add and subtract one from their operands

++and--

What will the following code display? 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; while (n <= 5) cout << n << ' '; n++;

1 1 . . . and on forever

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

20

How many times will the following loop display *"Looping!"*? for (int i = 20; i > 0; i--) cout << "Looping!" << endl;

20

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

21

What will the following code display? Int number = 6; Int x = 0; X = --number; Cout << x << endl;

5

What will the following code display? Int number = 6; Int x = 0; X = number--; Cout << x << endl;

6

What will the following code display? int x = 0; for (int count = 0; count < 3; count++) x+= count; cout << x << endl;

6

What will the following code display? Int number = 6; ++number; Cout << x << endl;

7

What will the following code display? Int number = 6; number++; Cout << number << endl;

7

What will the following code display? int number = 6; cout << ++number << endl;

7

In the following statement, which operator is used first? while (x++ < 10)

<

The *do-while* loop is considered

a post-test loop

The two important parts of a *while* loop are the 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 while the statements in the body of a *do-while* loop will be executed

at least once

A statement that causes a loop to terminate early is

break

A file __________ is a small holding section of memory that file-bound information is first written to

buffer

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

closes a file

A statement that may be used to stop a loop's current iteration and begin the next one is

continue

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

counter

The __________ loop is ideal in situations where you want the loop to iterate at least once

do-while

If you want a user to enter exactly 20 values, which loop would be the best to use

for

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

for

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

fstream

To write read data from a file, you define an object of the __________ data type

ifstream

This means to increase a value

increment

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

infinite loop

In a *for* statement, this expression is executed only once

initialization

This is a control structure that causes a statement or group of statements to repeat

loop

A loop that is inside another loop is called a(n)

nested loop

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

null statement

A file must be __________ before data can be written to or read from it

opened

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*?

outFile<<number;

The *while* loop is a __________ loop

pre-test

When the increment operator precedes its operand, as *++num*, the expression is in __________ mode

prefix

This operator increments the value of its operand and then uses the value in context

prefix increment

This operator increments the value of its operand, then uses the value in context.

prefix increment

A special value that marks the end of a list of values is a

sentinel

To write information to a file, use the

stream insertion operator

A *for* statement contains three expressions: initialization, test, and

update

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

variable

The __________ loop is a good choice when you do not want the loop to iterate if the condition is false in the beginning

while


Related study sets

Non-price Factors Affecting Demand

View Set

Values, Ethics, and Legal Issues

View Set

RN Adult Medical Surgical Online Practice 2016/2019

View Set

Environmental Science CH 11 study guide

View Set

Selecciona Verdadero o Falso según la respuesta correcta

View Set