You are previewing C++ How to Program, 10/e.
O'Reilly logo
C++ How to Program, 10/e

Book Description

C++ How to Program presents leading-edge computing technologies in a friendly manner appropriate for introductory college course sequences, based on the curriculum recommendations of two key professional organizations—the ACM and the IEEE.

The best-selling C++ How to Program is accessible to readers with little or no programming experience, yet comprehensive enough for the professional programmer. The Deitels’ signature live-code approach presents the concepts in the context of full working programs followed by sample executions. The early objects approach gets readers thinking about objects immediately—allowing them to more thoroughly master the concepts. Emphasis is placed on achieving program clarity and building well-engineered software. Interesting, entertaining, and challenging exercises encourage students to make a difference and use computers and the Internet to work on problems. To keep readers up-to-date with leading-edge computing technologies, the Tenth Edition conforms to the C++11 standard and the new C++14 standard.

Table of Contents

  1. C++ HOW TO PROGRAM Introducing the New C++14 Standard
  2. How To Program Series
  3. Deitel® Developer Series
  4. Simply Series
  5. VitalSource Web Books
  6. LiveLessons Video Learning Products
  7. C++ How to Program Introducing the New C++14 Standard
  8. Trademarks
  9. Contents
  10. Preface
    1. Contacting the Authors
    2. Join the Deitel & Associates, Inc. Social Media Communities
    3. The C++11 and C++14 Standards
    4. Key Features of C++ How to Program, 10/e
    5. New in This Edition
    6. Object-Oriented Programming
    7. Hundreds of Code Examples
    8. Exercises
    9. Illustrations and Figures
    10. Dependency Chart
    11. Teaching Approach
    12. Secure C++ Programming
    13. Online Chapters, Appendices and Other Content
    14. Obtaining the Software Used in C++ How to Program, 10/e
    15. Instructor Supplements
    16. Online Practice and Assessment with MyProgrammingLab™
    17. Reviewers
    18. About the Authors
      1. About Deitel & Associates, Inc.
  11. Before You Begin
  12. 1 Introduction to Computers and C++
    1. Objectives
    2. Outline
    3. 1.1 Introduction
    4. 1.2 Computers and the Internet in Industry and Research
    5. 1.3 Hardware and Software
      1. 1.3.1 Moore’s LawMoore’s Law
      2. 1.3.2 Computer Organization
    6. 1.4 Data Hierarchy
    7. 1.5 Machine Languages, Assembly Languages and High-Level Languages
    8. 1.6 C and C++
    9. 1.7 Programming Languages
    10. 1.8 Introduction to Object Technology
    11. 1.9 Typical C++ Development Environment
    12. 1.10 Test-Driving a C++ Application
      1. 1.10.1 Compiling and Running an Application in Visual Studio 2015 for Windows
        1. Step 1: Checking Your Setup
        2. Step 2: Launching Visual Studio
        3. Step 3: Creating a Project
        4. Step 4: Adding the GuessNumber.cpp File into the Project
        5. Step 5: Compiling and Running the Project
        6. Step 6: Entering Your First Guess
        7. Step 7: Entering Another Guess
        8. Step 8: Entering Additional Guesses
        9. Step 9: Playing the Game Again or Exiting the Application
      2. 1.10.2 Compiling and Running Using GNU C++ on Linux
        1. Step 1: Locating the Completed Application
        2. Step 2: Compiling the Application
        3. Step 3: Running the Application
        4. Step 4: Entering Your First Guess
        5. Step 5: Entering Another Guess
        6. Step 6: Entering Additional Guesses
        7. Step 7: Playing the Game Again or Exiting the Application
      3. 1.10.3 Compiling and Running with Xcode on Mac OS X
        1. Step 1: Checking Your Setup
        2. Step 2: Launching Xcode
        3. Step 3: Creating a Project
        4. Step 4: Deleting the main.cpp File from the Project
        5. Step 5: Adding the GuessNumber.cpp File into the Project
        6. Step 6: Compiling and Running the Project
        7. Step 7: Entering Your First Guess
        8. Step 8: Entering Another Guess
        9. Step 9: Entering Additional Guesses
        10. Playing the Game Again or Exiting the Application
    13. 1.11 Operating Systems
      1. 1.11.1 Windows—A Proprietary Operating SystemWindows—A Proprietary Operating System
      2. 1.11.2 Linux—An Open-Source Operating SystemLinux—An Open-Source Operating System
      3. 1.11.3 Apple’s OS X; Apple’s iOS for iPhoneApple’s OS X; Apple’s iOS for iPhone®, iPad® and iPod Touch® Devices
      4. 1.11.4 Google’s AndroidGoogle’s Android
    14. 1.12 The Internet and the World Wide Web
    15. 1.13 Some Key Software Development Terminology
    16. 1.14 C++11 and C++14: The Latest C++ Versions
    17. 1.15 Boost C++ Libraries
    18. 1.16 Keeping Up to Date with Information Technologies
    19. Self-Review Exercises
    20. Exercises
    21. Making a Difference
    22. Making a Difference Resources
  13. 2 Introduction to C++ Programming, Input/Output and Operators
    1. Objectives
    2. Outline
    3. 2.1 Introduction
    4. 2.2 First Program in C++: Printing a Line of Text
    5. 2.3 Modifying Our First C++ Program
    6. 2.4 Another C++ Program: Adding Integers
    7. 2.5 Memory Concepts
    8. 2.6 Arithmetic
    9. 2.7 Decision Making: Equality and Relational Operators
    10. 2.8 Wrap-Up
    11. Summary
    12. Self-Review Exercises
    13. Exercises
    14. Making a Difference
  14. 3 Introduction to Classes, Objects, Member Functions and Strings
    1. Objectives
    2. Outline
    3. 3.1 Introduction 1
    4. 3.2 Test-Driving an Account Object
      1. 3.2.1 Instantiating an Object
      2. 3.2.2 Headers and Source-Code Files
      3. 3.2.3 Calling Class Account’s getName Member Function
      4. 3.2.4 Inputting a string with getline
        1. getline Function Receiving a Line of Text from the User
      5. 3.2.5 Calling Class Account’s setName Member Function
        1. Displaying the Name That Was Entered by the User
    5. 3.3 Account Class with a Data Member and Set and Get Member Functions
      1. 3.3.1 Account Class Definition
      2. 3.3.2 Keyword class and the Class Body
        1. Identifiers and Camel-Case Naming
      3. 3.3.3 Data Member name of Type string
        1. Use std:: with Standard Library Components in Headers
      4. 3.3.4 setName Member Function
        1. setName Parameter
        2. setName Parameter List
        3. setName Member Function Body
        4. Parameters Are Local Variables
        5. Argument and Parameter Types Must Be Consistent
      5. 3.3.5 getName Member Function
        1. const Member Functions
      6. 3.3.6 Access Specifiers private and public
        1. Default Access for Class Members
      7. 3.3.7 Account UML Class Diagram
        1. Top Compartment
        2. Middle Compartment
        3. Bottom Compartment
        4. Return Types
        5. Parameters
    6. 3.4 Account Class: Initializing Objects with Constructors
      1. 3.4.1 Defining an Account Constructor for Custom Object Initialization
        1. Account Class’s Constructor Definition Class’s Constructor Definition
        2. explicit Keyword
        3. Using the Same Parameter Name in the Constructor and Member Function setName
      2. 3.4.2 Initializing Account Objects When They’re Created Objects When They’re Created
        1. Default Constructor
        2. There’s No Default Constructor in a Class That Defines a Constructor
      3. 3.4.3 Account UML Class Diagram with a Constructor
    7. 3.5 Software Engineering with Set and Get Member Functions
    8. 3.6 Account Class with a Balance; Data Validation
      1. 3.6.1 Data Member balance
        1. Account’s Member Functions Can All Use ’s Member Functions Can All Use balance
      2. 3.6.2 Two-Parameter Constructor with Validation
      3. 3.6.3 deposit Member Function with Validation
      4. 3.6.4 getBalance Member Function
      5. 3.6.5 Manipulating Account Objects with Balances
        1. Displaying the Account Objects’ Initial Balances Objects’ Initial Balances
        2. Reading a Deposit Amount from the User and Making a Deposit
        3. Duplicated Code in the main Function
      6. 3.6.6 Account UML Class Diagram with a Balance and Member Functions deposit and getBalance
    9. 3.7 Wrap-Up
    10. Summary
    11. Self-Review Exercises
    12. Exercises
    13. Making a Difference
  15. 4 Algorithm Development and Control Statements: Part 1
    1. Objectives
    2. Outline
    3. 4.1 Introduction
    4. 4.2 Algorithms
    5. 4.3 Pseudocode
    6. 4.4 Control Structures
      1. 4.4.1 Sequence Structure
      2. 4.4.2 Selection Statements
      3. 4.4.3 Iteration Statements
      4. 4.4.4 Summary of Control Statements
    7. 4.5 if Single-Selection Statement
    8. 4.6 if……else Double-Selection Statement
      1. 4.6.1 Nested if……else Statements
      2. 4.6.2 Dangling-else Problem
      3. 4.6.3 Blocks
        1. Syntax and Logic Errors
        2. Empty Statement
      4. 4.6.4 Conditional Operator (?:)
    9. 4.7 Student Class: Nested if……else Statements
    10. 4.8 while Iteration Statement
    11. 4.9 Formulating Algorithms: Counter-Controlled Iteration
      1. 4.9.1 Pseudocode Algorithm with Counter-Controlled Iteration
      2. 4.9.2 Implementing Counter-Controlled Iteration
        1. Local Variables in main
        2. Initialization Phase: Initializing Variables total and gradeCounter
        3. Processing Phase: Reading 10 Grades from the User
        4. Termination Phase: Calculating and Displaying the Class Average
      3. 4.9.3 Notes on Integer Division and Truncation
      4. 4.9.4 Arithmetic Overflow
      5. 4.9.5 Input Validation
    12. 4.10 Formulating Algorithms: Sentinel-Controlled Iteration
      1. 4.10.1 Top-Down, Stepwise Refinement: The Top and First Refinement
      2. 4.10.2 Proceeding to the Second Refinement
      3. 4.10.3 Implementing Sentinel-Controlled Iteration
        1. Program Logic for Sentinel-Controlled Iteration vs. Counter-Controlled Iteration
        2. Braces in a while Statement
      4. 4.10.4 Converting Between Fundamental Types Explicitly and Implicitly
        1. static_cast Operator
        2. Promotions
        3. Cast Operators for Any Type
      5. 4.10.5 Formatting Floating-Point Numbers
        1. setprecision Parameterized Stream Manipulator
        2. fixed Nonparameterized Stream Manipulator
        3. Rounding Floating-Point Numbers
      6. 4.10.6 Unsigned Integers and User Input
    13. 4.11 Formulating Algorithms: Nested Control Statements
      1. 4.11.1 Problem Statement
        1. Problem Statement Observations
      2. 4.11.2 Top-Down, Stepwise Refinement: Pseudocode Representation of the Top
      3. 4.11.3 Top-Down, Stepwise Refinement: First Refinement
      4. 4.11.4 Top-Down, Stepwise Refinement: Second Refinement
      5. 4.11.5 Complete Second Refinement of the Pseudocode
      6. 4.11.6 Program That Implements the Pseudocode Algorithm
      7. 4.11.7 Preventing Narrowing Conversions with List Initialization
        1. A Look Back at Fig. 4.10
    14. 4.12 Compound Assignment Operators
    15. 4.13 Increment and Decrement Operators
    16. 4.14 Fundamental Types Are Not Portable
    17. 4.15 Wrap-Up
    18. Summary
    19. Self-Review Exercises
    20. Exercises
    21. Making a Difference
  16. 5 Control Statements: Part 2; Logical Operators
    1. Objectives
    2. Outline
    3. 5.1 Introduction
    4. 5.2 Essentials of Counter-Controlled Iteration
    5. 5.3 for Iteration Statement
    6. 5.4 Examples Using the for Statement
    7. 5.5 Application: Summing Even Integers
    8. 5.6 Application: Compound-Interest Calculations
    9. 5.7 Case Study: Integer-Based Monetary Calculations with Class DollarAmount
      1. 5.7.1 Demonstrating Class DollarAmount
        1. Calculating Compound Interest with DollarAmount
      2. 5.7.2 Class DollarAmount
        1. C++11 Type int64_t
        2. DollarAmount Constructor
        3. DollarAmount Member Functions add and subtract
        4. DollarAmount Member Function addInterest
        5. Member Function toString
        6. Banker’s Rounding
        7. Even int64_t Is Limited
        8. A Note About Arithmetic Operators and Modifying Operands
    10. 5.8 do……while Iteration Statement
    11. 5.9 switch Multiple-Selection Statement
    12. 5.10 break and continue Statements
      1. 5.10.1 break Statement
      2. 5.10.2 continue Statement
    13. 5.11 Logical Operators
      1. 5.11.1 Logical AND (&&) Operator
      2. 5.11.2 Logical OR (||) Operator
      3. 5.11.3 Short-Circuit Evaluation
      4. 5.11.4 Logical Negation (!) Operator
      5. 5.11.5 Logical Operators Example
        1. Precedence and Associativity of the Operators Presented So Far
    14. 5.12 Confusing the Equality (==) and Assignment (=) Operators
    15. 5.13 Structured-Programming Summary
    16. 5.14 Wrap-Up
    17. Summary
    18. Self-Review Exercises
    19. Exercises
    20. Making a Difference
  17. 6 Functions and an Introduction to Recursion
    1. Objectives
    2. Outline
    3. 6.1 Introduction
    4. 6.2 Program Components in C++
    5. 6.3 Math Library Functions
    6. 6.4 Function Prototypes
    7. 6.5 Function-Prototype and Argument-Coercion Notes
      1. 6.5.1 Function Signatures and Function Prototypes
      2. 6.5.2 Argument Coercion
      3. 6.5.3 Argument-Promotion Rules and Implicit Conversions1
        1. Conversions Can Result in Incorrect Values
    8. 6.6 C++ Standard Library Headers
    9. 6.7 Case Study: Random-Number Generation2
      1. 6.7.1 Rolling a Six-Sided Die
      2. 6.7.2 Rolling a Six-Sided Die 60,000,000 Times
        1. C++14 Digit Separators for Numeric Literals
      3. 6.7.3 Randomizing the Random-Number Generator with srand
        1. Demonstrating srand
      4. 6.7.4 Seeding the Random-Number Generator with the Current Time
      5. 6.7.5 Scaling and Shifting Random Numbers
    10. 6.8 Case Study: Game of Chance; Introducing Scoped enums
    11. 6.9 C++11 Random Numbers
    12. 6.10 Scope Rules
    13. 6.11 Function-Call Stack and Activation Records
    14. 6.12 Inline Functions
    15. 6.13 References and Reference Parameters
    16. 6.14 Default Arguments
    17. 6.15 Unary Scope Resolution Operator
    18. 6.16 Function Overloading
    19. 6.17 Function Templates
    20. 6.18 Recursion
    21. 6.19 Example Using Recursion: Fibonacci Series
    22. 6.20 Recursion vs. Iteration
    23. 6.21 Wrap-Up
    24. Summary
      1. Section 6.11 Function-Call Stack and Activation Records
      2. Section 6.12 Inline Functions
      3. Section 6.13 References and Reference Parameters
      4. Section 6.14 Default Arguments
      5. Section 6.15 Unary Scope Resolution Operator
      6. Section 6.16 Function Overloading
      7. Section 6.17 Function Templates
      8. Section 6.18 Recursion
      9. Section 6.19 Example Using Recursion: Fibonacci Series
        1. Section 6.20 Recursion vs. Iteration
    25. Self-Review Exercises
    26. Exercises
    27. Making a Difference
  18. 7 Class Templates array and vector; Catching Exceptions
    1. Objectives
    2. Outline
    3. 7.1 Introduction
    4. 7.2 arrays
    5. 7.3 Declaring arrays
    6. 7.4 Examples Using arrays
      1. 7.4.1 Declaring an array and Using a Loop to Initialize the array’s Elements’s Elements
      2. 7.4.2 Initializing an array in a Declaration with an Initializer List
        1. Fewer Initializers Than array Elements
        2. More Initializers Than array Elements
      3. 7.4.3 Specifying an array’s Size with a Constant Variable and Setting ’s Size with a Constant Variable and Setting array Elements with Calculations
        1. Constant Variables
      4. 7.4.4 Summing the Elements of an array
      5. 7.4.5 Using a Bar Chart to Display array Data Graphically
      6. 7.4.6 Using the Elements of an array as Counters
      7. 7.4.7 Using arrays to Summarize Survey Results
        1. Bounds Checking for array Subscripts
      8. 7.4.8 Static Local arrays and Automatic Local arrays
    7. 7.5 Range-Based for Statement
    8. 7.6 Case Study: Class GradeBook Using an array to Store Grades
    9. 7.7 Sorting and Searching arrays
      1. 7.7.1 Sorting
      2. 7.7.2 Searching
      3. 7.7.3 Demonstrating Functions sort and binary_search
    10. 7.8 Multidimensional arrays
    11. 7.9 Case Study: Class GradeBook Using a Two-Dimensional array
    12. 7.10 Introduction to C++ Standard Library Class Template vector
    13. 7.11 Wrap-Up
    14. Summary
    15. Self-Review Exercises
    16. Exercises
    17. Recursion Exercises
    18. Making a Difference
  19. 8 Pointers
    1. Objectives
    2. Outline
    3. 8.1 Introduction
    4. 8.2 Pointer Variable Declarations and Initialization
      1. 8.2.1 Declaring Pointers
      2. 8.2.2 Initializing Pointers
      3. 8.2.3 Null Pointers Prior to C++11
    5. 8.3 Pointer Operators
      1. 8.3.1 Address (&) Operator
      2. 8.3.2 Indirection (*) Operator
      3. 8.3.3 Using the Address (&) and Indirection (*) Operators
        1. Precedence and Associativity of the Operators Discussed So Far
    6. 8.4 Pass-by-Reference with Pointers
    7. 8.5 Built-In Arrays
      1. 8.5.1 Declaring and Accessing a Built-In Array
      2. 8.5.2 Initializing Built-In Arrays
      3. 8.5.3 Passing Built-In Arrays to Functions
      4. 8.5.4 Declaring Built-In Array Parameters
      5. 8.5.5 C++11: Standard Library Functions begin and end
      6. 8.5.6 Built-In Array Limitations
      7. 8.5.7 Built-In Arrays Sometimes Are Required
    8. 8.6 Using const with Pointers
      1. 8.6.1 Nonconstant Pointer to Nonconstant Data
      2. 8.6.2 Nonconstant Pointer to Constant Data
      3. 8.6.3 Constant Pointer to Nonconstant Data
      4. 8.6.4 Constant Pointer to Constant Data
    9. 8.7 sizeof Operator
    10. 8.8 Pointer Expressions and Pointer Arithmetic
      1. 8.8.1 Adding Integers to and Subtracting Integers from Pointers
      2. 8.8.2 Subtracting Pointers
      3. 8.8.3 Pointer Assignment
      4. 8.8.4 Cannot Dereference a void*
      5. 8.8.5 Comparing Pointers
    11. 8.9 Relationship Between Pointers and Built-In Arrays
      1. 8.9.1 Pointer/Offset Notation
      2. 8.9.2 Pointer/Offset Notation with the Built-In Array’s Name as the PointerPointer/Offset Notation with the Built-In Array’s Name as the Pointer
      3. 8.9.3 Pointer/Subscript Notation
      4. 8.9.4 Demonstrating the Relationship Between Pointers and Built-In Arrays
    12. 8.10 Pointer-Based Strings (Optional)
    13. 8.11 Note About Smart Pointers
    14. 8.12 Wrap-Up
    15. Summary
    16. Self-Review Exercises
    17. Exercises
    18. Special Section: Building Your Own Computer
  20. 9 Classes: A Deeper Look
    1. Objectives
    2. Outline
    3. 9.1 Introduction
    4. 9.2 Time Class Case Study: Separating Interface from Implementation
      1. 9.2.1 Interface of a Class
      2. 9.2.2 Separating the Interface from the Implementation
      3. 9.2.3 Time Class Definition
        1. Include Guard1
      4. 9.2.4 Time Class Member Functions
      5. 9.2.5 Scope Resolution Operator (::)
      6. 9.2.6 Including the Class Header in the Source-Code File
      7. 9.2.7 Time Class Member Function setTime and Throwing Exceptions
      8. 9.2.8 Time Class Member Function toUniversalString and String Stream Processing
      9. 9.2.9 Time Class Member Function toStandardString
      10. 9.2.10 Implicitly Inlining Member Functions
      11. 9.2.11 Member Functions vs. Global Functions
      12. 9.2.12 Using Class Time
        1. Calling setTime with Invalid Values
      13. 9.2.13 Object Size
    5. 9.3 Compilation and Linking Process
    6. 9.4 Class Scope and Accessing Class Members
    7. 9.5 Access Functions and Utility Functions
    8. 9.6 Time Class Case Study: Constructors with Default Arguments
      1. 9.6.1 Constructors with Default Arguments
        1. Notes Regarding Class Time’s Set and Get Functions and Constructor
      2. 9.6.2 Overloaded Constructors and C++11 Delegating Constructors
    9. 9.7 Destructors
    10. 9.8 When Constructors and Destructors Are Called
      1. 9.8.1 Constructors and Destructors for Objects in Global Scope
      2. 9.8.2 Constructors and Destructors for Non-static Local Objects
      3. 9.8.3 Constructors and Destructors for static Local Objects
      4. 9.8.4 Demonstrating When Constructors and Destructors Are Called
    11. 9.9 Time Class Case Study: A Subtle Trap — Returning a Reference or a Pointer to a Class Case Study: A Subtle Trap — Returning a Reference or a Pointer to a private Data Member
    12. 9.10 Default Memberwise Assignment
    13. 9.11 const Objects and const Member Functions
    14. 9.12 Composition: Objects as Members of Classes
    15. 9.13 friend Functions and friend Classes
    16. 9.14 Using the this Pointer
      1. 9.14.1 Implicitly and Explicitly Using the this Pointer to Access an Object’s Data Members Pointer to Access an Object’s Data Members
      2. 9.14.2 Using the this Pointer to Enable Cascaded Function Calls
    17. 9.15 static Class Members
      1. 9.15.1 Motivating Classwide Data
      2. 9.15.2 Scope and Initialization of static Data Members
      3. 9.15.3 Accessing static Data Members
      4. 9.15.4 Demonstrating static Data Members
    18. 9.16 Wrap-Up
    19. Summary
    20. Self-Review Exercises
    21. Exercises
    22. Making a Difference
  21. 10 Operator Overloading; Class string
    1. Objectives
    2. Outline
    3. 10.1 Introduction
    4. 10.2 Using the Overloaded Operators of Standard Library Class string
    5. 10.3 Fundamentals of Operator Overloading
      1. 10.3.1 Operator Overloading Is Not Automatic
      2. 10.3.2 Operators That You Do Not Have to Overload
      3. 10.3.3 Operators That Cannot Be Overloaded
      4. 10.3.4 Rules and Restrictions on Operator Overloading
    6. 10.4 Overloading Binary Operators
    7. 10.5 Overloading the Binary Stream Insertion and Stream Extraction Operators
    8. 10.6 Overloading Unary Operators
    9. 10.7 Overloading the Increment and Decrement Operators
    10. 10.8 Case Study: A Date Class
    11. 10.9 Dynamic Memory Management
    12. 10.10 Case Study: Array Class
      1. 10.10.1 Using the Array Class
        1. Creating Arrays, Outputting Their Size and Displaying Their Contents
        2. Using the Overloaded Stream Extraction Operator to Fill an Array
        3. Using the Overloaded Inequality Operator
        4. Initializing a New Array with a Copy of an Existing Array’s Contents’s Contents
        5. Using the Overloaded Assignment Operator
        6. Using the Overloaded Equality Operator
        7. Using the Overloaded Subscript Operator
      2. 10.10.2 Array Class Definition
        1. Overloading the Stream Insertion and Stream Extraction Operators as friends
        2. Range-Based for Does Not Work with Dynamically Allocated Built-In Arrays
        3. Array Default Constructor
        4. Array Copy Constructor
        5. Array Destructor
        6. getSize Member Function
        7. Overloaded Assignment Operator
        8. C++11: Move Constructor and Move Assignment Operator
        9. C++11: Deleting Unwanted Member Functions from Your Class
        10. Overloaded Equality and Inequality Operators
        11. Overloaded Subscript Operators
        12. C++11: Managing Dynamically Allocated Memory with unique_ptr
        13. C++11: Passing a List Initializer to a Constructor
    13. 10.11 Operators as Member vs. Non-Member Functions
    14. 10.12 Converting Between Types
    15. 10.13 explicit Constructors and Conversion Operators
    16. 10.14 Overloading the Function Call Operator ()
    17. 10.15 Wrap-Up
    18. Summary
    19. Self-Review Exercises
    20. Exercises
  22. 11 Object-Oriented Programming: Inheritance
    1. Objectives
    2. Outline
    3. 11.1 Introduction
    4. 11.2 Base Classes and Derived Classes
      1. 11.2.1 CommunityMember Class Hierarchy
      2. 11.2.2 Shape Class Hierarchy
    5. 11.3 Relationship between Base and Derived Classes
      1. 11.3.1 Creating and Using a CommissionEmployee Class
        1. CommissionEmployee Constructor
        2. CommissionEmployee Member Functions earnings and toString
        3. Testing Class CommissionEmployee
      2. 11.3.2 Creating a BasePlusCommissionEmployee Class Without Using Inheritance
        1. Defining Class BasePlusCommissionEmployee
        2. Testing Class BasePlusCommissionEmployee
        3. Exploring the Similarities Between Class BasePlusCommissionEmployee and Class CommissionEmployee
      3. 11.3.3 Creating a CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy
        1. Compilation Errors from Accessing Base-Class private Members
        2. Preventing the Errors in BasePlusCommissionEmployee
        3. Including the Base-Class Header in the Derived-Class Header with #include
        4. Linking Process in an Inheritance Hierarchy
      4. 11.3.4 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using protected Data
        1. Defining Base-Class CommissionEmployee with protected Data
        2. Class BasePlusCommissionEmployee
        3. Testing the Modified BasePlusCommissionEmployee Class
        4. Notes on Using protected Data
      5. 11.3.5 CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Data
        1. Changes to Class CommissionEmployee’s Member-Function Definitions’s Member-Function Definitions
        2. Changes to Class BasePlusCommissionEmployee’s Member-Function Definitions’s Member-Function Definitions
        3. BasePlusCommissionEmployee Member Function earnings
        4. BasePlusCommissionEmployee Member Function toString
        5. Testing the Modified Class Hierarchy
        6. Summary of the CommissionEmployee–BasePlusCommissionEmployee Examples
    6. 11.4 Constructors and Destructors in Derived Classes
    7. 11.5 public, protected and private Inheritance
    8. 11.6 Wrap-Up
    9. Summary
      1. Section 11.1 Introduction
      2. Section 11.2 Base Classes and Derived Classes
      3. Section 11.4 Constructors and Destructors in Derived Classes
      4. Section 11.5 public, protected and private Inheritance
    10. Self-Review Exercises
    11. Exercises
  23. 12 Object-Oriented Programming: Polymorphism
    1. Objectives
    2. Outline
    3. 12.1 Introduction
    4. 12.2 Introduction to Polymorphism: Polymorphic Video Game
    5. 12.3 Relationships Among Objects in an Inheritance Hierarchy
      1. 12.3.1 Invoking Base-Class Functions from Derived-Class Objects
        1. Creating Objects and Displaying Their Contents
        2. Aiming a Base-Class Pointer at a Base-Class Object
        3. Aiming a Derived-Class Pointer at a Derived-Class Object
        4. Aiming a Base-Class Pointer at a Derived-Class Object
      2. 12.3.2 Aiming Derived-Class Pointers at Base-Class Objects
      3. 12.3.3 Derived-Class Member-Function Calls via Base-Class Pointers
        1. Downcasting
    6. 12.4 Virtual Functions and Virtual Destructors
      1. 12.4.1 Why virtual Functions Are Useful
      2. 12.4.2 Declaring virtual Functions
      3. 12.4.3 Invoking a virtual Function Through a Base-Class Pointer or Reference
      4. 12.4.4 Invoking a virtual Function Through an Object’s Name Function Through an Object’s Name
      5. 12.4.5 virtual Functions in the CommissionEmployee Hierarchy
      6. 12.4.6 virtual Destructors
      7. 12.4.7 C++11: final Member Functions and Classes
    7. 12.5 Type Fields and switch Statements
    8. 12.6 Abstract Classes and Pure virtual Functions
      1. 12.6.1 Pure virtual Functions
      2. 12.6.2 Device Drivers: Polymorphism in Operating Systems
    9. 12.7 Case Study: Payroll System Using Polymorphism
      1. 12.7.1 Creating Abstract Base Class Employee
        1. Employee Class Header
        2. Employee Class Member-Function Definitions
      2. 12.7.2 Creating Concrete Derived Class SalariedEmployee
        1. SalariedEmployee Class Member-Function Definitions
      3. 12.7.3 Creating Concrete Derived Class CommissionEmployee
      4. 12.7.4 Creating Indirect Concrete Derived Class BasePlusCommissionEmployee
      5. 12.7.5 Demonstrating Polymorphic Processing
    10. 12.8 (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”(Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”
    11. 12.9 Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info
    12. 12.10 Wrap-Up
    13. Summary
      1. Section 12.1 Introduction
      2. Section 12.2 Introduction to Polymorphism: Polymorphic Video Game
      3. Section 12.3 Relationships Among Objects in an Inheritance Hierarchy
      4. Section 12.4.2 Declaring virtual Functions
      5. Section 12.4.3 Invoking a virtual Function Through a Base-Class Pointer or Reference
      6. Section 12.4.4 Invoking a virtual Function Through an Object’s Name Function Through an Object’s Name
      7. Section 12.4.5 virtual Functions in the CommissionEmployee Hierarchy
      8. Section 12.4.6 virtual Destructors
      9. Section 12.4.7 C++11: final Member Functions and Classes
      10. Section 12.5 Type Fields and switch Statements
      11. Section 12.6 Abstract Classes and Pure virtual Functions
      12. Section 12.6.1 Pure Virtual Functions
      13. Section 12.8 (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”(Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”
      14. Section 12.9 Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info
    14. Self-Review Exercises
    15. Exercises
    16. Making a Difference
  24. 13 Stream Input/Output: A Deeper Look
    1. Objectives
    2. Outline
    3. 13.1 Introduction
    4. 13.2 Streams
      1. 13.2.1 Classic Streams vs. Standard Streams
      2. 13.2.2 iostream Library Headers
      3. 13.2.3 Stream Input/Output Classes and Objects
        1. iostream Library Aliases Are Defined with typedef
        2. Standard Stream Objects cin, cout, cerr and clog
    5. 13.3 Stream Output
      1. 13.3.1 Output of char* Variables
      2. 13.3.2 Character Output Using Member Function put
    6. 13.4 Stream Input
      1. 13.4.1 get and getline Member Functions
        1. Using Member Functions eof, get and put
        2. Comparing cin and cin.get
        3. Using Member Function getline
      2. 13.4.2 istream Member Functions peek, putback and ignore
      3. 13.4.3 Type-Safe I/O
    7. 13.5 Unformatted I/O Using read, write and gcount
    8. 13.6 Stream Manipulators: A Deeper Look
      1. 13.6.1 Integral Stream Base: dec, oct, hex and setbase
      2. 13.6.2 Floating-Point Precision (precision, setprecision)
      3. 13.6.3 Field Width (width, setw)
      4. 13.6.4 User-Defined Output Stream Manipulators
    9. 13.7 Stream Format States and Stream Manipulators
      1. 13.7.1 Trailing Zeros and Decimal Points (showpoint)
      2. 13.7.2 Justification (left, right and internal)
      3. 13.7.3 Padding (fill, setfill)
      4. 13.7.4 Integral Stream Base (dec, oct, hex, showbase)
      5. 13.7.5 Floating-Point Numbers; Scientific and Fixed Notation (scientific, fixed)
      6. 13.7.6 Uppercase/Lowercase Control (uppercase)
      7. 13.7.7 Specifying Boolean Format (boolalpha)
      8. 13.7.8 Setting and Resetting the Format State via Member Function flags
    10. 13.8 Stream Error States
    11. 13.9 Tying an Output Stream to an Input Stream
    12. 13.10 Wrap-Up
    13. Summary
      1. Section 13.1 Introduction
      2. Section 13.2 Streams
      3. Section 13.2.2 iostream Library Headers
      4. Section 13.2.3 Stream Input/Output Classes and Objects
      5. Section 13.3 Stream Output
      6. Section 13.4 Stream Input
      7. Section 13.5 Unformatted I/O Using read, write and gcount
      8. Section 13.6 Stream Manipulators: A Deeper Look
      9. Section 13.7 Stream Format States and Stream Manipulators
      10. Section 13.8 Stream Error States
      11. Section 13.9 Tying an Output Stream to an Input Stream
    14. Self-Review Exercises
    15. Exercises
  25. 14 File Processing
    1. Objectives
    2. Outline
    3. 14.1 Introduction
    4. 14.2 Files and Streams
    5. 14.3 Creating a Sequential File
      1. 14.3.1 Opening a File
      2. 14.3.2 Opening a File via the open Member Function
      3. 14.3.3 Testing Whether a File Was Opened Successfully
      4. 14.3.4 Overloaded bool Operator
      5. 14.3.5 Processing Data
      6. 14.3.6 Closing a File
      7. 14.3.7 Sample Execution
    6. 14.4 Reading Data from a Sequential File
      1. 14.4.1 Opening a File for Input
      2. 14.4.2 Reading from the File
      3. 14.4.3 File-Position Pointers
      4. 14.4.4 Case Study: Credit Inquiry Program
    7. 14.5 C++14: Reading and Writing Quoted Text
    8. 14.6 Updating Sequential Files
    9. 14.7 Random-Access Files
    10. 14.8 Creating a Random-Access File
      1. 14.8.1 Writing Bytes with ostream Member Function write
      2. 14.8.2 Converting Between Pointer Types with the reinterpret_cast Operator
      3. 14.8.3 Credit-Processing Program
      4. 14.8.4 Opening a File for Output in Binary Mode
    11. 14.9 Writing Data Randomly to a Random-Access File
      1. 14.9.1 Opening a File for Input and Output in Binary Mode
      2. 14.9.2 Positioning the File-Position Pointer
    12. 14.10 Reading from a Random-Access File Sequentially
    13. 14.11 Case Study: A Transaction-Processing Program
    14. 14.12 Object Serialization
    15. 14.13 Wrap-Up
    16. Summary
      1. Section 14.1 Introduction
      2. Section 14.2 Files and Streams
      3. Section 14.3 Creating a Sequential File
      4. Section 14.4 Reading Data from a Sequential File
      5. Section 14.5 C++14: Reading and Writing Quoted Text
      6. Section 14.6 Updating Sequential Files
        1. Section 14.7 Random-Access Files
        2. Section 14.8 Creating a Random-Access File
        3. Section 14.9 Writing Data Randomly to a Random-Access File
        4. Section 14.10 Reading from a Random-Access File Sequentially
        5. Section 14.12 Object Serialization
      7. Self-Review Exercises
    17. Exercises
    18. Making a Difference
  26. 15 Standard Library Containers and Iterators
    1. Objectives
    2. Outline
    3. 15.1 Introduction
    4. 15.2 Introduction to Containers2
    5. 15.3 Introduction to Iterators
    6. 15.4 Introduction to Algorithms
    7. 15.5 Sequence Containers
      1. 15.5.1 vector Sequence Container
        1. Using vectors and Iterators
        2. Creating a vector
        3. vector Member Functions size and capacity
        4. vector Member Function push_back
        5. Updated size and capacity After Modifying a vector
        6. vector Growth
        7. Outputting Built-in Array Contents with Pointers
        8. Outputting vector Contents with Iterators
        9. Displaying the vector’s Contents in Reverse with const_reverse_iterators
        10. C++11: shrink_to_fit
        11. vector Element-Manipulation Functions
        12. ostream_iterator
        13. copy Algorithm
        14. vector Member Functions front and back
        15. Accessing vector Elements
        16. vector Member Function insert
        17. vector Member Function erase
        18. vector Member Function insert with Three Arguments (Range insert)
        19. vector Member Function clear
      2. 15.5.2 list Sequence Container
        1. C++11: forward_list Container
        2. list Member Functions
        3. Creating list Objects
        4. list Member Function sort
        5. list Member Function splice
        6. list Member Function merge
        7. list Member Function pop_front
        8. list Member Function unique
        9. list Member Function swap
        10. list Member Functions assign and remove
      3. 15.5.3 deque Sequence Container
    8. 15.6 Associative Containers
      1. 15.6.1 multiset Associative Container
        1. Creating a multiset
        2. multiset Member Function count
        3. multiset Member Function insert
        4. multiset Member Function find
        5. Inserting Elements of Another Container into a multiset
        6. multiset Member Functions lower_bound and upper_bound
        7. pair Objects and multiset Member Function equal_range
        8. C++11: Variadic Class Template tuple
        9. C++14: Heterogeneous Lookup
      2. 15.6.2 set Associative Container
      3. 15.6.3 multimap Associative Container
        1. C++11: List Initializing a Key–Value Pair Container
      4. 15.6.4 map Associative Container
    9. 15.7 Container Adapters
      1. 15.7.1 stack Adapter
      2. 15.7.2 queue Adapter
      3. 15.7.3 priority_queue Adapter
    10. 15.8 Class bitset
    11. 15.9 Wrap-Up
    12. Summary
      1. Section 15.1 Introduction
      2. Section 15.2 Introduction to Containers
      3. Section 15.3 Introduction to Iterators
      4. Section 15.4 Introduction to Algorithms
      5. Section 15.5 Sequence Containers
      6. Section 15.5.1 vector Sequence Container
      7. Section 15.5.2 list Sequence Container
      8. Section 15.5.3 deque Sequence Container
      9. Section 15.6 Associative Containers
      10. Section 15.6.1 multiset Associative Container
      11. Section 15.6.2 set Associative Container
      12. Section 15.6.3 multimap Associative Container
      13. Section 15.6.4 map Associative Container
      14. Section 15.7 Container Adapters
      15. Section 15.7.1 stack Adapter
      16. Section 15.7.2 queue Adapter
      17. Section 15.7.3 priority_queue Adapter
      18. Section 15.8 Class bitset
    13. Self-Review Exercises
    14. Exercises
      1. Discussion Questions
      2. Programming Exercises
    15. Recommended Reading
  27. 16 Standard Library Algorithms
    1. Objectives
    2. Outline
    3. 16.1 Introduction
    4. 16.2 Minimum Iterator Requirements
      1. Iterator Invalidation
    5. 16.3 Lambda Expressions
      1. 16.3.1 Algorithm for_each
      2. 16.3.2 Lambda with an Empty Introducer
      3. 16.3.3 Lambda with a Nonempty Introducer—Capturing Local VariablesLambda with a Nonempty Introducer—Capturing Local Variables
      4. 16.3.4 Lambda Return Types
    6. 16.4 Algorithms
      1. 16.4.1 fill, fill_n, generate and generate_n
        1. fill Algorithm
        2. fill_n Algorithm
        3. generate Algorithm
        4. generate_n Algorithm
        5. Using the generate_n Algorithm with a Lambda
        6. A Note About Reading Standard Library Algorithm Documentation
      2. 16.4.2 equal, mismatch and lexicographical_compare
        1. equal Algorithm
        2. equal Algorithm with Binary Predicate Function
        3. mismatch Algorithm
        4. auto Variables and List Initialization
        5. lexicographical_compare Algorithm
      3. 16.4.3 remove, remove_if, remove_copy and remove_copy_if
        1. remove Algorithm
        2. remove_copy Algorithm
        3. remove_if Algorithm
        4. remove_copy_if Algorithm
      4. 16.4.4 replace, replace_if, replace_copy and replace_copy_if
        1. replace Algorithm
        2. replace_copy Algorithm
        3. replace_if Algorithm
        4. replace_copy_if Algorithm
      5. 16.4.5 Mathematical Algorithms
        1. shuffle Algorithm
        2. count Algorithm
        3. count_if Algorithm
        4. min_element Algorithm
        5. max_element Algorithm
        6. C++11: minmax_element Algorithm
        7. accumulate Algorithm
        8. transform Algorithm
      6. 16.4.6 Basic Searching and Sorting Algorithms
        1. find Algorithm
        2. Storing Lambdas in Variables
        3. find_if Algorithm
        4. sort Algorithm
        5. binary_search Algorithm
        6. C++11: all_of Algorithm
        7. C++11: any_of Algorithm
        8. C++11: none_of Algorithm
        9. C++11: find_if_not Algorithm
      7. 16.4.7 swap, iter_swap and swap_ranges
        1. swap Algorithm
        2. iter_swap Algorithm
        3. swap_ranges Algorithm
      8. 16.4.8 copy_backward, merge, unique and reverse
        1. copy_backward Algorithm
        2. merge Algorithm
        3. back_inserter, front_inserter and inserter Iterator Adapters
        4. unique Algorithm
        5. reverse Algorithm
        6. C++11: copy_if and copy_n Algorithms
      9. 16.4.9 inplace_merge, unique_copy and reverse_copy
        1. inplace_merge Algorithm
        2. unique_copy Algorithm
        3. reverse_copy Algorithm
      10. 16.4.10 Set Operations
        1. includes Algorithm
        2. set_difference Algorithm
        3. set_intersection Algorithm
        4. set_symmetric_difference Algorithm
        5. set_union Algorithm
      11. 16.4.11 lower_bound, upper_bound and equal_range
        1. lower_bound Algorithm
        2. upper_bound Algorithm
        3. equal_range Algorithm
        4. Locating Insertion Points in Sorted Sequences
      12. 16.4.12 min, max, minmax and minmax_element
        1. Algorithms min and max with Two Parameters
        2. C++11: min and max Algorithms with initializer_list Parameters
        3. C++11: minmax Algorithm
        4. C++11: minmax_element Algorithm
    7. 16.5 Function Objects
      1. Advantages of Function Objects over Function Pointers
      2. Predefined Function Objects of the Standard Template Library
      3. Using the accumulate Algorithm
        1. Function sumSquares
        2. Class SumSquaresClass
        3. Calling Algorithm accumulate
    8. 16.6 Standard Library Algorithm Summary
      1. Mutating Sequence Algorithms
      2. Nonmodifying Sequence Algorithms
      3. Sorting and Related Algorithms
      4. Numerical Algorithms
    9. 16.7 Wrap-Up
    10. Summary
      1. Section 16.1 Introduction
      2. Section 16.3 Lambda Expressions
      3. Section 16.3.1 Algorithm for_each
      4. Section 16.3.2 Lambda with an Empty Introducer
      5. Section 16.3.3 Lambda with a Nonempty Introducer—Capturing Local VariablesLambda with a Nonempty Introducer—Capturing Local Variables
      6. Section 16.3.4 Lambda Return Types
      7. Section 16.4.1 fill, fill_n, generate and generate_n
      8. Section 16.4.2 equal, mismatch and lexicographical_compare
      9. Section 16.4.3 remove, remove_if, remove_copy and remove_copy_if
      10. Section 16.4.4 replace, replace_if, replace_copy and replace_copy_if
      11. Section 16.4.5 Mathematical Algorithms
      12. Section 16.4.6 Basic Searching and Sorting Algorithms
      13. Section 16.4.7 swap, iter_swap and swap_ranges
      14. Section 16.4.8 copy_backward, merge, unique and reverse
      15. Section 16.4.9 inplace_merge, unique_copy and reverse_copy
      16. Section 16.4.10 Set Operations
      17. Section 16.4.11 lower_bound, upper_bound and equal_range
      18. Section 16.4.12 min, max, minmax and minmax_element
      19. Section 16.5 Function Objects
    11. Self-Review Exercises
    12. Exercises
  28. 17 Exception Handling: A Deeper Look
    1. Objectives
    2. Outline
    3. 17.1 Introduction
    4. 17.2 Exception-Handling Flow of Control; Defining an Exception Class
      1. 17.2.1 Defining an Exception Class to Represent the Type of Problem That Might Occur
      2. 17.2.2 Demonstrating Exception Handling
      3. 17.2.3 Enclosing Code in a try Block
    5. 17.2.4 Defining a catch Handler to Process a DivideByZeroException
      1. 17.2.5 Termination Model of Exception Handling
      2. 17.2.6 Flow of Program Control When the User Enters a Nonzero Denominator
      3. 17.2.7 Flow of Program Control When the User Enters a Denominator of Zero
    6. 17.3 Rethrowing an Exception
    7. 17.4 Stack Unwinding
    8. 17.5 When to Use Exception Handling
    9. 17.6 noexcept: Declaring Functions That Do Not Throw Exceptions
    10. 17.7 Constructors, Destructors and Exception Handling
      1. 17.7.1 Destructors Called Due to Exceptions
      2. 17.7.2 Initializing Local Objects to Acquire Resources
    11. 17.8 Processing new Failures
      1. 17.8.1 new Throwing bad_alloc on Failure
      2. 17.8.2 new Returning nullptr on Failure
      3. 17.8.3 Handling new Failures Using Function set_new_handler
    12. 17.9 Class unique_ptr and Dynamic Memory Allocation
      1. Demonstrating unique_ptr
      2. 17.9.1 unique_ptr Ownership
      3. 17.9.2 unique_ptr to a Built-In Array
    13. 17.10 Standard Library Exception Hierarchy
    14. 17.11 Wrap-Up
    15. Summary
      1. Section 17.1 Introduction
      2. Section 17.2.1 Defining an Exception Class to Represent the Type of Problem That Might Occur
      3. Section 17.2.5 Termination Model of Exception Handling
      4. Section 17.2.7 Flow of Program Control When the User Enters a Denominator of Zero
      5. Section 17.3 Rethrowing an Exception
      6. Section 17.4 Stack Unwinding
      7. Section 17.5 When to Use Exception Handling
      8. Section 17.6 noexcept: Declaring Functions That Do Not Throw Exceptions
      9. Section 17.7.1 Destructors Called Due to Exceptions
      10. Section 17.7.2 Initializing Local Objects to Acquire Resources
      11. Section 17.8 Processing new Failures
      12. Section 17.9 Class unique_ptr and Dynamic Memory Allocation
      13. Section 17.10 Standard Library Exception Hierarchy
    16. Self-Review Exercises
    17. Exercises
  29. 18 Introduction to Custom Templates
    1. Objectives
    2. Outline
    3. 18.1 Introduction
    4. 18.2 Class Templates
      1. 18.2.1 Creating Class Template Stack&lt;T&gt;Creating Class Template Stack<T>
      2. 18.2.2 Class Template Stack&lt;T&gt;&#8217;s Data Representation’s Data Representation
      3. 18.2.3 Class Template Stack&lt;T&gt;&#8217;s Member Functions’s Member Functions
      4. 18.2.4 Declaring a Class Template&#8217;s Member Functions Outside the Class Template DefinitionDeclaring a Class Template’s Member Functions Outside the Class Template Definition
      5. 18.2.5 Testing Class Template Stack&lt;T&gt;
    5. 18.3 Function Template to Manipulate a Class-Template Specialization Object
    6. 18.4 Nontype Parameters
    7. 18.5 Default Arguments for Template Type Parameters
    8. 18.6 Overloading Function Templates
      1. Matching Process for Overloaded Functions
    9. 18.7 Wrap-Up
    10. Summary
      1. Section 18.1 Introduction
      2. Section 18.2 Class Templates
      3. Section 18.4 Nontype Parameters
      4. Section 18.5 Default Arguments for Template Type Parameters
      5. Section 18.6 Overloading Function Templates
    11. Self-Review Exercises
    12. Exercises
  30. 19 Custom Templatized Data Structures
    1. Objectives
    2. Outline
    3. 19.1 Introduction
      1. 19.1.1 Always Prefer the Standard Library&#8217;s Containers, Iterators and Algorithms, if PossibleAlways Prefer the Standard Library’s Containers, Iterators and Algorithms, if Possible
      2. 19.1.2 Special Section: Building Your Own Compiler
    4. 19.2 Self-Referential Classes
    5. 19.3 Linked Lists
      1. 19.3.1 Testing Our Linked List Implementation
      2. 19.3.2 Class Template ListNode
      3. 19.3.3 Class Template List
      4. 19.3.4 Member Function insertAtFront
      5. 19.3.5 Member Function insertAtBack
      6. 19.3.6 Member Function removeFromFront
      7. 19.3.7 Member Function removeFromBack
      8. 19.3.8 Member Function print
      9. 19.3.9 Circular Linked Lists and Double Linked Lists
    6. 19.4 Stacks
      1. 19.4.1 Taking Advantage of the Relationship Between Stack and List
      2. 19.4.2 Implementing a Class Template Stack Class Based By Inheriting from List
      3. 19.4.3 Dependent Names in Class Templates
      4. 19.4.4 Testing the Stack Class Template
      5. 19.4.5 Implementing a Class Template Stack Class With Composition of a List Object
    7. 19.5 Queues
      1. 19.5.1 Applications of Queues
      2. 19.5.2 Implementing a Class Template Queue Class Based By Inheriting from List
      3. 19.5.3 Testing the Queue Class Template
    8. 19.6 Trees
      1. 19.6.1 Basic Terminology
      2. 19.6.2 Binary Search Trees
        1. Implementing the Binary Search Tree Program
      3. 19.6.3 Testing the Tree Class Template
      4. 19.6.4 Class Template TreeNode
      5. 19.6.5 Class Template Tree
      6. 19.6.6 Tree Member Function insertNodeHelper
      7. 19.6.7 Tree Traversal Functions
        1. Inorder Traversal Algorithm
        2. Preorder Traversal Algorithm
        3. Postorder Traversal Algorithm
      8. 19.6.8 Duplicate Elimination
      9. 19.6.9 Overview of the Binary Tree Exercises
    9. 19.7 Wrap-Up
    10. Summary
    11. Self-Review Exercises
    12. Exercises
    13. Special Section: Building Your Own Compiler
  31. 20 Searching and Sorting
    1. Objectives
    2. Outline
    3. 20.1 Introduction
    4. 20.2 Searching Algorithms
      1. 20.2.1 Linear Search
        1. Function Template linearSearch
        2. Big O: Constant Runtime
        3. Big O: Linear Runtime
        4. Big O: Quadratic Runtime
        5. O(n2) Performance
        6. Linear Search’s Runtime
      2. 20.2.2 Binary Search
        1. Binary Search of 15 Integer Values
        2. Binary Search Example
        3. Function Template binarySearch
        4. Function main
        5. Efficiency of Binary Search
    5. 20.3 Sorting Algorithms
      1. 20.3.1 Insertion Sort
        1. Insertion Sort Algorithm
        2. First Iteration
        3. Second Iteration
        4. Third Iteration and Beyond
        5. Function Template insertionSort
        6. Big O: Efficiency of Insertion Sort
      2. 20.3.2 Selection Sort
        1. Selection Sort Algorithm
        2. First Iteration
        3. Second Iteration
        4. Third Iteration
        5. Function Template selectionSort
        6. Efficiency of Selection Sort
      3. 20.3.3 Merge Sort (A Recursive Implementation)
        1. Sample Merge
        2. Recursive Implementation
        3. Demonstrating Merge Sort
        4. Function mergeSort
        5. Function merge
        6. Efficiency of Merge Sort
        7. Summary of Searching and Sorting Algorithm Efficiencies
    6. 20.4 Wrap-Up
    7. Summary
    8. Self-Review Exercises
    9. Exercises
  32. 21 Class string and String Stream Processing: A Deeper
    1. Objectives
    2. Outline
    3. 21.1 Introduction1
    4. 21.2 string Assignment and Concatenation
    5. 21.3 Comparing strings
    6. 21.4 Substrings
    7. 21.5 Swapping strings
    8. 21.6 string Characteristics
    9. 21.7 Finding Substrings and Characters in a string
    10. 21.8 Replacing Characters in a string
    11. 21.9 Inserting Characters into a string
    12. 21.10 Conversion to Pointer-Based char* Strings
    13. 21.11 Iterators
    14. 21.12 String Stream Processing
    15. 21.13 C++11 Numeric Conversion Functions
    16. 21.14 Wrap-Up
    17. Summary
    18. Self-Review Exercises
    19. Exercises
    20. Making a Difference
  33. 22 Bits, Characters, C Strings and structs
    1. Objectives
    2. Outline
    3. 22.1 Introduction
    4. 22.2 Structure Definitions
    5. 22.3 typedef and using
    6. 22.4 Example: Card Shuffling and Dealing Simulation
    7. 22.5 Bitwise Operators
    8. 22.6 Bit Fields
    9. 22.7 Character-Handling Library
    10. 22.8 C String-Manipulation Functions
    11. 22.9 C String-Conversion Functions
    12. 22.10 Search Functions of the C String-Handling Library
    13. 22.11 Memory Functions of the C String-Handling Library
    14. 22.12 Wrap-Up
    15. Summary
    16. Self-Review Exercises
    17. Exercises
    18. Special Section: Advanced String-Manipulation Exercises
    19. Challenging String-Manipulation Projects
  34. Chapters on the Web
  35. A Operator Precedence and Associativity
  36. B ASCII Character Set
  37. C Fundamental Types
  38. D Number Systems
    1. Objectives
    2. Outline
    3. D.1 Introduction
    4. D.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
    5. D.3 Converting Octal and Hexadecimal Numbers to Binary Numbers
    6. D.4 Converting from Binary, Octal or Hexadecimal to Decimal
    7. D.5 Converting from Decimal to Binary, Octal or Hexadecimal
    8. D.6 Negative Binary Numbers: Two&#8217;s Complement NotationNegative Binary Numbers: Two’s Complement Notation
    9. Summary
    10. Self-Review Exercises
    11. Answers to Self-Review Exercises
    12. Exercises
  39. E Preprocessor
    1. Objectives
    2. Outline
    3. E.1 Introduction
    4. E.2 #include Preprocessing Directive
    5. E.3 #define Preprocessing Directive: Symbolic Constants
    6. E.4 #define Preprocessing Directive: Macros
    7. E.5 Conditional Compilation
    8. E.6 #error and #pragma Preprocessing Directives
    9. E.7 Operators # and ##
    10. E.8 Predefined Symbolic Constants
    11. E.9 Assertions
    12. E.10 Wrap-Up
    13. Summary
    14. Self-Review Exercises
    15. Answers to Self-Review Exercises
    16. Exercises
  40. Appendices on the Web
  41. Index
    1. Symbols
    2. Numerics
    3. A
    4. B
    5. C
    6. D
    7. E
    8. F
    9. G
    10. H
    11. I
    12. J
    13. K
    14. L
    15. M
    16. N
    17. O
    18. P
    19. Q
    20. R
    21. S
    22. T
    23. U
    24. V
    25. W
    26. X
    27. Y
    28. Z