Clearly, the best way to learn C++--not just its language constructs, but how the language is actually put to use--is through problem solving and practice. Accordingly, the best-selling C++ Primer, Third Edition, by Stanley Lippman and Josée Lajoie, presents dozens of open-ended exercises to help C++ programmers gain practical experience and acquire a deeper understanding of the language's intricacies.
But what do you do when the answer to one of these exercises baffles you? Now you can turn to the C++ Primer Answer Book. Intended as a companion to the C++ Primer, the Answer Book provides the solutions to the exercises, allowing you to learn how the masters solve critical programming challenges. With the Answer Book in hand, you will have the technical explanations, practical techniques, and actual code to end your frustration and help you work through solutions.
This book is completely up-to-date, covering the final ANSI/ISO C++ Standard, extensions, standard library, and the STL. The exercises and corresponding solutions address a broad range of C++ topics, including
C++ programmers who use the C++ Primer Answer Book in conjunction with the C++ Primer will better understand the concepts of C++ by working through the exercises, and will gain new perspectives through reviewing these solutions.
1 Getting Started.
2 A Tour of C++.
3 The C++ Data Types.
6 Abstract Container Types.
8 Scope and Lifetime.
9 Overloaded Functions.
10 Function Templates.
11 Exception Handling.
12 The Generic Algorithms.
14 Class Initialization, Assignment, and Destruction.
15 Overloaded Operators and User-Defined Conversions.
16 Class Templates.
17 Class Inheritance and Subtyping.
18 Multiple and Virtual Inheritance.
19 Uses of Inheritance in C++.
20 The iostream Library.
C++ has proven to be a popular programming language, and C++ Primer has proven to be just as popular among those wishing to learn the language. Learning a programming language, however, requires more than just reading about the language constructs. You must program, write your own code, and study code written by those who are more experienced with the use of the language.
To this end, Lippman and Lajoie (L&L) have provided exercises throughout C++ Primer to encourage their readers to test their understanding of the material. Our book provides the solutions to those exercises.
C++ Primer Answer Book is intended to be used in conjunction with C++ Primer. We assume that you have read the material in L&L preceding each exercise. We present our solution along with an explanation, but we do not repeat the material found in L&L. Only those concepts and constructs that have already been introduced are used in the solutions.
When the solution involves a complete program, we generally include the entire source code so that each solution stands on its own. All programs have been compiled using Microsoft Visual C++ Version 5.0. In some instances when the compiler did not meet the standard, a workaround was used and an explanation given.We recommend that you use L&L to learn C++, work the exercises, and study the solutions presented here. We hope C++ Primer Answer Book will aid you in understanding C++ while eliminating the frustration of being stuck without an answer to a problem.
Special thanks go to Stan Lippman and Josée Lajoie for having the faith to allow us to write this answer book and for their careful review of the text.
Sean Davey, Steve Edwards, S. Rollins Guild, Cay Horstmann, and Jeffrey Oldham provided many helpful comments on the manuscript.
Clovis thanks George Edmunds, Sam Hsu, Mohammad Ilyas, Mahesh Neelakanta, and Cyril Párkányi for their continued support; Sean Davey for the C++ review, for the LaTeX macros, and for his technical support; Andrew Nathanson for his friendship and software/hardware support; S. Rollins Guild for the C++ review and his friendship; A. Carlos Tondo, Julia Mistrello, and Luiz and Elizabete T. Biavatti for helping our company succeed; and Caren E. Tondo for her love, patience, and sense of humor.
Bruce thanks Andrew Bellezza, Jodi Solomon, and Mary Walstrom for their friendship and encouragement; Zahira Ammarguellat, Luddy Harrison, Sandra Loosemore, and Cotton Seed -- one couldn't ask for better co-workers; and Misty and Buddy for their boundless patience.
Last, but certainly not least, we thank the staff at Addison-Wesley. We are especially grateful to our associate editor, Debbie Lafferty, for her patience and knowing when and how hard to push; the production editor, Maureen Willard, for guiding us through the editing, proofs, and final pages; the production manager, John Fuller, for getting the macros approved and improved early in the process; and the freelancer, Diane Freed, for assisting with the production of this book. We appreciate your kind help.Clovis L. Tondo