I l
@
ve RuBoard
•
Table of Contents
•
Index
•
Reviews
•
Examples
•
Reader Reviews
•
Errata
Practical C++ Programming
By
Steve Oualline
Publisher
: O'Reilly
Pub Date
: December 2002
ISBN
: 0-596-00419-2
Pages
: 574
Copyright
Preface
Scope of This Handbook
How This Book Is Organized
How to Read This Book If You Already Know C
Font Conventions
How to Contact Us
Acknowledgments for the First Edition
Acknowledgments for the Second Edition
Part I: The Basics
Chapter 1. What Is C++?
Section 1.1. A Brief History of C++
Section 1.2. C++ Organization
Section 1.3. How to Learn C++
Chapter 2. The Basics of Program Writing
Section 2.1. Programs from Conception to Execution
Section 2.2. Creating a Real Program
Section 2.3. Getting Help in Unix
Section 2.4. Getting Help in an IDE
Section 2.5. Programming Exercises
Chapter 3. Style
Section 3.1. Comments
Section 3.2. C++ Code
Section 3.3. Naming Style
Section 3.4. Coding Religion
Section 3.5. Indentation and Code Format
Section 3.6. Clarity
Section 3.7. Simplicity
Section 3.8. Consistency and Organization
Section 3.9. Further Reading
Section 3.10. Summary
Chapter 4. Basic Declarations and Expressions
Section 4.1. Basic Program Structure
Section 4.2. Simple Expressions
Section 4.3. The std::cout Output Object
Section 4.4. Variables and Storage
Section 4.5. Variable Declarations
Section 4.6. Integers
Section 4.7. Assignment Statements
Section 4.8. Floating-Point Numbers
Section 4.9. Floating-Point Divide Versus Integer Divide
Section 4.10. Characters
Section 4.11. Wide Characters
Section 4.12. Boolean Type
Section 4.13. Programming Exercises
Section 4.14. Answers to Chapter Questions
Chapter 5. Arrays, Qualifiers, and Reading Numbers
Section 5.1. Arrays
Section 5.2. Strings
Section 5.3. Reading Data
Section 5.4. Initializing Variables
Section 5.5. Multidimensional Arrays
Section 5.6. C-Style Strings
Section 5.7. Types of Integers
Section 5.8. Types of Floats
Section 5.9. Constant and Reference Declarations
Section 5.10. Qualifiers
Section 5.11. Hexadecimal and Octal Constants
Section 5.12. Operators for Performing Shortcuts
Section 5.13. Side Effects
Section 5.14. Programming Exercises
Section 5.15. Answers to Chapter Questions
Chapter 6. Decision and Control Statements
Section 6.1. if Statement
Section 6.2. else Statement
Section 6.3. How Not to Use std::strcmp
Section 6.4. Looping Statements
Section 6.5. while Statement
Section 6.6. break Statement
Section 6.7. continue Statement
Section 6.8. The Assignment Anywhere Side Effect
Section 6.9. Programming Exercises
Section 6.10. Answers to Chapter Questions
Chapter 7. The Programming Process
Section 7.1. Setting Up Your Work Area
Section 7.2. The Specification
Section 7.3. Code Design
Section 7.4. The Prototype
Section 7.5. The Makefile
Section 7.6. Testing
Section 7.7. Debugging
Section 7.8. Maintenance
Section 7.9. Revisions
Section 7.10. Electronic Archaeology
Section 7.11. Mark Up the Program
Section 7.12. Use the Debugger
Section 7.13. Use the Text Editor as a Browser
Section 7.14. Add Comments
Section 7.15. Programming Exercises
Part II: Simple Programming
Chapter 8. More Control Statements
Section 8.1. for Statement
Section 8.2. switch Statement
Section 8.3. switch, break, and continue
Section 8.4. Programming Exercises
Section 8.5. Answers to Chapter Questions
Chapter 9. Variable Scope and Functions
Section 9.1. Scope and Storage Class
Section 9.2. Namespaces
Section 9.3. Functions
Section 9.4. Summary of Parameter Types
Section 9.5. Recursion
Section 9.6. Structured Programming Basics
Section 9.7. Real-World Programming
Section 9.8. Programming Exercises
Section 9.9. Answers to Chapter Questions
Chapter 10. The C++ Preprocessor
Section 10.1. #define Statement
Section 10.2. Conditional Compilation
Section 10.3. #include Files
Section 10.4. Parameterized Macros
Section 10.5. Advanced Features
Section 10.6. Summary
Section 10.7. Programming Exercises
Section 10.8. Answers to Chapter Questions
Chapter 11. Bit Operations
Section 11.1. Bit Operators
Section 11.2. The AND Operator (&)
Section 11.3. Bitwise OR (|)
Section 11.4. The Bitwise Exclusive OR (^)
Section 11.5. The Ones Complement Operator (NOT) (~)
Section 11.6. The Left and Right Shift Operators (<<, >>)
Section 11.7. Setting, Clearing, and Testing Bits
Section 11.8. Bitmapped Graphics
Section 11.9. Programming Exercises
Section 11.10. Answers to Chapter Questions
Part III: Advanced Types and Classes
Chapter 12. Advanced Types
Section 12.1. Structures
Section 12.2. Unions
Section 12.3. typedef
Section 12.4. enum Type
Section 12.5. Bit Members or Packed Structures
Section 12.6. Arrays of Structures
Section 12.7. Programming Exercises
Section 12.8. Answers to Chapter Questions
Chapter 13. Simple Classes
Section 13.1. Stacks
Section 13.2. Improved Stack
Section 13.3. Using a Class
Section 13.4. Introduction to Constructors and Destructors
Section 13.5. Automatically Generated Member Functions
Section 13.6. Shortcuts
Section 13.7. Style
Section 13.8. Structures Versus Classes
Section 13.9. Programming Exercises
Chapter 14. More on Classes
Section 14.1. Friends
Section 14.2. Constant Functions
Section 14.3. Constant Members
Section 14.4. Static Member Variables
Section 14.5. Static Member Functions
Section 14.6. The Meaning of static
Section 14.7. Programming Exercises
Chapter 15. Simple Pointers
Section 15.1. const Pointers
Section 15.2. Pointers and Printing
Section 15.3. Pointers and Arrays
Section 15.4. The reinterpret_cast
Section 15.5. Pointers and Structures
Section 15.6. Command-Line Arguments
Section 15.7. Programming Exercises
Section 15.8. Answers to Chapter Questions
Part IV: Advanced Programming Concepts
Chapter 16. File Input/Output
Section 16.1. C++ File I/O
Section 16.2. Conversion Routines
Section 16.3. Binary and ASCII Files
Section 16.4. The End-of-Line Puzzle
Section 16.5. Binary I/O
Section 16.6. Buffering Problems
Section 16.7. Unbuffered I/O
Section 16.8. Designing File Formats
Section 16.9. C-Style I/O Routines
Section 16.10. C-Style Conversion Routines
Section 16.11. C-Style Binary I/O
Section 16.12. C- Versus C++- Style I/O
Section 16.13. Programming Exercises
Section 16.14. Answers to Chapter Questions
Chapter 17. Debugging and Optimization
Section 17.1. Code Reviews
Section 17.2. Serial Debugging
Section 17.3. Going Through the Output
Section 17.4. Interactive Debuggers
Section 17.5. Debugging a Binary Search
Section 17.6. Interactive Debugging Tips and Tricks
Section 17.7. Runtime Errors
Section 17.8. Optimization
Section 17.9. How to Optimize
Section 17.10. Case Study: Inline Functions Versus Normal Functions
Section 17.11. Case Study: Optimizing a Color-Rendering Algorithm
Section 17.12. Programming Exercises
Section 17.13. Answers to Chapter Questions
Chapter 18. Operator Overloading
Section 18.1. Creating a Simple Fixed-Point Class
Section 18.2. Operator Functions
Section 18.3. Operator Member Functions
Section 18.4. Warts
Section 18.5. Full Definition of the Fixed-Point Class
Section 18.6. Programming Exercises
Section 18.7. Answers to Chapter Questions
Chapter 19. Floating Point
Section 19.1. Floating-Point Format
Section 19.2. Floating Addition/Subtraction
Section 19.3. Multiplication and Division
Section 19.4. Overflow and Underflow
Section 19.5. Roundoff Error
Section 19.6. Accuracy
Section 19.7. Minimizing Roundoff Error
Section 19.8. Determining Accuracy
Section 19.9. Precision and Speed
Section 19.10. Power Series
Section 19.11. Programming Exercises
Chapter 20. Advanced Pointers
Section 20.1. Pointers, Structures, and Classes
Section 20.2. delete Operator
Section 20.3. Linked Lists
Section 20.4. Ordered Linked Lists
Section 20.5. Doubly Linked Lists
Section 20.6. Trees
Section 20.7. Printing a Tree
Section 20.8. The Rest of the Program
Section 20.9. Data Structures for a Chess Program
Section 20.10. Programming Exercises
Section 20.11. Answers to Chapter Questions
Chapter 21. Advanced Classes
Section 21.1. Derived Classes
Section 21.2. Virtual Functions
Section 21.3. Virtual Classes
Section 21.4. Function Hiding in Derived Classes
Section 21.5. Constructors and Destructors in Derived Classes
Section 21.6. The dynamic_cast Operator
Section 21.7. Summary
Section 21.8. Programming Exercises
Section 21.9. Answers to Chapter Questions
Part V: Other Language Features
Chapter 22. Exceptions
Section 22.1. Adding Exceptions to the Stack Class
Section 22.2. Exceptions Versus assert
Section 22.3. Programming Exercises
Chapter 23. Modular Programming
Section 23.1. Modules
Section 23.2. Public and Private
Section 23.3. The extern Storage Class
Section 23.4. Headers
Section 23.5. The Body of the Module
Section 23.6. A Program to Use Infinite Arrays
Section 23.7. The Makefile for Multiple Files
Section 23.8. Using the Infinite Array
Section 23.9. Dividing a Task into Modules
Section 23.10. Module Design Guidelines
Section 23.11. Programming Exercises
Chapter 24. Templates
Section 24.1. What Is a Template?
Section 24.2. Templates: The Hard Way
Section 24.3. Templates: The C++ Way
Section 24.4. Function Specialization
Section 24.5. Class Templates
Section 24.6. Class Specialization
Section 24.7. Implementation Details
Section 24.8. Advanced Features
Section 24.9. Summary
Section 24.10. Programming Exercises
Chapter 25. Standard Template Library
Section 25.1. STL Basics
Section 25.2. Class List—A Set of Students
Section 25.3. Creating a Waiting List with the STL List
Section 25.4. Storing Grades in a STL Map
Section 25.5. Putting It All Together
Section 25.6. Practical Considerations When Using the STL
Section 25.7. Getting More Information
Section 25.8. Exercises
Chapter 26. Program Design
Section 26.1. Design Goals
Section 26.2. Design Factors
Section 26.3. Design Principles
Section 26.4. Coding
Section 26.5. Objects
Section 26.6. Real-World Design Techniques
Section 26.7. Conclusion
Chapter 27. Putting It All Together
Section 27.1. Requirements
Section 27.2. Code Design
Section 27.3. Coding
Section 27.4. Functional Description
Section 27.5. Testing
Section 27.6. Revisions
Section 27.7. A Final Warning
Section 27.8. Program Files
Section 27.9. Programming Exercises
Chapter 28. From C to C++
Section 28.1. K&R-Style Functions
Section 28.2. struct
Section 28.3. malloc and free
Section 28.4. Turning Structures into Classes
Section 28.5. setjmp and longjmp
Section 28.6. Mixing C and C++ Code
Section 28.7. Summary
Section 28.8. Programming Exercise
Chapter 29. C++'s Dustier Corners
Section 29.1. do/while
Section 29.2. goto
Section 29.3. The ?: Construct
Section 29.4. The Comma Operator
Section 29.5. Overloading the ( ) Operator
Section 29.6. Pointers to Members
Section 29.7. The asm Statement
Section 29.8. The mutable Qualifier
Section 29.9. Run Time Type Identification
Section 29.10. Trigraphs
Section 29.11. Answers to Chapter Questions
Chapter 30. Programming Adages
Section 30.1. General
Section 30.2. Design
Section 30.3. Declarations
Section 30.4. switch Statement
Section 30.5. Preprocessor
Section 30.6. Style
Section 30.7. Compiling
Section 30.8. The Ten Commandments for C++ Programmers
Section 30.9. Final Note
Section 30.10. Answers to Chapter Questions
Part VI: Appendixes
Appendix A. ASCII Table
Appendix B. Ranges
Appendix C. Operator Precedence Rules
Section C.1. Standard Rules
Section C.2. Practical Subset of the Operator Precedence Rules
Appendix D. Computing Sine Using a Power Series
Appendix E. Resources
Section E.1. Compilers
Section E.2. Standard Template Library
Section E.3. Standards
Section E.4. Programming Tools
Colophon
Index
I l
@
ve RuBoard