| Introduction | 1 |
1 | The Big Picture | 9 |
| Why Do We Need Object-Oriented Programming? | 10 |
| Characteristics of Object-Oriented Languages | 16 |
| C++ and C | 22 |
| Laying the Groundwork | 23 |
| The Unified Modeling Language (UML) | 23 |
| Summary | 25 |
| Questions | 25 |
2 | C++ Programming Basics | 29 |
| Getting Started | 30 |
| Basic Program Construction | 30 |
| Output Using cout | 33 |
| Directives | 35 |
| Comments | 36 |
| Integer Variables | 38 |
| Character Variables | 42 |
| Input with cin | 45 |
| Floating Point Types | 48 |
| Type bool | 51 |
| The setw Manipulator | 52 |
| Variable Type Summary | 54 |
| Type Conversion | 56 |
| Arithmetic Operators | 60 |
| Library Functions | 65 |
| Summary | 68 |
| Questions | 69 |
| Exercises | 71 |
3 | Loops and Decisions | 75 |
| Relational Operators | 76 |
| Loops | 78 |
| Decisions | 93 |
| Logical Operators | 114 |
| Precedence Summary | 118 |
| Other Control Statements | 118 |
| Summary | 123 |
| Questions | 124 |
| Exercises | 126 |
4 | Structures | 131 |
| Structures | 132 |
| Enumerations | 148 |
| Summary | 156 |
| Questions | 156 |
| Exercises | 158 |
5 | Functions | 161 |
| Simple Functions | 162 |
| Passing Arguments to Functions | 167 |
| Returning Values from Functions | 176 |
| Reference Arguments | 182 |
| Overloaded Functions | 188 |
| Recursion | 193 |
| Inline Functions | 195 |
| Default Arguments | 197 |
| Scope and Storage Class | 199 |
| Returning by Reference | 206 |
| const Function Arguments | 208 |
| Summary | 209 |
| Questions | 210 |
| Exercises | 212 |
6 | Objects and Classes | 215 |
| A Simple Class | 216 |
| C++ Objects as Physical Objects | 223 |
| C++ Objects as Data Types | 226 |
| Constructors | 227 |
| Objects as Function Arguments | 233 |
| The Default Copy Constructor | 238 |
| Returning Objects from Functions | 240 |
| A Card-Game Example | 243 |
| Structures and Classes | 247 |
| Classes, Objects, and Memory | 247 |
| Static Class Data | 249 |
| const and Classes | 252 |
| What Does It All Mean? | 256 |
| Summary | 257 |
| Questions | 257 |
| Exercises | 259 |
7 | Arrays and Strings | 263 |
| Array Fundamentals | 264 |
| Arrays as Class Member Data | 279 |
| Arrays of Objects | 283 |
| C-Strings | 290 |
| The Standard C++ string Class | 302 |
| Summary | 310 |
| Questions | 311 |
| Exercises | 313 |
8 | Operator Overloading | 319 |
| Overloading Unary Operators | 320 |
| Overloading Binary Operators | 328 |
| Data Conversion | 344 |
| UML Class Diagrams | 357 |
| Pitfalls of Operator Overloading and Conversion | 358 |
| Keywords explicit and mutable | 360 |
| Summary | 364 |
| Questions | 364 |
| Exercises | 367 |
9 | Inheritance | 371 |
| Derived Class and Base Class | 373 |
| Derived Class Constructors | 380 |
| Overriding Member Functions | 382 |
| Which Function Is Used? | 383 |
| Inheritance in the English Distance Class | 384 |
| Class Hierarchies | 388 |
| Inheritance and Graphics Shapes | 393 |
| Public and Private Inheritance | 396 |
| Levels of Inheritance | 399 |
| Multiple Inheritance | 403 |
| private Derivation in Empmult | 409 |
| Ambiguity in Multiple Inheritance | 413 |
| Aggregation: Classes Within Classes | 414 |
| Inheritance and Program Development | 420 |
| Summary | 421 |
| Questions | 422 |
| Exercises | 424 |
10 | Pointers | 429 |
| Addresses and Pointers | 430 |
| The Address-of Operator & | 431 |
| Pointers and Arrays | 440 |
| Pointers and Functions | 443 |
| Pointers and C-Type Strings | 452 |
| Memory Management: new and delete | 458 |
| Pointers to Objects | 464 |
| A Linked List Example | 469 |
| Pointers to Pointers | 474 |
| A Parsing Example | 479 |
| Simulation: A Horse Race | 484 |
| UML State Diagrams | 490 |
| Debugging Pointers | 492 |
| Summary | 493 |
| Questions | 494 |
| Exercises | 497 |
11 | Virtual Functions | 503 |
| Virtual Functions | 504 |
| Friend Functions | 520 |
| Static Functions | 529 |
| Assignment and Copy Initialization | 532 |
| The this Pointer | 547 |
| Dynamic Type Information | 553 |
| Summary | 557 |
| Questions | 558 |
| Exercises | 561 |
12 | Streams and Files | 567 |
| Stream Classes | 568 |
| Stream Errors | 577 |
| Disk File I/O with Streams | 583 |
| File Pointers | 597 |
| Error Handling in File I/O | 601 |
| File I/O with Member Functions | 604 |
| Overloading the Extraction and Insertion Operators | 616 |
| Memory as a Stream Object | 620 |
| Command-Line Arguments | 622 |
| Printer Output | 624 |
| Summary | 626 |
| Questions | 627 |
| Exercises | 628 |
13 | Multifile Programs | 633 |
| Reasons for Multifile Programs | 634 |
| Creating a Multifile Program | 637 |
| Inter-File Communication | 638 |
| A Very Long Number Class | 651 |
| A High-Rise Elevator Simulation | 658 |
| Summary | 676 |
| Questions | 677 |
| Projects | 679 |
14 | Templates and Exceptions | 681 |
| Function Templates | 682 |
| Class Templates | 690 |
| Exceptions | 703 |
| Summary | 720 |
| Questions | 720 |
| Exercises | 722 |
15 | The Standard Template Library | 725 |
| Introduction to the STL | 726 |
| Algorithms | 735 |
| Sequence Containers | 743 |
| Iterators | 751 |
| Specialized Iterators | 763 |
| Associative Containers | 771 |
| Storing User-Defined Objects | 778 |
| Function Objects | 786 |
| Summary | 794 |
| Questions | 795 |
| Exercises | 797 |
16 | Object-Oriented Software Development | 801 |
| Evolution of the Software Development Processes | 802 |
| Use Case Modeling | 805 |
| The Programming Problem | 809 |
| The Elaboration Phase for the Landlord Program | 812 |
| From Use Cases to Classes | 816 |
| Writing the Code | 824 |
| Interacting with the Program | 841 |
| Final Thoughts | 843 |
| Summary | 844 |
| Questions | 844 |
| Projects | 846 |
A | ASCII Chart | 849 |
B | C++ Precedence Table and Keywords | 859 |
| Precedence Table | 860 |
| Keywords | 860 |
C | Microsoft Visual C++ | 863 |
| Screen Elements | 864 |
| Single-File Programs | 864 |
| Multifile Programs | 866 |
| Building Console Graphics Lite Programs | 868 |
| Debugging | 868 |
D | Borland C++Builder | 871 |
| Running the Example Programs in C++Builder | 872 |
| Cleaning Up the Screen | 873 |
| Creating a New Project | 873 |
| Naming and Saving a Project | 874 |
| Starting with Existing Files | 875 |
| Compiling, Linking, and Executing | 875 |
| Adding a Header File to Your Project | 876 |
| Projects with Multiple Source Files | 877 |
| Console Graphics Lite Programs | 878 |
| Debugging | 878 |
E | Console Graphics Lite | 881 |
| Using the Console Graphics Lite Routines | 882 |
| The Console Graphics Lite Functions | 883 |
| Implementations of the Console Graphics Lite Functions | 884 |
| Source Code Listings | 885 |
F | STL Algorithms and Member Functions | 895 |
| Algorithms | 896 |
| Member Functions | 907 |
| Iterators | 909 |
G | Answers to Questions and Exercises | 913 |
Chapter 1914 |
Chapter 2914 |
Chapter 3917 |
Chapter 4921 |
Chapter 5924 |
Chapter 6928 |
Chapter 7932 |
Chapter 8937 |
Chapter 9943 |
Chapter 10949 |
Chapter 11954 |
Chapter 12960 |
Chapter 13963 |
Chapter 14964 |
Chapter 15969 |
Chapter 16974 |
H | Bibliography | 977 |
| Advanced C++ | 978 |
| Defining Documents | 978 |
| The Unified Modeling Language | 978 |
| The History of C++ | 979 |
| Other Topics | 979 |
| Index | 981 |