C++ Primer Plus, Fifth Edition
Copyright © 2005 by Sams Publishing
CONTENTS AT A GLANCE
TABLE OF CONTENTS
ABOUT THE AUTHOR
WE WANT TO HEAR FROM YOU!
INTRODUCTION
CHAPTER 1 GETTING STARTED
Learning C++: What Lies Before You
The Origins of C++: A Little History
Portability and Standards
The Mechanics of Creating a Program
Summary
CHAPTER 2 SETTING OUT TO C++
C++ Initiation
C++ Statements
More C++ Statements
Functions
Summary
Review Questions
Programming Exercises
CHAPTER 3 DEALING WITH DATA
Simple Variables
The const Qualifier
Floating-Point Numbers
C++ Arithmetic Operators
Summary
Review Questions
Programming Exercises
CHAPTER 4 COMPOUND TYPES
Introducing Arrays
Strings
Introducing the string Class
Introducing Structures
Unions
Enumerations
Pointers and the Free Store
Pointers, Arrays, and Pointer Arithmetic
Summary
Review Questions
Programming Exercises
CHAPTER 5 LOOPS AND RELATIONAL EXPRESSIONS
Introducing for Loops
Relational Expressions
The while Loop
The do while Loop
Loops and Text Input
Nested Loops and Two-Dimensional Arrays
Summary
Review Questions
Programming Exercises
CHAPTER 6 BRANCHING STATEMENTS AND LOGICAL OPERATORS
The if Statement
Logical Expressions
The cctype Library of Character Functions
The ?: Operator
The switch Statement
The break and continue Statements
Number-Reading Loops
Simple File Input/Output
Summary
Review Questions
Programming Exercises
CHAPTER 7 FUNCTIONS: C++’S PROGRAMMING MODULES
Function Review
Function Arguments and Passing by Value
Functions and Arrays
Functions and Two-Dimensional Arrays
Functions and C-Style Strings
Functions and Structures
Functions and string Class Objects
Recursion
Pointers to Functions
Summary
Review Questions
Programming Exercises
CHAPTER 8 ADVENTURES IN FUNCTIONS
C++ Inline Functions
Reference Variables
Default Arguments
Function Overloading
Function Templates
Summary
Review Questions
Programming Exercises
CHAPTER 9 MEMORY MODELS AND NAMESPACES
Separate Compilation
Storage Duration, Scope, and Linkage
The Placement new Operator
Namespaces
Summary
Review Questions
Programming Exercises
CHAPTER 10 OBJECTS AND CLASSES
Procedural and Object-Oriented Programming
Abstraction and Classes
Class Constructors and Destructors
Knowing Your Objects: The this Pointer
An Array of Objects
The Interface and Implementation Revisited
Class Scope
Abstract Data Types
Summary
Review Questions
Programming Exercises
CHAPTER 11 WORKING WITH CLASSES
Operator Overloading
Time on Our Hands: Developing an Operator Overloading Example
Introducing Friends
Overloaded Operators: Member Versus Nonmember Functions
More Overloading: A Vector Class
Automatic Conversions and Type Casts for Classes
Summary
Review Questions
Programming Exercises
CHAPTER 12 CLASSES AND DYNAMIC MEMORY ALLOCATION
Dynamic Memory and Classes
A Queue Simulation
Summary
Review Questions
Programming Exercises
CHAPTER 13 CLASS INHERITANCE
Beginning with a Simple Base Class
Inheritance: An Is-a Relationship
Polymorphic Public Inheritance
Access Control: protected
Abstract Base Classes
Inheritance and Dynamic Memory Allocation
Class Design Review
Summary
Review Questions
Programming Exercises
CHAPTER 14 REUSING CODE IN C++
Classes with Object Members
Private Inheritance
Multiple Inheritance
Class Templates
Summary
Review Questions
Programming Exercises
CHAPTER 15 FRIENDS, EXCEPTIONS, AND MORE
Friends
Nested Classes
Exceptions
RTTI
Type Cast Operators
Summary
Review Questions
Programming Exercises
CHAPTER 16 THE string CLASS AND THE STANDARD TEMPLATE LIBRARY
The string Class
The auto_ptr Class
The STL
Generic Programming
Function Objects (aka Functors)
Algorithms
Other Libraries
Summary
Review Questions
Programming Exercises
CHAPTER 17 INPUT, OUTPUT, AND FILES
An Overview of C++ Input and Output
Output with cout
Input with cin
File Input and Output
Incore Formatting
What Now?
Summary
Review Questions
Programming Exercises
APPENDIX A NUMBER BASES
Decimal Numbers (Base 10)
Octal Integers (Base 8)
Hexadecimal Numbers (Base 16)
Binary Numbers (Base 2)
Binary and Hex
APPENDIX B C++ RESERVED WORDS
C++ Keywords
Alternative Tokens
C++ Library Reserved Names
APPENDIX C THE ASCII CHARACTER SET
APPENDIX D OPERATOR PRECEDENCE
APPENDIX E OTHER OPERATORS
Bitwise Operators
Member Dereferencing Operators
APPENDIX F THE string TEMPLATE CLASS
Thirteen Types and a Constant
Data Information, Constructors, and Odds and Ends
String Access
Basic Assignment
String Searching
Comparison Methods and Functions
String Modifiers
Output and Input
APPENDIX G THE STL METHODS AND FUNCTIONS
Members Common to All Containers
Additional Members for Vectors, Lists, and Deques
Additional Members for Sets and Maps
STL Functions
APPENDIX H SELECTED READINGS AND INTERNET RESOURCES
Selected Readings
Internet Resources
APPENDIX I CONVERTING TO ANSI/ISO STANDARD C++
Use Alternatives for Some Preprocessor Directives
Use Function Prototypes
Use Type Casts
Become Familiar with C++ Features
Use the New Header Organization
Use Namespaces
Use the autoptr Template
Use the string Class
Use the STL
APPENDIX J ANSWERS TO THE REVIEW QUESTIONS
Answers to Review Questions for Chapter 2
Answers to Review Questions for Chapter 3
Answers to Review Questions for Chapter 4
Answers to Review Questions for Chapter 5
Answers to Review Questions for Chapter 6
Answers to Review Questions for Chapter 7
Answers to Review Questions for Chapter 8
Answers to Review Questions for Chapter 9
Answers to Review Questions for Chapter 10
Answers to Review Questions for Chapter 11
Answers to Review Questions for Chapter 12
Answers to Review Questions for Chapter 13
Answers to Review Questions for Chapter 14
Answers to Review Questions for Chapter 15
Answers to Review Questions for Chapter 16
Answers to Review Questions for Chapter 17
INDEX