| 1 | Introduction to Computers, the Internet and World Wide Web | 1 |
| | | |
| 1.1 | Introduction | 2 |
| 1.2 | What Is a Computer? | 3 |
| 1.3 | Computer Organization | 4 |
| 1.4 | Early Operating Systems | 5 |
| 1.5 | Personal, Distributed and Client/Server Computing | 5 |
| 1.6 | The Internet and the World Wide Web | 6 |
| 1.7 | Machine Languages, Assembly Languages and High-Level Languages | 6 |
| 1.8 | History of C and C++ | 8 |
| 1.9 | C++ Standard Library | 8 |
| 1.1 | History of Java | 9 |
| 1.11 | FORTRAN, COBOL, Pascal and Ada | 10 |
| 1.12 | Basic, Visual Basic, Visual C++, C# and .NET | 11 |
| 1.13 | Key Software Trend: Object Technology | 11 |
| 1.14 | Typical C++ Development Environment | 12 |
| 1.15 | Notes About C++ and Small C++ How to Program, 5/e | 15 |
| 1.16 | Test-Driving a C++ Application | 16 |
| 1.17 | Introduction to Object Technology and the UML | 22 |
| 1.18 | Wrap-Up | 27 |
| 1.19 | Web Resources | 28 |
| 2 | Introduction to C++ Programming | 36 |
| 2.1 | Introduction | 37 |
| 2.2 | First Program in C++: Printing a Line of Text | 37 |
| 2.3 | Modifying Our First C++ Program | 41 |
| 2.4 | Another C++ Program: Adding Integers | 42 |
| 2.5 | Memory Concepts | 46 |
| 2.6 | Arithmetic | 48 |
| 2.7 | Decision Making: Equality and Relational Operators | 51 |
| 2.8 | Wrap-Up | 56 |
| 3 | Introduction to Classes and Objects | 65 |
| 3.1 | Introduction | 66 |
| 3.2 | Classes, Objects, Member Functions and Data Members | 66 |
| 3.3 | Overview of the Chapter Examples | 68 |
| 3.4 | Defining a Class with a Member Function | 68 |
| 3.5 | Defining a Member Function with a Parameter | 72 |
| 3.6 | Data Members, set Functions and get Functions | 75 |
| 3.7 | Initializing Objects with Constructors | 82 |
| 3.8 | Placing a Class in a Separate File for Reusability | 86 |
| 3.9 | Separating Interface from Implementation | 90 |
| 3.1 | Validating Data with set Functions | 96 |
| 3.11 | Wrap-Up | 101 |
| 4 | Control Statements: Part 1 | 108 |
| 4.1 | Introduction | 109 |
| 4.2 | Algorithms | 109 |
| 4.3 | Pseudocode | 110 |
| 4.4 | Control Structures | 111 |
| 4.5 | if Selection Statement | 115 |
| 4.6 | if else Double-Selection Statement | 116 |
| 4.7 | while Repetition Statement | 121 |
| 4.8 | Formulating Algorithms: Counter-Controlled Repetition | 123 |
| 4.9 | Formulating Algorithms: Sentinel-Controlled Repetition | 129 |
| 4.1 | Formulating Algorithms: Nested Control Statements | 140 |
| 4.11 | Assignment Operators | 145 |
| 4.12 | Increment and Decrement Operators | 145 |
| 4.13 | Wrap-Up | 149 |
| 5 | Control Statements: Part 2 | 164 |
| 5.1 | Introduction | 165 |
| 5.2 | Essentials of Counter-Controlled Repetition | 165 |
| 5.3 | for Repetition Statement | 167 |
| 5.4 | Examples Using the for Statement | 172 |
| 5.5 | do while Repetition Statement | 176 |
| 5.6 | switch Multiple-Selection Statement | 178 |
| 5.7 | break and continue Statements | 188 |
| 5.8 | Logical Operators | 190 |
| 5.9 | Confusing Equality (==) and Assignment (=) Operators | 195 |
| 5.1 | Structured Programming Summary | 196 |
| 5.11 | Wrap-Up | 201 |
| 6 | Functions and an Introduction to Recursion | 211 |
| 6.1 | Introduction | 212 |
| 6.2 | Program Components in C++ | 213 |
| 6.3 | Math Library Functions | 214 |
| 6.4 | Function Definitions with Multiple Parameters | 216 |
| 6.5 | Function Prototypes and Argument Coercion | 221 |
| 6.6 | C++ Standard Library Header Files | 223 |
| 6.7 | Case Study: Random Number Generation | 225 |
| 6.8 | Case Study: Game of Chance and Introducing enum | 231 |
| 6.9 | Storage Classes | 235 |
| 6.1 | Scope Rules | 238 |
| 6.11 | Function Call Stack and Activation Records | 241 |
| 6.12 | Functions with Empty Parameter Lists | 245 |
| 6.13 | Inline Functions | 246 |
| 6.14 | References and Reference Parameters | 248 |
| 6.15 | Default Arguments | 253 |
| 6.16 | Unary Scope Resolution Operator | 255 |
| 6.17 | Function Overloading | 256 |
| 6.18 | Function Templates | 259 |
| 6.19 | Recursion | 261 |
| 6.2 | Example Using Recursion: Fibonacci Series | 265 |
| 6.21 | Recursion vs. Iteration | 268 |
| 6.22 | Wrap-Up | 271 |
| 7 | Arrays and Vectors | 292 |
| 7.1 | Introduction | 293 |
| 7.2 | Arrays | 294 |
| 7.3 | Declaring Arrays | 295 |
| 7.4 | Examples Using Arrays | 296 |
| 7.5 | Passing Arrays to Functions | 312 |
| 7.6 | Case Study: Class GradeBook Using an Array to Store Grades | 317 |
| 7.7 | Searching Arrays with Linear Search | 324 |
| 7.8 | Sorting Arrays with Insertion Sort | 325 |
| 7.9 | Multidimensional Arrays | 328 |
| 7.1 | Case Study: Class GradeBook Using a Two-Dimensional Array | 331 |
| 7.11 | Introduction to C++ Standard Library Class Template vector | 338 |
| 7.12 | Wrap-Up | 343 |
| 8 | Pointers and Pointer-Based Strings | 360 |
| 8.1 | Introduction | 361 |
| 8.2 | Pointer Variable Declarations and Initialization | 362 |
| 8.3 | Pointer Operators | 363 |
| 8.4 | Passing Arguments to Functions by Reference with Pointers | 366 |
| 8.5 | Using const with Pointers | 370 |
| 8.6 | Selection Sort Using Pass-by-Reference | 377 |
| 8.7 | sizeof Operators | 380 |
| 8.8 | Pointer Expressions and Pointer Arithmetic | 383 |
| 8.9 | Relationship Between Pointers and Arrays | 386 |
| 8.1 | Arrays of Pointers | 390 |
| 8.11 | Case Study: Card Shuffling and Dealing Simulation | 391 |
| 8.12 | Function Pointers | 397 |
| 8.13 | Introduction to Pointer-Based String Processing | 402 |
| 8.14 | Wrap-Up | 413 |
| 9 | Classes: A Deeper Look, Part 1 | 439 |
| 9.1 | Introduction | 440 |
| 9.2 | Time Class Case Study | 441 |
| 9.3 | Class Scope and Accessing Class Members | 446 |
| 9.4 | Separating Interface from Implementation | 448 |
| 9.5 | Access Functions and Utility Functions | 450 |
| 9.6 | Time Class Case Study: Constructors with Default Arguments | 452 |
| 9.7 | Destructors | 458 |
| 9.8 | When Constructors and Destructors Are Called | 459 |
| 9.9 | Time Class Case Study: Subtle Trap—Returning a Reference to a private Data Member | 462 |
| 9.1 | Default Memberwise Assignment | 465 |
| 9.11 | Software Reusability | 467 |
| 9.12 | Wrap-Up | 468 |
| 10 | Classes: A Deeper Look, Part 2 | 474 |
| 10.1 | Introduction | 475 |
| 10.2 | const (Constant) Objects and const Member Functions | 475 |
| 10.3 | Composition: Objects as Members of Classes | 485 |
| 10.4 | friend Functions and friend Classes | 492 |
| 10.5 | Using the this Pointer | 496 |
| 10.6 | Dynamic Memory Management with Operators new and delete | 501 |
| 10.7 | static Class Members | 503 |
| 10.8 | Data Abstraction and Information Hiding | 509 |
| 10.9 | Container Classes and Iterators | 512 |
| 10.1 | Proxy Classes | 513 |
| 10.11 | Wrap-Up | 516 |
| 11 | Operator Overloading; String and Array Objects | 522 |
| 11.1 | Introduction | 523 |
| 11.2 | Fundamentals of Operator Overloading | 524 |
| 11.3 | Restrictions on Operator Overloading | 525 |
| 11.4 | Operator Functions as Class Members vs. Global Functions | 527 |
| 11.5 | Overloading Stream Insertion and Stream Extraction Operators | 528 |
| 11.6 | Overloading Unary Operators | 532 |
| 11.7 | Overloading Binary Operators | 532 |
| 11.8 | Case Study: Array Class | 533 |
| 11.9 | Converting between Types | 545 |
| 11.1 | Case Study: String Class | 546 |
| 11.11 | Overloading ++ and -- | 558 |
| 11.12 | Case Study: A Date Class | 560 |
| 11.13 | Standard Library Class string | 564 |
| 11.14 | explicit Constructors | 568 |
| 11.15 | Wrap-Up | 572 |
| 12 | Object-Oriented Programming: Inheritance | 584 |
| 12.1 | Introduction | 585 |
| 12.2 | Base Classes and Derived Classes | 586 |
| 12.3 | protected Members | 589 |
| 12.4 | Relationship between Base Classes and Derived Classes | 589 |
| 12.5 | Constructors and Destructors in Derived Classes | 621 |
| 12.6 | public, protected and private Inheritance | 629 |
| 12.7 | Software Engineering with Inheritance | 629 |
| 12.8 | Wrap-Up | 631 |
| 13 | Object-Oriented Programming: Polymorphism | 637 |
| 13.1 | Introduction | 638 |
| 13.2 | Polymorphism Examples | 640 |
| 13.3 | Relationships Among Objects in an Inheritance Hierarchy | 641 |
| 13.4 | Type Fields and switch Statements | 658 |
| 13.5 | Abstract Classes and Pure virtual Functions | 659 |
| 13.6 | Case Study: Payroll System Using Polymorphism | 661 |
| 13.7 | (Optional) Polymorphism, Virtual Function and Dynamic Binding “Under the Hood” | 679 |
| 13.8 | Case Study: Payroll System Using Polymorphism and Run-Time Type Information with Downcasting, dynamic_cast, typeid and type_info | 683 |
| 13.9 | Virtual Destructors | 686 |
| 13.1 | Wrap-Up | 687 |
| A | Operator Precedence and Associativity Chart | 692 |
| A.1 | Operator Precedence | 692 |
| B | ASCII Character Set | 695 |
| C | Fundamental Types | 696 |
| D | Number Systems | 698 |
| D.1 | Introduction | 699 |
| D.2 | Abbreviating Binary Numbers as Octal and Hexadecimal Numbers | 702 |
| D.3 | Converting Octal and Hexadecimal Numbers to Binary Numbers | 703 |
| D.4 | Converting from Binary, Octal or Hexadecimal to Decimal | 703 |
| D.5 | Converting from Decimal to Binary, Octal or Hexadecimal | 704 |
| D.6 | Negative Binary Numbers: Two’s Complement Notation | 706 |
| E | C++ Internet and Web Resources | 711 |
| E.1 | Resources | 711 |
| E.2 | Tutorials | 713 |
| E.3 | FAQs | 713 |
| E.4 | Visual C++ | 713 |
| E.5 | Newsgroups | 714 |
| E.6 | Compilers and Development Tools | 714 |
| F | Using the Visual Studio .NET Debugger | 715 |
| F.1 | Introduction | 716 |
| F.2 | Breakpoints and the Continue Command | 716 |
| F.3 | The Locals and Watch Windows | 722 |
| F.4 | Controlling Execution Using the Step Into, Step Over, Step Out and Continue Commands | 725 |
| F.5 | The Autos Window | 728 |
| F.6 | Wrap-Up | 729 |
| G | Using the GNU C++ Debugger | 732 |
| G.1 | Introduction | 733 |
| G.2 | Breakpoints and the run, stop, continue and print Commands | 733 |
| G.3 | The print and set Commands | 740 |
| G.4 | Controlling Execution Using the step, finish and next Commands | 742 |
| G.5 | The watch Command | 744 |
| G.6 | Wrap-Up | 747 |
| Bibliography | 750 |
| Index | | 752 |