What is the output of the following code segment? n = 1; while (n <= 5) cout <<
ID: 3641328 • Letter: W
Question
What is the output of the following code segment?n = 1;
while (n <= 5)
cout << n << ' ';
n++;
A) 1 2 3 4
B) 2 3 4 5
C) 2 3 4 5 6
D) 1 1 1... and on forever
E) 1 2 3 4 5
2. Multiple relational expressions cannot be placed into the test condition of a for loop.
A) True
B) False
3. How many times will the following loop display "Hello"?
for (int i = 1; i < 20; i++)
cout << "Hello!" << endl;
A) 21
B) 19
C) 20
D) an infinite number of times
4. ________ must be included in any program that uses the cout object.
A) The header file iostream
B) Comments
C) Escape sequences
D) Opening and closing braces
E) None of these
5. Please skip this question, this part refers to the in-class (performance) programming part of the exam
HTML Editor6. A while loop is somewhat limited, because the counter can only be incremented by one each time through the loop.
A) True
B) False
7. Which statement allows you to properly check the char variable code to determine whether it is equal to a "C" and then output "This is a check" and then advance to a new line?
A) if (code == 'C')
cout << "This is a check ";
B) if (code = "C")
cout << "This is a check" << endl;
C) if (code == C)
cout << "This is a check" << endl;
D) if code is equal to C
cout << "This is a check ";
8. Something within a while loop must eventually cause the condition to become false, or a(n) ________ results.
A) compiler error
B) null value
C) unexpected exit
D) infinite loop
E) None of these
9. Input values should always be checked for:
A) reasonableness
B) appropriate range
C) division by zero, if division is taking place
D) All of these
E) None of these
10. This operator increments the value of its operand, then uses the value in context.
A) postfix increment
B) prefix increment
C) prefix decrement
D) postfix decrement
E) None of these
11. Which of the following defines a double-precision floating point variable named payCheck?
A) Double payCheck;
B) double payCheck;
C) payCheck double;
D) float payCheck;
12. 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?
A) outFile << number;
B) number >> outFile;
C) outFile >> number;
D) write(outFile, number);
13. In the following C++ statement, what will be executed first according to the order of precedence?
result = 6 - 3 * 2 + 7 - 10 / 2 ;
A) 7 - 10
B) 6 - 3
C) 10 / 2
D) 3 * 2
E) 2 + 7
14. What will the following segment of code output?
score = 40;
if (score > 95)
cout << "Congratulations! ";
cout << "That's a high score! ";
cout << "This is a test question!" << endl;
A) That's a high score!
This is a test question!
B) This is a test question!
C) Congratulations!
That's a high score!
This is a test question!
D) Congratulations!
That's a high score!
E) None of these
15. A CPU really only understands instructions that are written in machine language.
A) True
B) False
16. In memory, C++ automatically places a ________ at the end of string literals.
A) semicolon
B) quotation marks
C) newline escape sequence
D) null terminator
E) None of these
17. The following code correctly determines whether x contains a value in the range of 0 through 100.
if (x >= 0 && <= 100)
A) True
B) False
18. The only difference between the get function and the >> operator is that get reads the first character typed, even if it is a space, tab, or the [Enter] key.
A) True
B) False
19. Mistakes that cause a running program to produce incorrect results are called:
A) syntax errors
B) linker errors
C) logic errors
D) compiler errors
E) None of these
20. In the process of translating a source file into an executable file, which of the following is the correct sequence?
A) source code, preprocessor, modified source code, compiler, object code, linker, executable code
B) source code, compiler, modified source code, preprocessor, object code, linker, executable code
C) source code, linker, object code, compiler, modified source code, preprocessor, executable code
D) preprocessor, source code, compiler, executable code, linker, modified source code, object code
E) source code, preprocessor, modified source code, linker, object code, compiler, executable code
21. The statement
cout << setprecision(5) << dollars << endl;
will output $5.00 to the screen.
A) True
B) False
22. In programming, the terms "line" and "statement" always mean the same thing.
A) True
B) False
23. If the sub-expression on the left side of the || operator is true, the expression on the right side will not be checked.
A) True
B) False
24. This function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires.
A) len
B) sizeof
C) int
D) bytes
E) f(x)
25. What is the value stored at x, given the statements:
int x;
x = 3 / static_cast<int>(4.5 + 6.4);
A) 3.3
B) 0
C) .3
D) .275229
E) None of these
26. What will the following loop display?
int x = 0;
while (x < 5)
{
cout << x << endl;
x++;
}
A) 0
1
2
3
4
5
B) 0
1
2
3
4
C) 01 2 3 4
D) The loop will display numbers starting at 0, for infinity.
Explanation / Answer
1E, 2A, 3B, 4A, 5(skip), 6B, 7A, 8E, 9D, 10B, 11B, 12A, 13D, 14E, 15A, 16E, 17A, 18A, 19C, 20C, 21B, 22B, 23A, 24B, 25D, 26B
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.