ch2
ch2
ae
MULTIPLE CHOICE
5. The _____ causes the contents of another file to be inserted into a program.
a. Backslash
b. Pound sign
c. Semicolon
d. #include directive
e. None of the above
7. These are data items whose values do not change while the program is running.
a. Literals
b. Variables
c. Comments
d. Integers
e. None of the above
8. You must have a ___________ for every variable you intend to use in a program.
a. purpose
b. definition
c. comment
d. constant
e. None of the above
10. The numeric data types in C++ can be broken into two general categories:
a. numbers and characters
b. singles and doubles
c. integer and floating point
d. real and unreal
e. None of the above
cout << "A double is stored in " << sizeof(double) << " bytes.";
12. A character literal is enclosed in ________ quotation marks, whereas a string literal is
enclosed in ________ quotation marks.
a. double, single
b. triple, double
c. open, closed
d. single, double
e. None of the above
13. In memory, C++ automatically places a ___________ at the end of string literals.
a. Semicolon
b. Quotation marks
c. Null terminator
d. Newline escape sequence
e. None of the above
14. Which escape sequence causes the cursor to move to the beginning of the next line?
a. \n
b. \t
c. \a
d. \b
e. \r
15. What is the modulus operator?
a. +
b. *
c. &
d. %
e. ||
16. Which data type typically requires only one byte of storage?
a. short
b. int
c. float
d. char
e. double
a. 15
b. 12
c. 63
d. 72
e. None of these
18. In programming terms, a group of characters inside a set of quotation marks is called a:
a. String literal
b. Variable
c. Operation
d. Statement
e. None of the above
19. This is used to mark the end of a complete C++ programming statement.
a. Pound Sign
b. Semicolon
c. Data type
d. Void
e. None of the above
21. ____________ must be included in any program that uses the cout object.
a. Opening and closing braces
b. The header file iostream
c. Comments
d. Escape sequences
e. None of the above
22. If you use a C++ key word as an identifier, your program will:
a. execute with unpredictable results
b. not compile
c. understand the difference and run without problems
d. compile, link, but not execute
e. None of the above
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. bytes
c. f(x)
d. int
e. sizeof
26. These are used to declare variables that can hold fractional numbers.
a. Integer data types
b. Real data types
c. Floating point data types
d. Long data types
e. None of the above
27. The float data type is considered _________ precision, and the double data type is
considered _________ precision.
a. single, double
b. float, double
c. integer, double
d. short, long
e. None of the above
28. A variable whose value can be either true or false is of this data type.
a. binary
b. bool
c. T/F
d. float
e. None of the above
29. How would you consolidate the following declaration statements into one statement?
int x = 7;
int y = 16;
int z = 28;
30. A variable's ___________ is the part of the program that has access to the variable.
a. data Type
b. value
c. scope
d. reach
e. None of the above
32. This control sequence is used to skip over to the next horizontal tab stop.
a. \n
b. \h
c. \t
d. \a
e. \'
a. 13 and 14 d. 13
b. 8 and 9 e. 15
c. 14
35. Which of the following defines a double-precision floating point variable named payCheck?
a. Monday c. MondayTuesdayWednesday
Tuesday
Wednesday
b. Monday Tuesday Wednesday d. "Monday"
"Tuesday"
"Wednesday"
int number = 7;
cout << "The number is " << "number" << endl;
int x = 0, y = 1, z = 2;
cout << x << y << z << endl;
a. 0 1 2 c. xyz
b. 0 d. 012
1
2
a. Four c. Four
score score
and and seven
seven years ago
years ago
d. Four
score
and
seven
yearsago
41. What will the following code display?
a. Four
score
and
seven
years
ago
d. Fourscore
andseven
yearsago
char letter;
Which of the following statements correctly assigns the character Z to the variable?
43. What will the value of x be after the following statements execute?
int x;
x = 18 / 4;
a. 4.5 c. 0
b. 4 d. unknown
44. What will the value of x be after the following statements execute?
int x;
x = 18.0 / 4;
a. 4.5 c. 0
b. 4 d. unknown
45. What will the value of x be after the following statements execute?
int x;
x = 18 % 4;
a. 0.45 c. 2
b. 4 d. unknown
46. Assuming you are using a system with 1-byte characters, how many bytes of memory
will the following string literal occupy?
"William"
a. 7 c. 8
b. 14 d. 1
47. The first step in using the string class is to #include the ___________ header file.
a. Iostream
b. Cctype
c. Cmath
d. String
e. None of the above
48. Assume that a program has the following string object definition:
string name;
Which of the following statements correctly assigns a string literal to the string object?
51. What will be the output after the following statement executes?
a. 5.0
b. 5
c. 2.0
d. 2
e. None of the above
6.7245E2
7.34e-4
2356.7
TRUE/FALSE
1. When typing in your source code into the computer, you must be very careful since most of your C++
instructions, header files, and variable names are case sensitive.
ANS: T/F
3. The C++ language requires that you give variables names that indicate what the variables are used for.
ANS: T/F
4. A variable called "average" should be declared as an integer data type because it will probably hold data that
contains decimal places.
ANS: T/F
7. C++ does not have a built in data type for storing strings of characters.
ANS: T/F
8. If you do not follow a consistent programming style, your programs will generate compiler errors.
ANS: T/F