| |
| |
Preface | |
| |
| |
| |
C++ Fundamentals | |
| |
| |
A Brief History of C++ | |
| |
| |
C: The Beginning of the Modern Age of Programming | |
| |
| |
The Need for C++ | |
| |
| |
C++ Is Born | |
| |
| |
The Evolution of C++ | |
| |
| |
How C++ Relates to Java and C# | |
| |
| |
Object-Oriented Programming | |
| |
| |
Encapsulation | |
| |
| |
Polymorphism | |
| |
| |
Inheritance | |
| |
| |
A First Simple Program | |
| |
| |
Entering the Program | |
| |
| |
Compiling the Program | |
| |
| |
Run the Program | |
| |
| |
The First Sample Program Line by Line | |
| |
| |
Handling Syntax Errors | |
| |
| |
A Second Simple Program | |
| |
| |
Using an Operator | |
| |
| |
Reading Input from the Keyboard | |
| |
| |
Some Output Options | |
| |
| |
Another Data Type | |
| |
| |
| |
Converting Feet to Meters | |
| |
| |
Two Control Statements | |
| |
| |
The if Statement | |
| |
| |
The for Loop | |
| |
| |
Using Blocks of Code | |
| |
| |
Semicolons and Positioning | |
| |
| |
Indentation Practices | |
| |
| |
| |
Generating a Table of Feet to Meter Conversions | |
| |
| |
Introducing Functions | |
| |
| |
The C++ Libraries | |
| |
| |
The C++ Keywords | |
| |
| |
Identifiers | |
| |
| |
Module 1 Mastery Check | |
| |
| |
| |
Introducing Data Types and Operators | |
| |
| |
Why Data Types Are Important | |
| |
| |
The C++ Data Types | |
| |
| |
Integers | |
| |
| |
Characters | |
| |
| |
Floating-Point Types | |
| |
| |
The bool Type | |
| |
| |
void | |
| |
| |
| |
Talking to Mars | |
| |
| |
Literals | |
| |
| |
Hexadecimal and Octal Literals | |
| |
| |
String Literals | |
| |
| |
Character Escape Sequences | |
| |
| |
A Closer Look at Variables | |
| |
| |
Initializing a Variable | |
| |
| |
Dynamic Initialization | |
| |
| |
Operators | |
| |
| |
Arithmetic Operators | |
| |
| |
Increment and Decrement | |
| |
| |
Relational and Logical Operators | |
| |
| |
| |
Construct an XOR Logical Operation | |
| |
| |
The Assignment Operator | |
| |
| |
Compound Assignments | |
| |
| |
Type Conversion in Assignments | |
| |
| |
Expressions | |
| |
| |
Type Conversion in Expressions | |
| |
| |
Casts | |
| |
| |
Spacing and Parentheses | |
| |
| |
| |
Compute the Regular Payments on a Loan | |
| |
| |
Module 2 Mastery Check | |
| |
| |
| |
Program Control Statements | |
| |
| |
The if Statement | |
| |
| |
The Conditional Expression | |
| |
| |
Nested ifs | |
| |
| |
The if-else-if Ladder | |
| |
| |
The switch Statement | |
| |
| |
Nested switch Statements | |
| |
| |
| |
Start Building a C++ Help System | |
| |
| |
The for Loop | |
| |
| |
Some Variations on the for Loop | |
| |
| |
Missing Pieces | |
| |
| |
The Infinite for Loop | |
| |
| |
Loops with No Body | |
| |
| |
Declaring Loop Control Variables Inside the for Loop | |
| |
| |
The while Loop | |
| |
| |
The do-while Loop | |
| |
| |
| |
Improve the C++ Help System | |
| |
| |
Using break to Exit a Loop | |
| |
| |
Using continue | |
| |
| |
| |
Finish the C++ Help System | |
| |
| |
Nested Loops | |
| |
| |
Using the goto Statement | |
| |
| |
Module 3 Mastery Check | |
| |
| |
| |
Arrays, Strings, and Pointers | |
| |
| |
One-Dimensional Arrays | |
| |
| |
No Bounds Checking | |
| |
| |
Two-Dimensional Arrays | |
| |
| |
Multidimensional Arrays | |
| |
| |
| |
Sorting an Array | |
| |
| |
Strings | |
| |
| |
String Fundamentals | |
| |
| |
Reading a String from the Keyboard | |
| |
| |
Some String Library Functions | |
| |
| |
strcpy | |
| |
| |
strcat | |
| |
| |
strcmp | |
| |
| |
strlen | |
| |
| |
A String Function Example | |
| |
| |
Using the Null Terminator | |
| |
| |
Array Initialization | |
| |
| |
Unsized Array Initializations | |
| |
| |
Arrays of Strings | |
| |
| |
Pointers | |
| |
| |
What Are Pointers? | |
| |
| |
The Pointer Operators | |
| |
| |
The Base Type of a Pointer Is Important | |
| |
| |
Assigning Values Through a Pointer | |
| |
| |
Pointer Expressions | |
| |
| |
Pointer Arithmetic | |
| |
| |
Pointer Comparisons | |
| |
| |
Pointers and Arrays | |
| |
| |
Indexing a Pointer | |
| |
| |
String Constants | |
| |
| |
| |
Reversing a String in Place | |
| |
| |
Arrays of Pointers | |
| |
| |
The Null Pointer Convention | |
| |
| |
Multiple Indirection | |
| |
| |
Module 4 Mastery Check | |
| |
| |
| |
Introducing Functions | |
| |
| |
Function Fundamentals | |
| |
| |
The General Form of a Function | |
| |
| |
Creating a Function | |
| |
| |
Using Arguments | |
| |
| |
Using return | |
| |
| |
Returning Values | |
| |
| |
Using Functions in Expressions | |
| |
| |
Scope Rules | |
| |
| |
Local Scope | |
| |
| |
Global Scope | |
| |
| |
Passing Pointers and Arrays to Functions | |
| |
| |
Passing a Pointer | |
| |
| |
Passing an Array | |
| |
| |
Passing Strings | |
| |
| |
Returning Pointers | |
| |
| |
The main() Function | |
| |
| |
Pass Command-Line Arguments to main() | |
| |
| |
Passing Numeric Command-Line Arguments | |
| |
| |
Function Prototypes | |
| |
| |
Headers Contain Prototypes | |
| |
| |
Recursion | |
| |
| |
| |
The Quicksort | |
| |
| |
Module 5 Mastery Check | |
| |
| |
| |
A Closer Look at Functions | |
| |
| |
Two Approaches to Argument Passing | |
| |
| |
How C++ Passes Arguments | |
| |
| |
Using a Pointer to Create a Call-by-Reference | |
| |
| |
Reference Parameters | |
| |
| |
Returning References | |
| |
| |
Independent References | |
| |
| |
A Few Restrictions When Using References | |
| |
| |
Function Overloading | |
| |
| |
Automatic Type Conversions and Overloading | |
| |
| |
| |
Create Overloaded Output Functions | |
| |
| |
Default Function Arguments | |
| |
| |
Default Arguments Versus Overloading | |
| |
| |
Using Default Arguments Correctly | |
| |
| |
Function Overloading and Ambiguity | |
| |
| |
Module 6 Mastery Check | |
| |
| |
| |
More Data Types and Operators | |
| |
| |
The const and volatile Qualifiers | |
| |
| |
const | |
| |
| |
volatile | |
| |
| |
Storage Class Specifiers | |
| |
| |
auto | |
| |
| |
extern | |
| |
| |
static Variables | |
| |
| |
register Variables | |
| |
| |
Enumerations | |
| |
| |
typedef | |
| |
| |
Bitwise Operators | |
| |
| |
AND, OR, XOR, and NOT | |
| |
| |
The Shift Operators | |
| |
| |
| |
Create Bitwise Rotation Functions | |
| |
| |
The ? Operator | |
| |
| |
The Comma Operator | |
| |
| |
Multiple Assignments | |
| |
| |
Compound Assignment | |
| |
| |
Using sizeof | |
| |
| |
Precedence Summary | |
| |
| |
Module 7 Mastery Check | |
| |
| |
| |
Classes and Objects | |
| |
| |
Class Fundamentals | |
| |
| |
The General Form of a Class | |
| |
| |
Defining a Class and Creating Objects | |
| |
| |
Adding Member Functions to a Class | |
| |
| |
| |
Creating a Help Class | |
| |
| |
Constructors and Destructors | |
| |
| |
Parameterized Constructors | |
| |
| |
Adding a Constructor to the Vehicle Class | |
| |
| |
An Initialization Alternative | |
| |
| |
Inline Functions | |
| |
| |
Creating Inline Functions Inside a Class | |
| |
| |
| |
Creating a Queue Class | |
| |
| |
Arrays of Objects | |
| |
| |
Initializing Object Arrays | |
| |
| |
Pointers to Objects | |
| |
| |
Object References | |
| |
| |
Module 8 Mastery Check | |
| |
| |
| |
A Closer Look at Classes | |
| |
| |
Overloading Constructors | |
| |
| |
Assigning Objects | |
| |
| |
Passing Objects to Functions | |
| |
| |
Constructors, Destructors, and Passing Objects | |
| |
| |
Passing Objects by Reference | |
| |
| |
A Potential Problem When Passing Objects | |
| |
| |
Returning Objects | |
| |
| |
Creating and Using a Copy Constructor | |
| |
| |
Friend Functions | |
| |
| |
Structures and Unions | |
| |
| |
Structures | |
| |
| |
Unions | |
| |
| |
The this Keyword | |
| |
| |
Operator Overloading | |
| |
| |
Operator Overloading Using Member Functions | |
| |
| |
Order Matters | |
| |
| |
Using Member Functions to Overload Unary Operators | |
| |
| |
Nonmember Operator Functions | |
| |
| |
Using a Friend to Overload a Unary Operator | |
| |
| |
Operator Overloading Tips and Restrictions | |
| |
| |
| |
Creating a Set Class | |
| |
| |
Module 9 Mastery Check | |
| |
| |
| |
Inheritance, Virtual Functions, and Polymorphism | |
| |
| |
Inheritance Fundamentals | |
| |
| |
Member Access and Inheritance | |
| |
| |
Base Class Access Control | |
| |
| |
Using protected Members | |
| |
| |
Constructors and Inheritance | |
| |
| |
Calling Base Class Constructors | |
| |
| |
| |
Extending the Vehicle Class | |
| |
| |
Creating a Multilevel Hierarchy | |
| |
| |
Inheriting Multiple Base Classes | |
| |
| |
When Constructor and Destructor Functions Are Executed | |
| |
| |
Pointers to Derived Types | |
| |
| |
References to Derived Types | |
| |
| |
Virtual Functions and Polymorphism | |
| |
| |
Virtual Function Fundamentals | |
| |
| |
Virtual Functions Are Inherited | |
| |
| |
Why Virtual Functions? | |
| |
| |
Applying Virtual Functions | |
| |
| |
Pure Virtual Functions and Abstract Classes | |
| |
| |
Module 10 Mastery Check | |
| |
| |
| |
The C++ I/O System | |
| |
| |
Old vs. Modern C++ I/O | |
| |
| |
C++ Streams | |
| |
| |
The C++ Predefined Streams | |
| |
| |
The C++ Stream Classes | |
| |
| |
Overloading the I/O Operators | |
| |
| |
Creating Inserters | |
| |
| |
Using Friend Functions to Overload Inserters | |
| |
| |
Overloading Extractors | |
| |
| |
Formatted I/O | |
| |
| |
Formatting with the ios Member Functions | |
| |
| |
Using I/O Manipulators | |
| |
| |
Creating Your Own Manipulator Functions | |
| |
| |
File I/O | |
| |
| |
Opening and Closing a File | |
| |
| |
Reading and Writing Text Files | |
| |
| |
Unformatted and Binary I/O | |
| |
| |
Reading and Writing Blocks of Data | |
| |
| |
More I/O Functions | |
| |
| |
More Versions of get() | |
| |
| |
getline() | |
| |
| |
Detecting EOF | |
| |
| |
peek() and putback() | |
| |
| |
flush() | |
| |
| |
| |
A File Comparison Utility | |
| |
| |
Random Access | |
| |
| |
Checking I/O Status | |
| |
| |
Module 11 Mastery Check | |
| |
| |
| |
Exceptions, Templates, and Other Advanced Topics | |
| |
| |
Exception Handling | |
| |
| |
Exception Handling Fundamentals | |
| |
| |
Using Multiple catch Statements | |
| |
| |
Catching All Exceptions | |
| |
| |
Specifying Exceptions Thrown by a Function | |
| |
| |
Rethrowing an Exception | |
| |
| |
Templates | |
| |
| |
Generic Functions | |
| |
| |
A Function with Two Generic Types | |
| |
| |
Explicitly Overloading a Generic Function | |
| |
| |
Generic Classes | |
| |
| |
Explicit Class Specializations | |
| |
| |
| |
Creating a Generic Queue Class | |
| |
| |
Dynamic Allocation | |
| |
| |
Initializing Allocated Memory | |
| |
| |
Allocating Arrays | |
| |
| |
Allocating Objects | |
| |
| |
Namespaces | |
| |
| |
Namespace Fundamentals | |
| |
| |
using | |
| |
| |
Unnamed Namespaces | |
| |
| |
The std Namespace | |
| |
| |
static Class Members | |
| |
| |
static Member Variables | |
| |
| |
static Member Functions | |
| |
| |
Runtime Type Identification (RTTI) | |
| |
| |
The Casting Operators | |
| |
| |
dynamic_cast | |
| |
| |
const_cast | |
| |
| |
static_cast | |
| |
| |
reinterpret_cast | |
| |
| |
What Next? | |
| |
| |
Module 12 Mastery Check | |
| |
| |
| |
The Preprocessor | |
| |
| |
#define | |
| |
| |
Function-Like Macros | |
| |
| |
#error | |
| |
| |
#include | |
| |
| |
Conditional Compilation Directives | |
| |
| |
#if, #else, #elif, and #endif | |
| |
| |
#ifdef and #ifndef | |
| |
| |
#undef | |
| |
| |
Using defined | |
| |
| |
#line | |
| |
| |
#pragma | |
| |
| |
The # and ## Preprocessor Operators | |
| |
| |
Predefined Macro Names | |
| |
| |
| |
Working with an Older C++ Compiler | |
| |
| |
Two Simple Changes | |
| |
| |
Index | |