Home Page Icon
Home Page
Table of Contents for
Features
Close
Features
by Harvey M. Deitel, Abbey Deitel, Paul J. Deitel
C++11 for Programmers, Second Edition
Title Page
Copyright Page
Dedication Page
Contents
Preface
Features
C++11 Standard
Object-Oriented Programming
Pedagogic Features
Other Features
Secure C++ Programming
Training Approach
Online Chapter and Appendices
Obtaining the Software Used in C++11 for Programmers
C++11 Fundamentals: Parts I, II, III and IV LiveLessons Video Training Product
Acknowledgments
Reviewers
About the Authors
Deitel® Dive-Into® Series Corporate Training
1. Introduction
1.1. Introduction
1.2. C++
C++ Standard Library
1.3. Object Technology
The Automobile as an Object
Member Functions and Classes
Instantiation
Reuse
Messages and Member Function Calls
Attributes and Data Members
Encapsulation
Inheritance
Object-Oriented Analysis and Design (OOAD)
The UML (Unified Modeling Language)
1.4. Typical C++ Development Environment
Phase 1: Editing a Program
Phase 2: Preprocessing a C++ Program
Phase 3: Compiling a C++ Program
Phase 4: Linking
Phase 5: Loading
Phase 6: Execution
Problems That May Occur at Execution Time
1.5. Test-Driving a C++ Application
Running a C++ Application from the Windows Command Prompt
Running a C++ Application Using GNU C++ with Linux
1.6. Operating Systems
1.6.1. Windows—A Proprietary Operating System
1.6.2. Linux—An Open-Source Operating System
1.6.3. Apple’s OS X; Apple’s iOS for iPhone®, iPad® and iPod Touch® Devices
1.6.4. Google’s Android
1.7. C++11 and the Open Source Boost Libraries
Boost C++ Libraries
1.8. Web Resources
Deitel & Associates Websites
2. Introduction to C++ Programming, Input/Output and Operators
2.1. Introduction
Compiling and Running Programs
2.2. First Program in C++: Printing a Line of Text
Comments
#include Preprocessing Directive
Blank Lines and White Space
The main Function
An Output Statement
The std Namespace
The Stream Insertion Operator and Escape Sequences
The return Statement
2.3. Modifying Our First C++ Program
Printing a Single Line of Text with Multiple Statements
Printing Multiple Lines of Text with a Single Statement
2.4. Another C++ Program: Adding Integers
Variable Declarations
Fundamental Types
Identifiers
Placement of Variable Declarations
Obtaining the First Value from the User
Obtaining the Second Value from the User
Calculating the Sum of the Values Input by the User
Displaying the Result
2.5. Arithmetic
Arithmetic Expressions in Straight-Line Form
Parentheses for Grouping Subexpressions
Rules of Operator Precedence
Sample Algebraic and C++ Expressions
Evaluation of a Second-Degree Polynomial
Redundant Parentheses
2.6. Decision Making: Equality and Relational Operators
Using the if Statement
using Declarations
Variable Declarations and Reading the Inputs from the User
Comparing Numbers
White Space
Operator Precedence
2.7. Wrap-Up
3. Introduction to Classes, Objects and Strings
3.1. Introduction
3.2. Defining a Class with a Member Function
Class GradeBook
Testing Class GradeBook
UML Class Diagram for Class GradeBook
3.3. Defining a Member Function with a Parameter
Defining and Testing Class GradeBook
More on Arguments and Parameters
Updated UML Class Diagram for Class GradeBook
3.4. Data Members, set Member Functions and get Member Functions
GradeBook Class with a Data Member, and set and get Member Functions
Access Specifiers public and private
Member Functions setCourseName and getCourseName
Member Function displayMessage
Testing Class GradeBook
Software Engineering with Set and Get Functions
GradeBook’s UML Class Diagram with a Data Member and set and get Functions
3.5. Initializing Objects with Constructors
Defining a Constructor
Testing Class GradeBook
Ways to Provide a Default Constructor for a Class
Adding the Constructor to Class GradeBook’s UML Class Diagram
3.6. Placing a Class in a Separate File for Reusability
Headers
Use std:: with Standard Library Components in Headers
Including a Header That Contains a User-Defined Class
How Headers Are Located
Additional Software Engineering Issues
3.7. Separating Interface from Implementation
Interface of a Class
Separating the Interface from the Implementation
GradeBook.h: Defining a Class’s Interface with Function Prototypes
GradeBook.cpp: Defining Member Functions in a Separate Source-Code File
Testing Class GradeBook
The Compilation and Linking Process
3.8. Validating Data with set Functions
GradeBook Class Definition
Validating the Course Name with GradeBook Member Function setCourseName
Testing Class GradeBook
Additional Notes on Set Functions
3.9. Wrap-Up
4. Control Statements: Part 1; Assignment, ++ and -- Operators
4.1. Introduction
4.2. Control Structures
Sequence Structure in C++
Selection Statements in C++
Repetition Statements in C++
Summary of Control Statements in C++
4.3. if Selection Statement
4.4. if...else Double-Selection Statement
Conditional Operator (?:)
Nested if...else Statements
Dangling-else Problem
Blocks
4.5. while Repetition Statement
4.6. Counter-Controlled Repetition
Enhancing GradeBook Validation
Implementing Counter-Controlled Repetition in Class GradeBook
Demonstrating Class GradeBook
Notes on Integer Division and Truncation
A Note About Arithmetic Overflow
A Deeper Look at Receiving User Input
4.7. Sentinel-Controlled Repetition
Implementing Sentinel-Controlled Repetition in Class GradeBook
Program Logic for Sentinel-Controlled Repetition vs. Counter-Controlled Repetition
Floating-Point Number Precision and Memory Requirements
Converting Between Fundamental Types Explicitly and Implicitly
Formatting for Floating-Point Numbers
A Note About Unsigned Integers
4.8. Nested Control Statements
Program That Solves Examination Results
C++11 List Initialization
4.9. Assignment Operators
4.10. Increment and Decrement Operators
4.11. Wrap-Up
5. Control Statements: Part 2; Logical Operators
5.1. Introduction
5.2. Essentials of Counter-Controlled Repetition
5.3. for Repetition Statement
for Statement Header Components
Off-By-One Errors
General Format of a for Statement
Comma-Separated Lists of Expressions
Expressions in the for Statement’s Header Are Optional
Increment Expression Acts Like a Standalone Statement
for Statement: Notes and Observations
for Statement UML Activity Diagram
5.4. Examples Using the for Statement
Application: Summing the Even Integers from 2 to 20
Application: Compound Interest Calculations
A Caution about Using Type float or double for Monetary Amounts
Using Stream Manipulators to Format Numeric Output
5.5. do...while Repetition Statement
do...while Statement UML Activity Diagram
Braces in a do...while Statement
5.6. switch Multiple-Selection Statement
GradeBook Class with switch Statement to Count A, B, C, D and F Grades
GradeBook Class Header
GradeBook Class Source-Code File
Reading Character Input
Entering the EOF Indicator
switch Statement Details
Providing a default Case
Ignoring Newline, Tab and Blank Characters in Input
Testing Class GradeBook
switch Statement UML Activity Diagram
Notes on Data Types
C++11 In-Class Initializers
5.7. break and continue Statements
break Statement
continue Statement
5.8. Logical Operators
Logical AND (&&) Operator
Logical OR (||) Operator
Logical Negation (!) Operator
Logical Operators Example
Summary of Operator Precedence and Associativity
5.9. Confusing the Equality (==) and Assignment (=) Operators
lvalues and rvalues
5.10. Wrap-Up
6. Functions and an Introduction to Recursion
6.1. Introduction
6.2. Math Library Functions
6.3. Function Definitions with Multiple Parameters
Function Prototype for maximum
Logic of Function maximum
Returning Control from a Function to Its Caller
6.4. Function Prototypes and Argument Coercion
Function Signatures
Argument Coercion
Argument Promotion Rules and Implicit Conversions1
Conversions Can Result in Incorrect Values
6.5. C++ Standard Library Headers
6.6. Case Study: Random Number Generation
Rolling a Six-Sided Die
Rolling a Six-Sided Die 6,000,000 Times
Randomizing the Random Number Generator
Seeding the Random Number Generator with srand
Seeding the Random Number Generator with the Current Time
Scaling and Shifting Random Numbers
6.7. Case Study: Game of Chance; Introducing enum
enum Type Status
Winning or Losing on the First Roll
Continuing to Roll
C++11—Scoped enums
C++11—Specifying the Type of an enum’s Constants
6.8. C++11 Random Numbers
Rolling a Six-Sided Die
6.9. Storage Classes and Storage Duration
Storage Duration
Scope
Linkage
Storage Duration
Local Variables and Automatic Storage Duration
Register Variables
Static Storage Duration
Identifiers with Static Storage Duration
static Local Variables
6.10. Scope Rules
Block Scope
Function Scope
Global Namespace Scope
Function-Prototype Scope
Scope Demonstration
6.11. Function Call Stack and Activation Records
Function-Call Stack
Stack Frames
Automatic Variables and Stack Frames
Stack Overflow
Function Call Stack in Action
6.12. Functions with Empty Parameter Lists
6.13. Inline Functions
6.14. References and Reference Parameters
Reference Parameters
Passing Arguments by Value and by Reference
References as Aliases within a Function
Returning a Reference from a Function
6.15. Default Arguments
6.16. Unary Scope Resolution Operator
6.17. Function Overloading
Overloaded square Functions
How the Compiler Differentiates Among Overloaded Functions
Overloaded Operators
6.18. Function Templates
C++11—Trailing Return Types for Functions
6.19. Recursion
Recursion Concepts
Factorial
Iterative Factorial
Recursive Factorial
Evaluating 5!
Using a Recursive factorial Function to Calculate Factorials
Why We Chose Type unsigned long in This Example
C++11 Type unsigned long long int
Representing Even Larger Numbers
6.20. Example Using Recursion: Fibonacci Series
Recursive Fibonacci Definition
Evaluating fibonacci(3)
Order of Evaluation of Operands
Exponential Complexity
6.21. Recursion vs. Iteration
Iterative Factorial Implementation
Negatives of Recursion
6.22. Wrap-Up
7. Class Templates array and vector; Catching Exceptions
7.1. Introduction
7.2. arrays
7.3. Declaring arrays
7.4. Examples Using arrays
7.4.1. Declaring an array and Using a Loop to Initialize the array’s Elements
7.4.2. Initializing an array in a Declaration with an Initializer List
7.4.3. Specifying an array’s Size with a Constant Variable and Setting array Elements with Calculations
7.4.4. Summing the Elements of an array
7.4.5. Using Bar Charts to Display array Data Graphically
7.4.6. Using the Elements of an array as Counters
7.4.7. Using arrays to Summarize Survey Results
7.4.8. Static Local arrays and Automatic Local arrays
7.5. Range-Based for Statement
Using the Range-Based for to Display an array’s Contents
Using the Range-Based for to Modify an array’s Contents
Using an Element’s Subscript
7.6. Case Study: Class GradeBook Using an array to Store Grades
Storing Student Grades in an array in Class GradeBook
Constructor
Member Function processGrades
Member Function getAverage
Member Functions getMinimum and getMaximum
Member Function outputBarChart
Testing Class GradeBook
7.7. Sorting and Searching arrays
Sorting
Searching
Demonstrating Functions sort and binary_search
7.8. Multidimensional arrays
Nested Range-Based for Statements
Nested Counter-Controlled for Statements
Other Common array Manipulations
7.9. Case Study: Class GradeBook Using a Two-Dimensional array
Storing Student Grades in a Two-Dimensional array in Class GradeBook
Overview of Class GradeBook’s Functions
Functions getMinimum and getMaximum
Function outputBarChart
Function outputGrades
Function getAverage
Testing Class GradeBook
7.10. Introduction to C++ Standard Library Class Template vector
Creating vector Objects
vector Member Function size; Function outputVector
Function inputVector
Comparing vector Objects for Inequality
Initializing One vector with the Contents of Another
Assigning vectors and Comparing vectors for Equality
Using the [] Operator to Access and Modify vector Elements
Exception Handling: Processing an Out-of-Range Subscript
The try Statement
Executing the catch Block
what Member Function of the Exception Parameter
Changing the Size of a vector
C++11: List Initializing a vector
7.11. Wrap-Up
8. Pointers
8.1. Introduction
8.2. Pointer Variable Declarations and Initialization
Indirection
Declaring Pointers
Initializing Pointers
Null Pointers Prior to C++11
8.3. Pointer Operators
Address (&) Operator
Indirection (*) Operator
Using the Address (&) and Indirection (*) Operators
Precedence and Associativity of the Operators Discussed So Far
8.4. Pass-by-Reference with Pointers
An Example of Pass-By-Value
An Example of Pass-By-Reference with Pointers
Insight: All Arguments Are Passed By Value
Graphical Analysis of Pass-By-Value and Pass-By-Reference
8.5. Built-In Arrays
Declaring a Built-In Array
Accessing a Built-In Array’s Elements
Initializing Built-In Arrays
Passing Built-In Arrays to Functions
Declaring Built-In Array Parameters
C++11: Standard Library Functions begin and end
Built-In Array Limitations
Sometimes Built-In Arrays Are Required
8.6. Using const with Pointers
8.6.1. Nonconstant Pointer to Nonconstant Data
8.6.2. Nonconstant Pointer to Constant Data
8.6.3. Constant Pointer to Nonconstant Data
8.6.4. Constant Pointer to Constant Data
8.7. sizeof Operator
Determining the Sizes of the Fundamental Types, a Built-In Array and a Pointer
8.8. Pointer Expressions and Pointer Arithmetic
Adding Integers to and Subtracting Integers from Pointers
Subtracting Pointers
Pointer Assignment
Cannot Dereference a void *
Comparing Pointers
8.9. Relationship Between Pointers and Built-In Arrays
Pointer/Offset Notation
Pointer/Offset Notation with the Built-In Array’s Name as the Pointer
Pointer/Subscript Notation
The Name of a Built-In Array Is Not Modifiable
Demonstrating the Relationship Between Pointers and Built-In Arrays
8.10. Pointer-Based Strings
Characters and Character Constants
Strings
Pointer-Based Strings
String Literals as Initializers
Character Constants as Initializers
Accessing Characters in a C String
Reading Strings into char Built-In Arrays with cin
Reading Lines of Text into char Built-In Arrays with cin.getline
Displaying C Strings
8.11. Wrap-Up
9. Classes: A Deeper Look; Throwing Exceptions
9.1. Introduction
9.2. Time Class Case Study
Time Class Definition
Time Class Member Functions
Time Class Member Function setTime and Throwing Exceptions
Time Class Member Function printUniversal
Time Class Member Function printStandard
Defining Member Functions Outside the Class Definition; Class Scope
Member Functions vs. Global Functions (Also Called Free Functions)
Using Class Time
Calling setTime with Invalid Values
Looking Ahead to Composition and Inheritance
Object Size
9.3. Class Scope and Accessing Class Members
Class Scope and Block Scope
Dot (.) and Arrow (->) Member Selection Operators
Accessing public Class Members Through Objects, References and Pointers
9.4. Access Functions and Utility Functions
Access Functions
Utility Functions
9.5. Time Class Case Study: Constructors with Default Arguments
Notes Regarding Class Time’s Set and Get Functions and Constructor
C++11: Using List Initializers to Call Constructors
C++11: Overloaded Constructors and Delegating Constructors
9.6. Destructors
9.7. When Constructors and Destructors Are Called
Constructors and Destructors for Objects in Global Scope
Constructors and Destructors for Local Objects
Constructors and Destructors for static Local Objects
Demonstrating When Constructors and Destructors Are Called
9.8. Time Class Case Study: A Subtle Trap—Returning a Reference or a Pointer to a private Data Member
9.9. Default Memberwise Assignment
9.10. const Objects and const Member Functions
Using const and Non-const Member Functions
9.11. Composition: Objects as Members of Classes
Employee Constructor’s Member Initializer List
Date Class’s Default Copy Constructor
Testing Classes Date and Employee
What Happens When You Do Not Use the Member Initializer List?
9.12. friend Functions and friend Classes
Declaring a friend
Modifying a Class’s private Data with a Friend Function
Overloaded friend Functions
9.13. Using the this Pointer
Using the this Pointer to Avoid Naming Collisions
Type of the this Pointer
Implicitly and Explicitly Using the this Pointer to Access an Object’s Data Members
Using the this Pointer to Enable Cascaded Function Calls
9.14. static Class Members
Motivating Class-Wide Data
Scope and Initialization of static Data Members
Accessing static Data Members
Demonstrating static Data Members
9.15. Wrap-Up
10. Operator Overloading; Class string
10.1. Introduction
10.2. Using the Overloaded Operators of Standard Library Class string
10.3. Fundamentals of Operator Overloading
Operators That Cannot Be Overloaded
Rules and Restrictions on Operator Overloading
10.4. Overloading Binary Operators
Binary Overloaded Operators as Member Functions
Binary Overloaded Operators as Non-Member Functions
10.5. Overloading the Binary Stream Insertion and Stream Extraction Operators
Overloading the Stream Extraction (>>) Operator
Overloading the Stream Insertion (<<) Operator
Overloaded Operators as Non-Member friend Functions
Why Overloaded Stream Insertion and Stream Extraction Operators Are Overloaded as Non-Member Functions
10.6. Overloading Unary Operators
Unary Overloaded Operators as Member Functions
Unary Overloaded Operators as Non-Member Functions
10.7. Overloading the Unary Prefix and Postfix ++ and -- Operators
Overloading the Prefix Increment Operator
Overloading the Postfix Increment Operator
10.8. Case Study: A Date Class
Date Class Prefix Increment Operator
Date Class Postfix Increment Operator
10.9. Dynamic Memory Management
Obtaining Dynamic Memory with new
Releasing Dynamic Memory with delete
Initializing Dynamic Memory
Dynamically Allocating Built-In Arrays with new []
C++11: Using a List Initializer with a Dynamically Allocated Built-In Array
Releasing Dynamically Allocated Built-In Arrays with delete []
C++11: Managing Dynamically Allocated Memory with unique_ptr
10.10. Case Study: Array Class
10.10.1. Using the Array Class
10.10.2. Array Class Definition
10.11. Operators as Member vs. Non-Member Functions
Commutative Operators
10.12. Converting Between Types
Conversion Operators
Overloaded Cast Operator Functions
Implicit Calls to Cast Operators and Conversion Constructors
10.13. explicit Constructors and Conversion Operators
Accidentally Using a Single-Argument Constructor as a Conversion Constructor
Preventing Implicit Conversions with Single-Argument Constructors
C++11: explicit Conversion Operators
10.14. Overloading the Function Call Operator ()
10.15. Wrap-Up
11. Object-Oriented Programming: Inheritance
11.1. Introduction
11.2. Base Classes and Derived Classes
CommunityMember Class Hierarchy
Shape Class Hierarchy
11.3. Relationship between Base and Derived Classes
11.3.1. Creating and Using a CommissionEmployee Class
11.3.2. Creating a BasePlusCommissionEmployee Class Without Using Inheritance
11.3.3. Creating a CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy
11.3.4. CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using protected Data
11.3.5. CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Data
11.4. Constructors and Destructors in Derived Classes
C++11: Inheriting Base Class Constructors
11.5. public, protected and private Inheritance
11.6. Software Engineering with Inheritance
11.7. Wrap-Up
12. Object-Oriented Programming: Polymorphism
12.1. Introduction
Implementing for Extensibility
Optional Discussion of Polymorphism “Under the Hood”
12.2. Introduction to Polymorphism: Polymorphic Video Game
12.3. Relationships Among Objects in an Inheritance Hierarchy
12.3.1. Invoking Base-Class Functions from Derived-Class Objects
12.3.2. Aiming Derived-Class Pointers at Base-Class Objects
12.3.3. Derived-Class Member-Function Calls via Base-Class Pointers
12.3.4. Virtual Functions and Virtual Destructors
12.4. Type Fields and switch Statements
12.5. Abstract Classes and Pure virtual Functions
Pure Virtual Functions
Device Drivers and Polymorphism
12.6. Case Study: Payroll System Using Polymorphism
12.6.1. Creating Abstract Base Class Employee
12.6.2. Creating Concrete Derived Class SalariedEmployee
12.6.3. Creating Concrete Derived Class CommissionEmployee
12.6.4. Creating Indirect Concrete Derived Class BasePlusCommissionEmployee
12.6.5. Demonstrating Polymorphic Processing
12.7. (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”
Employee Class vtable
SalariedEmployee Class vtable
CommissionEmployee Class vtable
BasePlusCommissionEmployee Class vtable
Inheriting Concrete virtual Functions
Three Levels of Pointers to Implement Polymorphism
12.8. Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info
Determining an Object’s Type with dynamic_cast
Calculating the Current Employee’s Earnings
Displaying an Employee’s Type
Compilation Errors That We Avoided By Using dynamic_cast
12.9. Wrap-Up
13. Stream Input/Output: A Deeper Look
13.1. Introduction
13.2. Streams
13.2.1. Classic Streams vs. Standard Streams
13.2.2. iostream Library Headers
13.2.3. Stream Input/Output Classes and Objects
13.3. Stream Output
13.3.1. Output of char * Variables
13.3.2. Character Output Using Member Function put
13.4. Stream Input
13.4.1. get and getline Member Functions
13.4.2. istream Member Functions peek, putback and ignore
13.4.3. Type-Safe I/O
13.5. Unformatted I/O Using read, write and gcount
13.6. Introduction to Stream Manipulators
13.6.1. Integral Stream Base: dec, oct, hex and setbase
13.6.2. Floating-Point Precision (precision, setprecision)
13.6.3. Field Width (width, setw)
13.6.4. User-Defined Output Stream Manipulators
13.7. Stream Format States and Stream Manipulators
13.7.1. Trailing Zeros and Decimal Points (showpoint)
13.7.2. Justification (left, right and internal)
13.7.3. Padding (fill, setfill)
13.7.4. Integral Stream Base (dec, oct, hex, showbase)
13.7.5. Floating-Point Numbers; Scientific and Fixed Notation (scientific, fixed)
13.7.6. Uppercase/Lowercase Control (uppercase)
13.7.7. Specifying Boolean Format (boolalpha)
13.7.8. Setting and Resetting the Format State via Member Function flags
13.8. Stream Error States
13.9. Tying an Output Stream to an Input Stream
13.10. Wrap-Up
14. File Processing
14.1. Introduction
14.2. Files and Streams
File-Processing Class Templates
14.3. Creating a Sequential File
Opening a File
Opening a File via the open Member Function
Testing Whether a File Was Opened Successfully
The Overloaded void * Operator
Processing Data
Closing a File
The Sample Execution
14.4. Reading Data from a Sequential File
Opening a File for Input
Ensuring That the File Was Opened
Reading from the File
File Position Pointers
Credit Inquiry Program
14.5. Updating Sequential Files
14.6. Random-Access Files
14.7. Creating a Random-Access File
Writing Bytes with ostream Member Function write
Converting Between Pointer Types with the reinterpret_cast Operator
Credit Processing Program
Opening a File for Output in Binary Mode
14.8. Writing Data Randomly to a Random-Access File
Opening a File for Input and Output in Binary Mode
Positioning the File Position Pointer
14.9. Reading from a Random-Access File Sequentially
14.10. Case Study: A Transaction-Processing Program
14.11. Object Serialization
14.12. Wrap-Up
15. Standard Library Containers and Iterators
15.1. Introduction
Containers, Iterators and Algorithms
Common Member Functions Among Containers
Iterators
Algorithms
Custom Templatized Data Structures
15.2. Introduction to Containers
Containers Overview
Near Containers
Common Container Functions
First-Class Container Common Nested Types
Requirements for Container Elements
15.3. Introduction to Iterators
Using istream_iterator for Input and ostream_iterator for Output
istream_iterator
ostream_iterator
Iterator Categories and Iterator Category Hierarchy
Container Support for Iterators
Predefined Iterator typedefs
Iterator Operations
15.4. Introduction to Algorithms
15.5. Sequence Containers
Performance and Choosing the Appropriate Container
15.5.1. vector Sequence Container
15.5.2. list Sequence Container
15.5.3. deque Sequence Container
15.6. Associative Containers
15.6.1. multiset Associative Container
15.6.2. set Associative Container
15.6.3. multimap Associative Container
15.6.4. map Associative Container
15.7. Container Adapters
15.7.1. stack Adapter
15.7.2. queue Adapter
15.7.3. priority_queue Adapter
15.8. Class bitset
15.9. Wrap-Up
Recommended Reading
16. Standard Library Algorithms
16.1. Introduction
16.2. Minimum Iterator Requirements
Iterator Invalidation
16.3. Algorithms
16.3.1. fill, fill_n, generate and generate_n
16.3.2. equal, mismatch and lexicographical_compare
16.3.3. remove, remove_if, remove_copy and remove_copy_if
16.3.4. replace, replace_if, replace_copy and replace_copy_if
16.3.5. Mathematical Algorithms
16.3.6. Basic Searching and Sorting Algorithms
16.3.7. swap, iter_swap and swap_ranges
16.3.8. copy_backward, merge, unique and reverse
16.3.9. inplace_merge, unique_copy and reverse_copy
16.3.10. Set Operations
16.3.11. lower_bound, upper_bound and equal_range
16.3.12. Heapsort
16.3.13. min, max, minmax and minmax_element
16.4. Function Objects
Advantages of Function Objects Over Function Pointers
Predefined Function Objects of the Standard Template Library
Using the accumulate Algorithm
Function sumSquares
Class SumSquaresClass
Passing Function Pointers and Function Objects to Algorithm accumulate
16.5. Lambda Expressions
16.6. Standard Library Algorithm Summary
Mutating Sequence Algorithms
Nonmodifying Sequence Algorithms
Sorting and Related Algorithms
Numerical Algorithms
16.7. Wrap-Up
17. Exception Handling: A Deeper Look
17.1. Introduction
17.2. Example: Handling an Attempt to Divide by Zero
Defining an Exception Class to Represent the Type of Problem That Might Occur
Demonstrating Exception Handling
Enclosing Code in a try Block
Defining a catch Handler to Process a DivideByZeroException
Termination Model of Exception Handling
Flow of Program Control When the User Enters a Nonzero Denominator
Flow of Program Control When the User Enters a Denominator of Zero
17.3. Rethrowing an Exception
17.4. Stack Unwinding
17.5. When to Use Exception Handling
C++11: Declaring Functions That Do Not Throw Exceptions
17.6. Constructors, Destructors and Exception Handling
Initializing Local Objects to Acquire Resources
17.7. Exceptions and Inheritance
17.8. Processing new Failures
new Throwing bad_alloc on Failure
new Returning nullptr on Failure
Handling new Failures Using Function set_new_handler
17.9. Class unique_ptr and Dynamic Memory Allocation
unique_ptr Notes
unique_ptr to a Built-In Array
17.10. Standard Library Exception Hierarchy
17.11. Wrap-Up
18. Introduction to Custom Templates
18.1. Introduction
18.2. Class Templates
Creating Class Template Stack<T>
Class Template Stack<T>’s Data Representation
Class Template Stack<T>’s Member Functions
Declaring a Class Template’s Member Functions Outside the Class Template Definition
Testing Class Template Stack<T>
18.3. Function Template to Manipulate a Class-Template Specialization Object
18.4. Nontype Parameters
18.5. Default Arguments for Template Type Parameters
18.6. Overloading Function Templates
Matching Process for Overloaded Functions
18.7. Wrap-Up
19. Class string and String Stream Processing: A Deeper Look
19.1. Introduction
Initializing a string Object
strings Are Not Necessarily Null Terminated
Length of a string
Processing strings
string I/O
Validating Input
19.2. string Assignment and Concatenation
19.3. Comparing strings
19.4. Substrings
19.5. Swapping strings
19.6. string Characteristics
19.7. Finding Substrings and Characters in a string
19.8. Replacing Characters in a string
19.9. Inserting Characters into a string
19.10. Conversion to Pointer-Based char * Strings
19.11. Iterators
19.12. String Stream Processing
Demonstrating ostringstream
Demonstrating istringstream
19.13. C++11 Numeric Conversion Functions
Converting Numeric Values to string Objects
Converting string Objects to Numeric Values
Functions That Convert strings to Integral Types
Functions That Convert strings to Floating-Point Types
19.14. Wrap-Up
20. Bits, Characters, C Strings and structs
20.1. Introduction
20.2. Structure Definitions
20.3. typedef
20.4. Example: Card Shuffling and Dealing Simulation
20.5. Bitwise Operators
Printing a Binary Representation of an Integral Value
Bitwise AND Operator (&)
Bitwise Inclusive OR Operator (|)
Bitwise Exclusive OR (^)
Bitwise Complement (~)
Bitwise Shift Operators
Left-Shift Operator
Right-Shift Operator
Bitwise Assignment Operators
20.6. Bit Fields
20.7. Character-Handling Library
20.8. C String-Manipulation Functions
Copying Strings with strcpy and strncpy
Concatenating Strings with strcat and strncat
Comparing Strings with strcmp and strncmp
Tokenizing a String with strtok
Determining String Lengths
20.9. C String-Conversion Functions
20.10. Search Functions of the C String-Handling Library
20.11. Memory Functions of the C String-Handling Library
20.12. Wrap-Up
21. Other Topics
21.1. Introduction
21.2. const_cast Operator
21.3. mutable Class Members
Mechanical Demonstration of a mutable Data Member
21.4. namespaces
Defining namespaces
Accessing namespace Members with Qualified Names
using Directives Should Not Be Placed in Headers
Aliases for namespace Names
21.5. Operator Keywords
21.6. Pointers to Class Members (.* and ->*)
21.7. Multiple Inheritance
Resolving Ambiguity Issues That Arise When a Derived Class Inherits Member Functions of the Same Name from Multiple Base Classes
Demonstrating the Is-A Relationships in Multiple Inheritance
21.8. Multiple Inheritance and virtual Base Classes
Compilation Errors Produced When Ambiguity Arises in Diamond Inheritance
Eliminating Duplicate Subobjects with virtual Base-Class Inheritance
Constructors in Multiple-Inheritance Hierarchies with virtual Base Classes
21.9. Wrap-Up
22. ATM Case Study, Part 1: Object-Oriented Design with the UML
22.1. Introduction
22.2. Introduction to Object-Oriented Analysis and Design
22.3. Examining the ATM Requirements Document
Requirements Document
Analyzing the ATM System
Use Case Diagrams
Designing the ATM System
Web Resources
Self-Review Exercises for Section 22.3
22.4. Identifying the Classes in the ATM Requirements Document
Identifying the Classes in a System
Modeling Classes
Self-Review Exercises for Section 22.4
22.5. Identifying Class Attributes
Identifying Attributes
Modeling Attributes
Self-Review Exercises for Section 22.5
22.6. Identifying Objects’ States and Activities
State Machine Diagrams
Activity Diagrams
Self-Review Exercises for Section 22.6
22.7. Identifying Class Operations
Identifying Operations
Modeling Operations
Operations of Class BankDatabase and Class Account
Operations of Class Screen
Operations of Class Keypad
Operations of Class CashDispenser and Class DepositSlot
Operations of Class ATM
Identifying and Modeling Operation Parameters
Self-Review Exercises for Section 22.7
22.8. Indicating Collaboration Among Objects
Identifying the Collaborations in a System
Interaction Diagrams
Communication Diagrams
Sequence of Messages in a Communication Diagram
Sequence Diagrams
Self-Review Exercises for Section 22.8
22.9. Wrap-Up
Answers to Self-Review Exercises
23. ATM Case Study, Part 2: Implementing an Object-Oriented Design
23.1. Introduction
23.2. Starting to Program the Classes of the ATM System
Visibility
Navigability
Implementing the ATM System from Its UML Design
Self-Review Exercises for Section 23.2
23.3. Incorporating Inheritance into the ATM System
Processing Transactions Polymorphically
Additional Attribute of Classes Withdrawal and Deposit
Class Diagram with Transaction Hierarchy Incorporated
Implementing the ATM System Design Incorporating Inheritance
ATM Case Study Wrap-Up
Self-Review Exercises for Section 23.3
23.4. ATM Case Study Implementation
23.4.1. Class ATM
23.4.2. Class Screen
23.4.3. Class Keypad
23.4.4. Class CashDispenser
23.4.5. Class DepositSlot
23.4.6. Class Account
23.4.7. Class BankDatabase
23.4.8. Class Transaction
23.4.9. Class BalanceInquiry
23.4.10. Class Withdrawal
23.4.11. Class Deposit
23.4.12. Test Program ATMCaseStudy.cpp
23.5. Wrap-Up
Answers to Self-Review Exercises
A. Operator Precedence and Associativity
B. ASCII Character Set
C. Fundamental Types
D. Number Systems
D.1. Introduction
D.2. Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
D.3. Converting Octal and Hexadecimal Numbers to Binary Numbers
D.4. Converting from Binary, Octal or Hexadecimal to Decimal
D.5. Converting from Decimal to Binary, Octal or Hexadecimal
D.6. Negative Binary Numbers: Two’s Complement Notation
E. Preprocessor
E.1. Introduction
E.2. #include Preprocessing Directive
E.3. #define Preprocessing Directive: Symbolic Constants
E.4. #define Preprocessing Directive: Macros
E.5. Conditional Compilation
E.6. #error and #pragma Preprocessing Directives
E.7. Operators # and ##
E.8. Predefined Symbolic Constants
E.9. Assertions
E.10. Wrap-Up
Index
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Preface
Next
Next Chapter
C++11 Standard
Features
Here are the key features of
C++11 for Programmers
.
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset