Cs135- Chapter 5 quiz

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

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

update

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

21

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

3

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

for

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

fstream

This means to increase a value by one.

increment

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.

ofstream

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 do-while loop is a(n) ________ 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

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

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

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

ifstream

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

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

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


Ensembles d'études connexes

Comp sci quiz compendium 8,9,10,12

View Set

Chapter 18 - Cardiovascular System - Blood

View Set

APES Chapter 1; What is an Environmentally Sustainable Society?

View Set

Unanticipated Problems and Reporting Requirements in Social and Behavioral Research

View Set

Chapter 7: Portable Fire Extinguishers

View Set

Two-Variable Linear Inequalities

View Set