Chapter 1 Introduction to Computers and C++\t1
1.1 Introduction\t2
1.2 Computers and the Internet in Industry and Research\t2
1.3 Hardware and Software\t4
1.4 Data Hierarchy\t6
1.5 Machine Languages, Assembly Languages and High-Level Languages\t7
1.6 C++\t8
1.7 Programming Languages\t9
1.8 Introduction to Object Technology\t10
1.9 Typical C++ Development Environment\t13
1.10 Test-Driving a C++ Application\t15
1.11 Operating Systems\t20
1.12 The Internet and World Wide Web\t22
1.13 Some Key Software Development Terminology\t23
1.14 C++11 and the Open Source Boost Libraries\t25
1.15 Keeping Up to Date with Information Technologies\t25
1.16 Web Resources\t26
Chapter 2 Introduction to C++ Programming; Input/Output and Operators\t31
2.1 Introduction\t31
2.2 First Program in C++: Printing a Line of Text\t32
2.3 Modifying Our First C++ Program\t35
2.4 Another C++ Program: Adding Integers\t36
2.5 Memory Concepts\t39
2.6 Arithmetic\t40
2.7 Decision Making: Equality and Relational Operators\t43
2.8 Wrap-Up\t47
Chapter 3 Introduction to Classes, Objects and Strings\t55
3.1 Introduction\t55
3.2 Defining a Class with a Member Function\t56
3.3 Defining a Member Function with a Parameter\t58
3.4 Data Members, set Member Functions and get Member Functions\t61
3.5 Initializing Objects with Constructors\t66
3.6 Placing a Class in a Separate File for Reusability\t69
3.7 Separating Interface from Implementation\t72
3.8 Validating Data with set Functions\t76
3.9 Wrap-Up\t80
Chapter 4 Control Statements: Part 1; Assignment, ++ and - - Operators\t87
4.1 Introduction\t87
4.2 Algorithms\t88
4.3 Pseudocode\t88
4.4 Control Structures\t89
4.5 if Selection Statement\t92
4.6 if…else Double-Selection Statement\t93
4.7 while Repetition Statement\t97
4.8 Formulating Algorithms: Counter-Controlled Repetition\t98
4.9 Formulating Algorithms: Sentinel-Controlled Repetition\t103
4.10 Formulating Algorithms: Nested Control Statements\t111
4.11 Assignment Operators\t116
4.12 Increment and Decrement Operators\t116
4.13 Wrap-Up\t118
Chapter 5 Control Statements: Part 2; Logical Operators\t131
5.1 Introduction\t131
5.2 Essentials of Counter-Controlled Repetition\t132
5.3 for Repetition Statement\t133
5.4 Examples Using the for Statement\t136
5.5 do…while Repetition Statement\t140
5.6 switch Multiple-Selection Statement\t141
5.7 break and continue Statements\t148
5.8 Logical Operators\t150
5.9 Confusing the Equality (==) and Assignment (=) Operators\t153
5.10 Structured Programming Summary\t154
5.11 Wrap-Up\t158
Chapter 6 Functions and an Introduction to Recursion\t167
6.1 Introduction\t168
6.2 Program Components in C++\t168
6.3 Math Library Functions\t169
6.4 Function Definitions with Multiple Parameters\t170
6.5 Function Prototypes and Argument Coercion\t174
6.6 C++ Standard Library Headers\t176
6.7 Case Study: Random Number Generation\t177
6.8 Case Study: Game of Chance; Introducing enum\t182
6.9 C++11 Random Numbers\t185
6.10 Storage Classes and Storage Duration\t186
6.11 Scope Rules\t189
6.12 Function Call Stack and Activation Records\t191
6.13 Functions with Empty Parameter Lists\t194
6.14 Inline Functions\t195
6.15 References and Reference Parameters\t196
6.16 Default Arguments\t198
6.17 Unary Scope Resolution Operator\t200
6.18 Function Overloading\t200
6.19 Function Templates\t203
6.20 Recursion\t205
6.21 Example Using Recursion: Fibonacci Series\t208
6.22 Recursion vs. Iteration\t210
6.23 Wrap-Up\t213
Chapter 7 Class Templates array and vector; Catching Exceptions\t232
7.1 Introduction\t233
7.2 arrays\t233
7.3 Declaring arrays\t234
7.4 Examples Using arrays\t235
7.5 Range-Based for Statement\t244
7.6 Case Study: Class GradeBook Using an array to Store Grades\t246
7.7 Sorting and Searching arrays\t251
7.8 Multidimensional arrays\t252
7.9 Case Study: Class GradeBook Using a Two-Dimensional array\t255
7.10 Introduction to C++ Standard Library Class Template vector\t260
7.11 Wrap-Up\t264
Chapter 8 Pointers\t279
8.1 Introduction\t280
8.2 Pointer Variable Declarations and Initialization\t280
8.3 Pointer Operators\t281
8.4 Pass-by-Reference with Pointers\t283
8.5 Built-In Arrays\t287
8.6 Using const with Pointers\t289
8.7 sizeof Operator\t292
8.8 Pointer Expressions and Pointer Arithmetic\t294
8.9 Relationship Between Pointers and Built-In Arrays\t296
8.10 Pointer-Based Strings\t299
8.11 Wrap-Up\t301
Chapter 9 Classes: A Deeper Look; Throwing Exceptions\t316
9.1 Introduction\t317
9.2 Time Class Case Study\t317
9.3 Class Scope and Accessing Class Members\t323
9.4 Access Functions and Utility Functions\t324
9.5 Time Class Case Study: Constructors with Default Arguments\t324
9.6 Destructors\t328
9.7 When Constructors and Destructors Are Called\t329
9.8 Time Class Case Study: A Subtle Trap― Returning a Reference or a Pointer to a private Data Member\t331
9.9 Default Memberwise Assignment\t334
9.10 const Objects and const Member Functions\t335
9.11 Composition: Objects as Members of Classes\t337
9.12 friend Functions and friend Classes\t341
9.13 Using the this Pointer\t343
9.14 static Class Members\t347
9.15 Wrap-Up\t351
Chapter 10 Operator Overloading; Class string\t361
10.1 Introduction\t362
10.2 Using the Overloaded Operators of Standard Library Class string\t362
10.3 Fundamentals of Operator Overloading\t365
10.4 Overloading Binary Operators\t366
10.5 Overloading the Binary Stream Insertion and Stream Extraction Operators\t367
10.6 Overloading Unary Operators\t370
10.7 Overloading the Unary Prefix and Postfix ++ and -- Operators\t370
10.8 Case Study: A Date Class\t371
10.9 Dynamic Memory Management\t375
10.10 Case Study: Array Class\t377
10.11 Operators as Member vs. Non-Member Functions\t387
10.12 Converting Between Types\t388
10.13 explicit Constructors and Conversion Operators\t389
10.14 Overloading the Function Call Operator ()\t391
10.15 Wrap-Up\t392
Chapter 11 Object-Oriented Programming: Inheritance\t402
11.1 Introduction\t402
11.2 Base Classes and Derived Classes\t403
11.3 Relationship between Base and Derived Classes\t405
11.4 Constructors and Destructors in Derived Classes\t422
11.5 public, protected and private Inheritance\t424
11.6 Software Engineering with Inheritance\t425
11.7 Wrap-Up\t425
Chapter 12 Object-Oriented Programming: Polymorphism\t431
12.1 Introduction\t432
12.2 Introduction to Polymorphism: Polymorphic Video Game\t432
12.3 Relationships Among Objects in an Inheritance Hierarchy\t433
12.4 Type Fields and switch Statements\t443
12.5 Abstract Classes and Pure virtual Functions\t444
12.6 Case Study: Payroll System Using Polymorphism\t445
12.7 (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”\t456
12.8 Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info\t459
12.9 Wrap-Up\t462
Chapter 13 Stream Input/Output: A Deeper Look\t468
13.1 Introduction\t469
13.2 Streams\t469
13.3 Stream Output\t472
13.4 Stream Input\t473
13.5 Unformatted I/O Using read, write and gcount\t476
13.6 Introduction to Stream Manipulators\t477
13.7 Stream Format States and Stream Manipulators\t481
13.8 Stream Error States\t488
13.9 Tying an Output Stream to an Input Stream\t490
13.10 Wrap-Up\t490
Chapter 14 File Processing\t499
14.1 Introduction\t499
14.2 Files and Streams\t500
14.3 Creating a Sequential File\t500
14.4 Reading Data from a Sequential File\t504
14.5 Updating Sequential Files\t508
14.6 Random-Access Files\t508
14.7 Creating a Random-Access File\t509
14.8 Writing Data Randomly to a Random-Access File\t513
14.9 Reading from a Random-Access File Sequentially\t514
14.10 Case Study: A Transaction-Processing Program\t516
14.11 Object Serialization\t521
14.12 Wrap-Up\t521
Chapter 15 Standard Library Containers and Iterators\t530
15.1 Introduction\t531
15.2 Introduction to Containers\t532
15.3 Introduction to Iterators\t535
15.4 Introduction to Algorithms\t538
15.5 Sequence Containers\t539
15.6 Associative Containers\t550
15.7 Container Adapters\t557
15.8 Class bitset\t561
15.9 Wrap-Up\t562
Chapter 16 Standard Library Algorithms\t573
16.1 Introduction\t573
16.2 Minimum Iterator Requirements\t574
16.3 Algorithms\t575
16.4 Function Objects\t600
16.5 Lambda Expressions\t603
16.6 Standard Library Algorithm Summary\t604
16.7 Wrap-Up\t605
Chapter 17 Exception Handling: A Deeper Look\t613
17.1 Introduction\t613
17.2 Example: Handling an Attempt to Divide by Zero\t614
17.3 Rethrowing an Exception\t618
17.4 Stack Unwinding\t620
17.5 When to Use Exception Handling\t621
17.6 Constructors, Destructors and Exception Handling\t622
17.7 Exceptions and Inheritance\t622
17.8 Processing new Failures\t623
17.9 Class unique_ptr and Dynamic Memory Allocation\t625
17.10 Standard Library Exception Hierarchy\t627
17.11 Wrap-Up\t628
Chapter 18 Introduction to Custom Templates\t634
18.1 Introduction\t634
18.2 Class Templates\t635
18.3 Function Template to Manipulate a Class-Template Speization Object\t638
18.4 Nontype Parameters\t640
18.5 Default Arguments for Template Type Parameters\t640
18.6 Overloading Function Templates\t640
18.7 Wrap-Up\t641
Chapter 19 Custom Templatized Data Structures\t644
19.1 Introduction\t644
19.2 Self-Referential Classes\t645
19.3 Linked Lists\t646
19.4 Stacks\t657
19.5 Queues\t660
19.6 Trees\t663
19.7 Wrap-Up\t669
Chapter 20 Searching and Sorting\t680
20.1 Introduction\t680
20.2 Searching Algorithms\t681
20.3 Sorting Algorithms\t687
20.4 Wrap-Up\t696
Chapter 21 Class string and String Stream Processing: A Deeper Look\t702
21.1 Introduction\t703
21.2 string Assignment and Concatenation\t704
21.3 Comparing strings\t705
21.4 Substrings\t707
21.5 Swapping strings\t708
21.6 string Characteristics\t708
21.7 Finding Substrings and Characters in a string\t710
21.8 Replacing Characters in a string\t711
21.9 Inserting Characters into a string\t713
21.10 Conversion to Pointer-Based char * Strings\t713
21.11 Iterators\t715
21.12 String Stream Processing\t715
21.13 C++11 Numeric Conversion Functions\t718
21.14 Wrap-Up\t719
Chapter 22 Bits, Characters, C Strings and structs\t726
22.1 Introduction\t727
22.2 Structure Definitions\t727
22.3 typedef\t728
22.4 Example: Card Shuffling and Dealing Simulation\t728
22.5 Bitwise Operators\t730
22.6 Bit Fields\t737
22.7 Character-Handling Library\t740
22.8 C String-Manipulation Functions\t744
22.9 C String-Conversion Functions\t749
22.10 Search Functions of the C String-Handling Library\t753
22.11 Memory Functions of the C String-Handling Library\t756
22.12 Wrap-Up\t759
Chapter 23 Other Topics\t773
23.1 Introduction\t773
23.2 const_cast Operator\t774
23.3 mutable Class Members\t775
23.4 namespaces\t776
23.5 Operator Keywords\t779
23.6 Pointers to Class Members (.* and ->*)\t781
23.7 Multiple Inheritance\t782
23.8 Multiple Inheritance and virtual Base Classes\t786
23.9 Wrap-Up\t789
Appendix A Operator Precedence and Associativity\t794
Appendix B ASCII Character Set\t796
Appendix C Fundamental Types\t797
Appendix D Number Systems\t799
Appendix E Preprocessor\t809
Index\t819