Name:
Class:
Date:
Page 1
Indicate whether the statement is true or false.
1. Another name for the selection structure is the decision structure.
a.
True
b.
False
2. Comparison operators are used to compare two values with differing data types.
a.
True
b.
False
3. By default in C++, smaller real numbers with a decimal place (those containing six or fewer digits to the left of the
decimal) are displayed in exponential notation.
a.
True
b.
False
4. With short-circuit evaluation, each sub-condition is independent of any other sub-condition.
a.
True
b.
False
5. Without a specialized instruction, in order to swap the contents of two variables a third variable is needed.
a.
True
b.
False
6. C++ provides stream manipulators that allow the programmer to control the format used to display real numbers.
a.
True
b.
False
7. In the summary of operators, all arithmetic operators will be evaluated prior to any logical operators.
a.
True
b.
False
8. The oval in a flowchart is the decision symbol.
a.
True
b.
False
9. The “equal to” operator has a higher precedence number than the “less than” operator in C++.
a.
True
b.
False
10. Another name for logical operators are comparison operators.
a.
True
b.
False
Indicate the answer choice that best completes the statement or answers the question.
11. Which of the following conditions tests to see if the variable number is equal to 29?
Name:
Class:
Date:
Page 2
a.
( number > 28)
b.
( number = 29 )
c.
( number == 29 )
d.
( number != 29 )
12. What is used to summarize how the computer evaluates the logical operators in an expression?
a.
Evaluation tables
b.
Logical tables
c.
Truth tables
d.
Symbol tables
13. What type of selection structure occurs when there are one or more actions to be taken only when its condition
evaluates to true?
a.
dual-alternative
b.
if/else
c.
single-alternative
d.
conditional block
14. For a program to use the setprecision stream manipulator, it must include which file?
a.
<iostream>
b.
<iomanip>
c.
<namespace>
d.
<cmath>
15. Selection structures that contain instructions on both the true and false paths are referred to as which of the following?
a.
single-alternative
b.
dual-alternative
c.
two path
d.
none of the above
16. What type of variable can be used only within the statement block in which it is defined?
a.
global
b.
block
c.
function
d.
local
17. What is another way that the condition below could be written?
( num <= 10 )
a.
(num < 11 || num < 10)
b.
(num > 9)
c.
( (num < 10) && (num = 10) )
d.
( (num < 10) || (num = 10) )
18. In an if statement, the programmer must supply the condition that the computer needs to evaluate before further
processing can occur. The condition must be which type of expression?
a.
comparison
b.
arithmetic
c.
Boolean
d.
data
19. In a selection structure, if a path contains more than one statement, the statements must be entered as a statement
block, which means they must be enclosed in which of the following?
a.
single quotes
b.
double quotes
c.
braces
d.
parentheses
20. What is the result of the following arithmetic expression in C++?
2 * (4 + 4)
a.
8
b.
12
c.
10
d.
16
21. A computer programmer can use which of the following to control the number of decimal places that appear when a
Name:
Class:
Date:
Page 3
real number is displayed?
a.
fixed stream manipulator
b.
scientific stream manipulator
c.
setprecision stream manipulator
d.
endl
22. What value is stored in the letter variable after the following code is executed?
char letter = ‘a’;
char letter2 = ’;
letter2 = toupper(letter);
a.
a
b.
A
c.
a blank space
d.
none of the above
23. What is the name of the process used to verify that the input data is within the expected range?
a.
Data validation
b.
Triage
c.
Data capping
d.
Data heuristics
24. What would be the result of the following C++ code (assuming all necessary directives)?
double number = 1234.567;
cout << scientific << number << endl;
a.
1234.567
b.
1234.6
c.
1234.567000
d.
1.234567e+03
25. What data type is required for the argument in the toupper and tolower functions?
a.
string
b.
bool
c.
letter
d.
char
26. Which symbol is used in C++ for the logical And operator?
a.
||
b.
@
c.
%
d.
&&
27. To display real numbers in exponential notation, the programmer would use which stream manipulator?
a.
fixed
b.
real
c.
scientific
d.
none of the above
28. Which of the following describes an item that appears between parentheses in a function’s syntax?
a.
data type
b.
relational operator
c.
function body
d.
argument
29. Which symbol in a flowchart is known as the decision symbol?
a.
oval
b.
rectangle
c.
parallelogram
d.
diamond
30. What would be the result of the following C++ code (assuming all necessary directives)?
double number = 1234.567;
cout << fixed << number << endl;
Name:
Class:
Date:
Page 4
a.
1234.567
b.
1234.6
c.
1234.567000
d.
1235
31. Which of the following comparison operators represents “not equal to” in C++?
a.
< >
b.
<=
c.
!=
d.
/=
32. What is the result of the following arithmetic expression in C++?
2 + 4 * 2
a.
8
b.
12
c.
10
d.
16
33. AND and OR are the two most commonly used examples of which type of operator?
a.
relational
b.
comparison
c.
boolean
d.
assignment
34. Stream manipulators that do not have arguments, such as fixed and scientific, are defined in which file?
a.
namespace
b.
iomanip
c.
iostream
d.
none of the above
35. Comparison operators evaluate to what type of value?
a.
integer
b.
boolean
c.
character
d.
real
36. What would be the result of the following C++ code (assuming all necessary directives)?
double number = 1234.56;
cout << fixed;
cout << setprecision(0);
cout << number << endl;
a.
1234
b.
1234.6
c.
1234.567000
d.
1235
37. Given the following code:
int number = 49;
What will be printed, if anything, and what will the value of the variable number be after the following statements are
executed?
if ( number >= 50)
cout << “yes” << endl;
number = number + 1;
38. Write an if statement that prints “yes” on the screen if the value stored in the variable number is between 1 and 100,
exclusive (excluding 1 and 100).
Name:
Class:
Date:
Page 5
39. Write an if statement that prints “yes” on the screen if the value stored in the variable number is between 1 and 100,
inclusive (including 1 and 100).
40. Given the following code:
int testScore = 0;
cout << “Enter the test score: “;
cin >> testScore;
Write an if statement that prints “yes” if the test score entered is valid, and “no” if it is not. A valid test score would be in
the range from 0 to 100, inclusive (including 0 and 100).
41. Rewrite the following if statement condition without using the != operator.
if ( number != 50 )
42. Given the following code:
int number = 50;
Write an if statement that prints “yes” and adds one to the number variable, if the value stored in the number variable is
greater than or equal to 50.
43. Given the following code:
char letter = ‘;
cout << “Enter a letter: “;
cin >> letter;
Rewrite the following if statement without using the toupper function:
if ( toupper(letter) = “X” )
cout << “The letter entered was either x or X” << endl;
44. Given the following code:
int x = 1;
int y = 2;
int z = 3;
What will the result of the condition in the if statement below be? Show your evaluation breakdown.
if ( (x == 2) || (y == 2) || (z == 2) )
45. Given the C++ instructions below, add the necessary instructions to swap the contents of the variables num1 and
num2.
int num1 = 10;
int num2 = 15;
int temp = 0;
Name:
Class:
Date:
Page 6
Name:
Class:
Date:
Page 7
Name:
Class:
Date:
Page 8