Engineering Problem Solving with C++, 3e Chapter 3 Test Bank
1. Evaluate the following expressions.
2. What is the correct output from the following program?
#include <iostream>
using namespace std;
int main()
{ int A, B;
A = 6;
B = 1;
if (A > B)
{ A = A * B + 2;
B ++;
}
else
{ A = A / 2;
B = B + 4;
}
cout << “A = “ << A << “ B = “ << B;
return 0;
}
3. What is the output of the following program?
#include <iostream>
using namespace std;
int main()
{ int Num, X, Y;
Num = 4;
X = 5;
Y = 6;
switch (Num)
{ case 1: X = Num;
break;
case 2: Y = Y + 3;
case 3: X = Num + 4;
break;
case 4: X = X * 3;
default: Y = Y – 3;
}
cout << “X = ” << X << ” and Y = ” << Y;
return 0;
4. What is the output of the following program?
#include <iostream>
using namespace std;
int main()
{ int X, Y;
X = 30;
if (X <= 5)
{ Y = X * X;
X = X + 5;
}
else
{ if (X < 10)
Y = X – 2;
else if (X < 25)
Y = X + 10;
else
Y = X / 10;
X++;
}
cout << “Y = “ << Y << “; X = “ << X;
return 0;
5. Which of the following operators is a relational operator
6. Which of the following operators is a logical operator
8. The operator = is used to determine whether the left hand operand is equivalent to the right
hand operand.
9. The value which follows the word case in a switch statement can be of type integer or
character.
10. The operands of the operator || must both be Boolean values.
11. A blank space can be placed between the ampersands in the logical operator && to make it
more readable.
12. Linear interpolation is used to …
13. Which of the following are characteristics of a good algorithm:
15. Top-down design begins with a ‘big picture’ description of a problem solution in sequential
steps; the sequential steps are repeatedly refined until the steps are detailed enough to
17. In C++, the = and == operators perform identical operations and may be used
interchangeably.
18. Which of the following C++ operators performs logical not equal:
19. Complete the true table for C++ logical operators.
A
B
A&&B
A||B
!B
false
false
false
false
true
false
true
false
true
false
true
false
false
true
true
true
true
true
true
false
20. C++ only evaluates as much of a logical expression as necessary to evaluate it; this is called
Engineering Problem Solving with C++, 3e Chapter 3 Test Bank
23. The control expression in C++ switch statements may be of type string.