Engineering Problem Solving with C++, 3e Chapter 2 Test Bank
1. Match each of the following data types with literal constants of that data type. A data type
can be used more than once.
2. For each of the following determine if it is a valid identifier, and if it is not state why.
3. Evaluate the following expressions
4. What is the output of the following program.
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{ int hr, min;
hr = 1;
min = 50;
cout << “The exam is over at ” << hr << “:” << min << endl;
cout << “One down\n ” << “two to go!” ;
return 0;
}
5. What is the output of the following program
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{ int WholeNumber;
double Real1, Real2;
WholeNumber = 76;
Real1 = 3.167;
Real2 = -24.103;
cout << setw(6) << WholeNumber << endl;
cout << setiosflags(ios::fixed);
cout << setprecision(2) << Real1 << “, ” << Real2 << endl;
cout << setiosflags(ios::showpoint) << Real2 << 8.376 << endl;
return 0;
}
6. Which of the following are valid on the left side of an assignment operator?
7. Which of the following are valid on the right side of an assignment operator?
9. The file which must appear in a #include preprocessor statement if you are using the fabs
function is …
10. Which of the following is not a data type used to represent a floating point value
11. Which of the following is not a syntactically correct declaration?
12. Which of the following operators is the increment operator
13. Which output flag is set to guarantee that a decimal point will be printed when printing a
floating point value?
14. Function arguments are …
15. Which of the following function invocations is an approximation of PI
17. The purpose of a comment is to help the compiler understand your program and create
efficient object code.
18. The math function sin will compute sine when given the angle in degrees
19. The setw manipulator is used to set the field width for all values that are printed until another
setw manipulator is encountered.
20. The preprocessor directive #include <iostream> copies the file iostream into the program
before compilation, so that the program can use input and output objects and operators.
21. The operand of the increment operator may be either a declared constant or a variable.
22. The math function tan will compute tangent when the angle is given in radians.
23. In a case sensitive language, such as C++, the variables apples and APPLES refer to
24. An expression involving operators can appear after the output operator << in a cout
25. The precision of a floating point number is determined by the number of bits used to
26. Given the declaration auto i = 0; i is declared as an int.
27. Given the declaration auto i = 1.0; i is declared as type double.
Engineering Problem Solving with C++, 3e Chapter 2 Test Bank
28. C++ is a strongly typed programming language.
29. Symbolic constants in C++ are declared with the modifier const; attempting to change the
33. Class attributes define the operations that may be performed on class objects.
34. Constructors are special methods of a class that are executed when objects of the class type
36. There must be exactly one constructor defined in every class.
37. Once a class is defined, you may use the class as a type specifier.