Name: __________________________ Date: _____________



1.
Any statement used to alter the normally sequential flow of control is called a(n) ____________________.

Answer:


2.
If the int variables i, j, and k contain the values 10, 3, and 20, respectively, what is the value of the following logical expression: j < 4 || j == 5 && i <= k
A.
3
B.
false
C.
20
D.
true


3.
True or False? If P and Q are logical expressions, the expression P AND Q is TRUE if either P or Q is TRUE or both are TRUE.
A. True
B. False


4.
True or False? An example of a logical (Boolean) expression is an arithmetic expression followed by a relational operator followed by an arithmetic expression.
A. True
B. False


5.
An If-Then-Else-If structure represents a(n) ____________________-way branch.

Answer:


6.
What does the following statement print? (All variables are of type int.)

if (j < k)
if (k < j)
   cout << 1;
else
   cout << 2;
else
if (j < k)
   cout << 3;
else
   cout << 4;
A.
It prints nothing unless j equals k.
B.
It always prints 4.
C.
It prints 2 if j equals k and 4 otherwise.
D.
It prints 2 if j < k and 1 if k <= j.
E.
It prints 2 if j < k and 4 otherwise.


7.
After the code is written in the implementation phase, you should go over it line by line. This process is known as a(n) ____________________.

Answer:


8.
Consider the following If statement, which is syntactically correct but uses poor style and indentation:

if (x >= y) if (y > 0) x = x * y; else if (y < 4) x = x - y;

Assume that x and y are int variables containing the values 3 and 9, respectively, before execution of the above statement. After execution of the statement, what value will x contain?
A.
9
B.
-6
C.
6
D.
27
E.
none of the above


9.
If p is a Boolean variable, which of the following logical expressions always has the value false?
A.
p && p
B.
p || p
C.
p && !p
D.
p || !p
E.
b and d above


10.
True or False? Boolean variables cannot store the result of a comparison of two variables.
A. True
B. False


11.
Which logical operator (op) is defined by the following table? (T and F denote TRUE and FALSE.)


P
Q   P op Q
------------
T
T
T
T
F
F
F
T
F
F
F
F
 
A.
NOT
B.
AND
C.
OR
D.
none of the above


12.
Write a C++ logical expression that is true if the variable testScore is greater than or equal to 90 and less than or equal to 100: ____________________

Answer:


13.
If DeMorgan's Law is used to negate the expression

   (i < j) && (k == l)

then the result is:
A.
(i < j) || (k == l)
B.
(i > j) && (k != l)
C.
(i >= j) || (k != l)
D.
(i > j) || (k != l)
E.
(i >= j) && (k != l)


14.
True or False? The expression !(n < 5) is equivalent to the expression n > 5.
A. True
B. False


15.
The operators <, ==, >=, and != are examples of ____________________ operators. (Do not answer "binary.")

Answer:


16.
After execution of the following code, what will be the value of angle if the input value is 10?

cin >> angle;
if (angle > 5)
angle = angle + 5;
if (angle > 2)
angle = angle + 10;
A.
0
B.
5
C.
10
D.
15
E.
25


17.
Given the following code:

string name1;
string name2;

name1 = "Mark";
name2 = "Mary";

what is the value of the relational expression string1 < string2 ?
A.
true
B.
false
C.
none; it causes a compile-time error
D.
none; it causes a run-time error


18.
True or False? Implementing a test plan guarantees that a program is completely correct.
A. True
B. False


19.
This question is about short-circuit evaluation of logical expressions. Consider the following expression in some imaginary programming language (not C++):

(N > 5) AND (K / N < 12)

If N equals 0 when this expression is evaluated, which of the following statements about the expression is true?
A.
It causes a divide-by-zero error only if the language uses short-circuit evaluation.
B.
It causes a divide-by-zero error only if the language does not use short-circuit evaluation.
C.
It causes a divide-by-zero error whether or not the language uses short-circuit evaluation.
D.
It never causes a divide-by-zero error.


20.
After execution of the following code, what will be the value of angle if the input value is 10?

n >> angle;
if (angle > 5)
angle = angle + 5;
else if (angle > 2)
angle = angle + 10;
A.
0
B.
5
C.
10
D.
15
E.
25



STOP This is the end of the test. When you have completed all the questions and reviewed your answers, press the button below to grade the test.