Chapter Five Quiz Questions

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

++ and --

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

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

19

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?

<

A loop that is inside another loop is called:

A nested loop

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

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

Buffer

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

Closes a file

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

You may nest While and Do-While loops, but you may not nest For loops.

False

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

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

The While loop is this type of loop.

Pre-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

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

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

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

Update

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

Variable

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;

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; Number++; C out << number << endl;

7

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

True

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

6

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

0 1 2 3 4 5

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; Int X=0; X=number--; C out << X << endl;

6

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

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 want to stop the loop before it goes through all its iterations, the Break statement may be used.

True

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

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

7

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

False

You may not use the Break and Continue statements within the same set of nested 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

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

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

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


Kaugnay na mga set ng pag-aaral

Lecture Four: Glucose Absorption

View Set

Macroeconomics/ Chapter 4 Demand and Supply

View Set