Chapter Five Quiz Questions elee

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the output of the following code segment? n=1; For ( ;n<=5; ) C out << n << ' '; n++;

1 1 1.. And on forever

What is the output of the following code segment? n=1; While (n <= 5) C out << n << ' '; n++;

1 1 1.. And on forever

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

6

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

7

What will the following code display? Int number=6; Number++; C out << number << endl;

7

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

7

Following statement While (x++ < 10) Which operator is used first?

<

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.

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

Closes a file

You may not use the Break and Continue statements within the same set of nested loops.

False

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

For

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

This means to increase a value by one.

Increment

Something within a While loop must eventually cause the condition to become false, or a(n) -blank- results

Infinite loop

In a For statement, this expression is executed only once.

Initialization

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

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

Loop

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.

Of stream

A file must be -blank- before data can be written to or read from it.

Opened

The Do-While loop is a -blank- loop that is ideal in the situations where you always want the loop to iterate at least once.

Post-test

The Do-While loop is considered a(n) -blank- loop.

Post-test

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

Prefix

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

Prefix increment

An Initialization expression may be omitted from the For loop if no Initialization is required.

True

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

True

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

True

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

True

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

True

The update expression of a For loop can contain more than one statement, e.g. Counter++, total+=sales

True

A For statement contains three expressions, Initialization, test, and:

Update

You may define a -blank- in the Initialization expression of a For loop.

Variable

This is a pre-test loop that is ideal in situations where you do not want the loop to iterate if the condition is false from the beginning.

While

These are operators that add and subtract one from their operands.

++ and --

What will the following loop display? Int X=0; While (X<5) { C out << X << endl; X++; }

0 1 2 3 4 5

How many times will the following loop display "Hello"? For (int i=1; i< 20; i++) C out << "Hello!" << endl;

19

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

20

How many times will the following loop display "Hello"? For (int i=20; i>0; i--) C out << "Hello!" << endl;

20

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

21

What will the following code display? int x=0; For (int count=0; count < 3; count ++) X += count; C out << X << endl;

3

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

5

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

6

A loop that is inside another loop is called:

A nested loop

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

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

Buffer

This statement may be used to stop a loop's current iteration and begin the next one.

Continue

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

Counter

To allow file access in a program, you must #include this header file.

F stream

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

False

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

False

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

False

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

False

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

To read data from a file, you define an object of this data type.

If stream

The While loop is this type of loop.

Pre-test

This is a special value hat marks the end of a list of values.

Sentinel

This may be used to write information to a file.

Stream insertion operator

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

True

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;


Ensembles d'études connexes

Ch. 13 Mindfulness, Meditation, and Self-Hypnosis

View Set

CEHv11 | Module 3 | Scanning Networks

View Set

Chapter 27: Adults (Psych - Exam 4)

View Set

Chapter 11: Voting and Participation

View Set

Customer Service Mid course review

View Set

1.2.4 Review Quiz: Plate Boundary Types

View Set

5. Comptia A+ 1101: Configuring Network Addressing and Internet Connections.

View Set

Worksheet 29.2: Directors and Officers

View Set

Intro to Public Policy - MIDTERM

View Set