Module 5
This statement may be used to stop a loop's current iteration and begin the next one.
Continue
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
To allow file access in a program, you must #include this header file.
fstream
How many times will the following loop display "Hello"? for (int i = 1; i < 20; i--) cout << "Hello!" << endl;
An infinite number of times
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;
What will the following code display? (Beware, this is a tricky one.) int x = 0; for (int count = 0; count < 5; count++) x += count; cout << x << endl;
10
How many times will the following loop display "Hello"? for (int i = 1; i <= 4; i++) for (int j = 1; j <= 5; j++) cout << "Hello" << endl;
20
The following code correctly validates the variable value to be in the range of 0 through 100: while ( (value < 0) && (value > 100) ) { cout <<"Invalid entry. Please enter a number between 0 and 100: " cin >> value; }
False
What is wrong with the following code? int sum; //sum is accumulator int num ; //counter for (num =1; num <= 10; num++) { sum += num; } cout << "Sum of numbers 1 - 10 is " << sum << endl;
The variable sum is not initialized.
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