Absolute C++, 6th edition
By Walter Savitch, Kenrick Mock
IM
PR
ES
SI
VE
G
R
AD
ES
, Table of Content
Chapter 1 C++ BASICS 1
Chapter 2 FLOW OF CONTROL 45
Chapter 3 FUNCTION BASICS 99
IM
Chapter 4 PARAMETERS AND OVERLOADING 145
Chapter 5 ARRAYS 185
Chapter 6 STRUCTURES AND CLASSES 239
PR
Chapter 7 CONSTRUCTORS AND OTHER TOOLS 275
Chapter 8 OPERATOR OVERLOADING, FRIENDS, AND REFERENCES 321
Chapter 9 STRINGS 367
ES
Chapter 10 POINTERS AND DYNAMIC ARRAYS 419
Chapter 11 SEPARATE COMPILATION AND NAMESPACES 471
Chapter 12 STREAMS AND FILE I/O 515
Chapter 13 RECURSION 571
SI
Chapter 14 INHERITANCE 613
Chapter 15 POLYMORPHISM AND VIRTUAL FUNCTIONS 661
VE
Chapter 16 TEMPLATES 693
Chapter 17 LINKED DATA STRUCTURES 731
Chapter 18 EXCEPTION HANDLING 825
G
Chapter 19 STANDARD TEMPLATE LIBRARY 857
Chapter 20 PATTERNS AND UML (online at www.pearsonhighered.com/savitch)
R
AD
ES
, uytrew
Chapter 1 - Test Questions
These test questions are fill in the blank, multiple choice, and true-false. The
multiplechoice questions may have more than one correct answer. There is one
IM
matching question. Mark all of the correct answers for full credit.
True False questions require an explanation in addition to the true/false response, and, if
false, also require a correction.
PR
True False:
Comment required.
1. OOP is an acronym that means Object Oriented Programming.
ES
Answer: True.
Explanation: OOP is currently popular and is a powerful programming technique for a
large class of problems.
SI
2. C++ not only supports OOP but also supports other programming styles.
Answer: True.
Explanation: C++ supports OOP and traditional procedure oriented programming.
VE
3. The namespace facility is a tool used that assists in the study of genealogy.
Answer: False.
Explanation: The namespace facility helps prevent the libraries from “preempting all the
good names,” and allows us to use names we want whether the library has used them.
G
4. In C++ the variables Alpha, ALPHA and AlphA are the same identifier.
Answer: False.
R
Explanation: C++ is case sensitive, these are different identifiers.
5. In C++ the compiler will infer the type intended for a variable from the context in
AD
which the variable occurs.
Answer: False.
Explanation: C++ requires every identifier to be declared prior to use. The type is
ES
specified in the declaration.
6. A C++ declaration introduces only an identifier's spelling and specifies its type.
Answer: True.
Explanation: A declaration introduces the spelling and type, whereas a definition is a
uytre
, declaration that also allocates memory.
7. A C++ declaration is a definition that also allocates storage for an identifier's value
(or function's body etc.).
IM
Answer: True.
Explanation: A declaration introduces the spelling and type, whereas a definition is a
declaration that also allocates memory.
PR
8. The range of values for an int variable is from about 0 to +2 billion.
Answer: False:
Explanation: The correct range is about –2 Billion to +2 Billion.
9. The names x, y, and z are satisfactory variable names for the lengths of the legs and
ES
hypotenuse of a triangle.
Answer: False.
Explanation: Names should communicate to the human reader the meaning of the value.
SI
These identifiers do not communicate the meaning of their values..
10. In C++ you can assign an expression of type int to a variable of type double with
no problem.
VE
Answer: True.
Explanation: Assignment from an integer type to a floating point type can lose
information and should be avoided. Some compilers will warn, others may give an error
G
message, but you should avoid this.
11. In C++ you can assign an expression of type double to a variable of type int with
R
no problem.
Answer: False.
AD
Explanation: In general assigning a floating point value to an integer variable mostly
loses information. A warning message (or an error message) is issued by C++ compilers.
12. To put a character into a cstring constant that causes the output to continue on the
next line, insert the escape sequence \t into the string constant.
ES
Answer: False.
Explanation: \t is the tab escape sequence. Use \n instead.
13. If we execute this code in an otherwise correct and complete program:
n = 1;