Chapter 5 Computer Science Questions-AB

¡Supera tus tareas y exámenes ahora con Quizwiz!

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

++ and --

What will the following loop display? int x = 0; while (x < 5) { cout << x << endl; 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 1... and on forever

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

19

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

20

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

20

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

Answer is NOT 0 1 2 possibly 3

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

False

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

False

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

The answer is NOT 20 probably 21

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

True

True/ False: It is possible to define a file stream object and open a file in one statement.

True

A loop that is inside another loop is called:

a nested loop

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

continue statement

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

ifstream

This means to increase a value by one.

increment

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 file must be ________ before data can be written to or read from it.

opened

The do-while loop is a ________ loop that is ideal in situations where you always want the loop to iterate at least once.

post-test

The do-while loop is considered a(n) ________ loop.

post-test

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

prefix

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

update

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

variable

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

6

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

7

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

7

int number = 6; cout << ++number << endl;

7

True/ False: You may nest while and do-while loops, but you may not nest for loops.

False

True/ False: You may not use the break statement in a nested loop.

False

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 ________ is a small holding section of memory that file-bound information is first written to.

buffer

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


Conjuntos de estudio relacionados

Chapter 24: Environmental Emergencies

View Set

Unit 5 Managing/Coordinating Care

View Set

Serial Dilutions Mastering Microbiology Lab Homework

View Set

Chapter 20. Electroconvulsive Therapy (Practice)

View Set

Child and Adolescent Pathology exam 1

View Set

Chapter 3. Cost-Volume-Profit Relationships

View Set