| |
| |
Preface | |
| |
| |
| |
Introduction to Computers and C++ Programming | |
| |
| |
| |
Introduction | |
| |
| |
| |
What is a Computer? | |
| |
| |
| |
Computer Organization | |
| |
| |
| |
Evolution of Operating Systems | |
| |
| |
| |
Personal Computing, Distributed Computing and Client/Server Computing | |
| |
| |
| |
Machine Languages, Assembly Languages, and High-level Languages | |
| |
| |
| |
History of C and C++ | |
| |
| |
| |
C++ Standard Library | |
| |
| |
| |
Java and Java How to Program | |
| |
| |
| |
Other High-level Languages | |
| |
| |
| |
Structured Programming | |
| |
| |
| |
The Key Software Trend: Object Technology | |
| |
| |
| |
Basics of a Typical C++ Environment | |
| |
| |
| |
Hardware Trends | |
| |
| |
| |
History of the Internet | |
| |
| |
| |
History of the World Wide Web | |
| |
| |
| |
General Notes About C++ and This Book | |
| |
| |
| |
Introduction to C++ Programming | |
| |
| |
| |
A Simple Program: Printing a Line of Text | |
| |
| |
| |
Another Simple Program: Adding Two Integers | |
| |
| |
| |
Memory Concepts | |
| |
| |
| |
Arithmetic | |
| |
| |
| |
Decision Making: Equality and Relational Operators | |
| |
| |
| |
Thinking About Objects: Introduction to Object Technology and the Unified Modeling Language | |
| |
| |
| |
Control Structures | |
| |
| |
| |
Introduction | |
| |
| |
| |
Algorithms | |
| |
| |
| |
Pseudocode | |
| |
| |
| |
Control Structures | |
| |
| |
| |
The if Selection Structure | |
| |
| |
| |
The if/else Selection Structure | |
| |
| |
| |
The while Repetition Structure | |
| |
| |
| |
Formulating Algorithms: Case Study 1 (Counter-Controlled Repetition) | |
| |
| |
| |
Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel-Controlled Repetition) | |
| |
| |
| |
Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) | |
| |
| |
| |
Assignment Operators | |
| |
| |
| |
Increment and Decrement Operators | |
| |
| |
| |
Essentials of Counter-Controlled Repetition | |
| |
| |
| |
The for Repetition Structure | |
| |
| |
| |
Examples Using the for Structure | |
| |
| |
| |
The switch Multiple-Selection Structure | |
| |
| |
| |
The do/while Repetition Structure | |
| |
| |
| |
The break and continue Statements | |
| |
| |
| |
Logical Operators | |
| |
| |
| |
Confusing Equality (==) and Assignment (=) Operators | |
| |
| |
| |
Structured-Programming Summary | |
| |
| |
| |
[Optional Case Study] Thinking About Objects: Identifying the Classes in a Problem | |
| |
| |
| |
Functions | |
| |
| |
| |
Introduction | |
| |
| |
| |
Program Components in C++ | |
| |
| |
| |
Math Library Functions | |
| |
| |
| |
Functions | |
| |
| |
| |
Function Definitions | |
| |
| |
| |
Function Prototypes | |
| |
| |
| |
Header Files | |
| |
| |
| |
Random Number Generation | |
| |
| |
| |
Example: A Game of Chance and Introducing enum | |
| |
| |
| |
Storage Classes | |
| |
| |
| |
Scope Rules | |
| |
| |
| |
Recursion | |
| |
| |
| |
Example Using Recursion: The Fibonacci Series | |
| |
| |
| |
Recursion vs. Iteration | |
| |
| |
| |
Functions with Empty Parameter Lists | |
| |
| |
| |
Inline Functions | |
| |
| |
| |
References and Reference Parameters | |
| |
| |
| |
Default Arguments | |
| |
| |
| |
Unary Scope Resolution Operator | |
| |
| |
| |
Function Overloading | |
| |
| |
| |
Function Templates | |
| |
| |
| |
[Optional Case Study] Thinking About Objects: Identifying a Class's Attributes | |
| |
| |
| |
Arrays | |
| |
| |
| |
Introduction | |
| |
| |
| |
Arrays | |
| |
| |
| |
Declaring Arrays | |
| |
| |
| |
Examples Using Arrays | |
| |
| |
| |
Passing Arrays to Functions | |
| |
| |
| |
Sorting Arrays | |
| |
| |
| |
Case Study: Computing Mean, Median and Mode Using Arrays | |
| |
| |
| |
Searching Arrays: Linear Search and Binary Search | |
| |
| |
| |
Multiple-Subscripted Arrays | |
| |
| |
| |
[Optional Case Study] Thinking About Objects: Identifying the Operations of a Class | |
| |
| |
| |
Pointers and Strings | |
| |
| |
| |
Introduction | |
| |
| |
| |
Pointer Variable Declarations and Initialization | |
| |
| |
| |
Pointer Operators | |
| |
| |
| |
Calling Functions by Reference | |
| |
| |
| |
Using the const Qualifier with Pointers | |
| |
| |
| |
Bubble Sort Using Call-by-reference | |
| |
| |
| |
Pointer Expressions and Pointer Arithmetic | |
| |
| |
| |
The Relationship Between Pointers and Arrays | |
| |
| |
| |
Arrays of Pointers | |
| |
| |
| |
Case Study: A Card Shuffling and Dealing Simulation | |
| |
| |
| |
Function Pointers | |
| |
| |
| |
Introduction to Character and String Processing | |
| |
| |
| |
Fundamentals of Characters and Strings | |
| |
| |
| |
String Manipulation Functions of the String-handling Library | |
| |
| |
| |
[Optional Case Study] Thinking About Objects: Collaborations Among Objects | |
| |
| |
| |
Classes and Data Abstraction | |
| |
| |
| |
Introduction | |
| |
| |
| |
Structure Definitions | |
| |
| |
| |
Accessing Members of Structures | |
| |
| |
| |
Implementing a User-Defined Type Time with a struct | |
| |
| |
| |
Implementing a Time Abstract Data Type with a class | |
| |
| |
| |
Class Scope and Accessing Class Members | |
| |
| |
| |
Separating Interface from Implementation | |
| |
| |
| |
Controlling Access to Members | |
| |
| |
| |
Access Functions and Utility Functions | |
| |
| |
| |
Initializing Class Objects: Constructors | |
| |
| |
| |
Using Default Arguments with Constructors | |
| |
| |
| |
Using Destructors | |
| |
| |
| |
When Constructors and Destructors Are Called | |
| |
| |
| |
Using Data Members and Member Functions | |
| |
| |
| |
A Subtle Trap: Returning a Reference to a Private Data Member | |
| |
| |
| |
Assignment by Default Memberwise Copy | |
| |
| |
| |
Software Reusability | |
| |
| |
| |
[Optional Case Study) Thinking About Objects: Starting to Program the Classes for the Elevator Simulator | |
| |
| |
| |
Classes: Part II | |
| |
| |
| |
Introduction | |
| |
| |
| |
const (Constant) Objects and const Member Functions | |
| |
| |
| |
Composition: Objects as Members of Classes | |
| |
| |
| |
friend Functions and friend Classes | |
| |
| |
| |
Using the this Pointer | |
| |
| |
| |
Dynamic Memory Allocation with Operators new and delete | |
| |
| |
| |
static Class Members | |
| |
| |
| |
Data Abstraction and Information Hiding | |
| |
| |
| |
Example: Array Abstract Data Type | |
| |
| |
| |
Example: String Abstract Data Type | |
| |
| |
| |
Example: Queue Abstract Data Type | |
| |
| |
| |
Container Classes and Iterators | |
| |
| |
| |
Proxy Classes | |
| |
| |
| |
[Optional Case Study] Thinking About Objects: Programming the Classes for the Elevator Simulator | |
| |
| |
| |
Operator Overloading | |
| |
| |
| |
Introduction | |
| |
| |
| |
Fundamentals of Operator Overloading | |
| |
| |
| |
Restrictions on Operator Overloading | |
| |
| |
| |
Operator Functions as Class Members vs. as friend Functions | |
| |
| |
| |
Overloading Stream-Insertion and Stream-Extraction Operators | |
| |
| |
| |
Overloading Unary Operators | |
| |
| |
| |
Overloading Binary Operators | |
| |
| |
| |
Case Study: An Array Class | |
| |
| |
| |
Converting between Types | |
| |
| |
| |
Case Study: A String Class | |
| |
| |
| |
Overloading ++ and -- | |
| |
| |
| |
Case Study: A Date Class | |
| |
| |
| |
Inheritance | |
| |
| |
| |
Introduction | |
| |
| |
| |
Inheritance: Base Classes and Derived Classes | |
| |
| |
| |
Protected Members | |
| |
| |
| |
Casting Base-Class Pointers to Derived-Class Pointers | |
| |
| |
| |
Using Member Functions | |
| |
| |
| |
Overriding Base-Class Members in a Derived Class | |
| |
| |
| |
public, protected and private Inheritance | |
| |
| |
| |
Direct Base Classes and Indirect Base Classes | |
| |
| |
| |
Using Constructors and Destructors in Derived Classes | |
| |
| |
| |
Implicit Derived-Class Object to Base-Class Object Conversion | |
| |
| |
| |
Software Engineering with Inheritance | |
| |
| |
| |
Composition vs. Inheritance | |
| |
| |
| |
"Uses A" and "Knows A" Relationships | |
| |
| |
| |
Case Study: Point, Circle, Cylinder | |
| |
| |
| |
Multiple Inheritance | |
| |
| |
| |
[Optional Case Study] Thinking About Objects: Incorporating Inheritance into the Elevator Simulation | |
| |
| |
| |
Virtual Functions and Polymorphism | |
| |
| |
| |
Introduction | |
| |
| |
| |
Type Fields and switch Statements | |
| |
| |
| |
virtual Functions | |
| |
| |
| |
Abstract Base Classes and Concrete Classes | |
| |
| |
| |
Polymorphism | |
| |
| |
| |
Case Study: A Payroll System Using Polymorphism | |
| |
| |
| |
New Classes and Dynamic Binding | |
| |
| |
| |
virtual Destructors | |
| |
| |
| |
Case Study: Inheriting Interface and Implementation | |
| |
| |
| |
Polymorphism, virtual Functions and Dynamic Binding "Under the Hood" | |
| |
| |
| |
C++ Stream Input/Output | |
| |
| |
| |
Introduction | |
| |
| |
| |
Streams | |
| |
| |
| |
Iostream Library Header Files | |
| |
| |
| |
Stream Input/Output Classes and Objects | |
| |
| |
| |
Stream Output | |
| |
| |
| |
Stream-Insertion Operator | |
| |
| |
| |
Cascading Stream-Insertion/Extraction Operators | |
| |
| |
| |
Output of char * Variables | |
| |
| |
| |
Character Output with Member Function put; Cascading puts | |
| |
| |
| |
Stream Input | |
| |
| |
| |
Stream-Extraction Operator | |
| |
| |
| |
get and getline Member Functions | |
| |
| |
| |
istream Member Functions peek, putback and ignore | |
| |
| |
| |
Type-Safe I/O | |
| |
| |
| |
Unformatted I/O with read, gcount and write | |
| |
| |
| |
Stream Manipulators | |
| |
| |
| |
Integral Stream Base: dec, oct, hex and setbase | |
| |
| |
| |
Floating-Point Precision (precision, setprecision) | |
| |
| |
| |
Field Width (setw, width) | |
| |
| |
| |
User-Defined Manipulators | |
| |
| |
| |
Stream Format States | |
| |
| |
| |
Format State Flags | |
| |
| |
| |
Trailing Zeros and Decimal Points (ios::showpoint) | |
| |
| |
| |
Justification (ios::left, ios::right, ios::internal) | |
| |
| |
| |
Padding (fill, setfill) | |
| |
| |
| |
Integral Stream Base (ios::dec, ios::oct, ios::hex, ios::showbase) | |
| |
| |
| |
Floating-Point Numbers; Scientific Notation (ios::scientific, ios::fixed) | |
| |
| |
| |
Uppercase/Lowercase Control (ios::uppercase) | |
| |
| |
| |
Setting and Resetting the Format Flags (flags, setiosflags, resetiosflags) | |
| |
| |
| |
Stream Error States | |
| |
| |
| |
Tying an Output Stream to an Input Stream | |
| |
| |
| |
Templates | |
| |
| |
| |
Introduction | |
| |
| |
| |
Function Templates | |
| |
| |
| |
Overloading Template Functions | |
| |
| |
| |
Class Templates | |
| |
| |
| |
Class Templates and Nontype Parameters | |
| |
| |
| |
Templates and Inheritance | |
| |
| |
| |
Templates and friends | |
| |
| |
| |
Templates and static Members | |
| |
| |
| |
Exception Handling | |
| |
| |
| |
Introduction | |
| |
| |
| |
When Exception Handling Should Be Used | |
| |
| |
| |
Other Error-Handling Techniques | |
| |
| |
| |
Basics of C++ Exception Handling: try, throw, catch | |
| |
| |
| |
A Simple Exception-Handling Example: Divide by Zero | |
| |
| |
| |
Throwing an Exception | |
| |
| |
| |
Catching an Exception | |
| |
| |
| |
Rethrowing an Exception | |
| |
| |
| |
Exception Specifications | |
| |
| |
| |
Processing Unexpected Exceptions | |
| |
| |
| |
Stack Unwinding | |
| |
| |
| |
Constructors, Destructors and Exception Handling | |
| |
| |
| |
Exceptions and Inheritance | |
| |
| |
| |
Processing new Failures | |
| |
| |
| |
Class auto_ptr and Dynamic Memory Allocation | |
| |
| |
| |
Standard Library Exception Hierarchy | |
| |
| |
| |
File Processing | |
| |
| |
| |
Introduction | |
| |
| |
| |
The Data Hierarchy | |
| |
| |
| |
Files and Streams | |
| |
| |
| |
Creating a Sequential Access File | |
| |
| |
| |
Reading Data from a Sequential Access File | |
| |
| |
| |
Updating Sequential Access Files | |
| |
| |
| |
Random-Access Files | |
| |
| |
| |
Creating a Random-Access File | |
| |
| |
| |
Writing Data Randomly to a Random-Access File | |
| |
| |
| |
Reading Data Sequentially from a Random-Access File | |
| |
| |
| |
Example: A Transaction Processing Program | |
| |
| |
| |
Input/Output of Objects | |
| |
| |
| |
Data Structures | |
| |
| |
| |
Introduction | |
| |
| |
| |
Self-Referential Classes | |
| |
| |
| |
Dynamic Memory Allocation | |
| |
| |
| |
Linked Lists | |
| |
| |
| |
Stacks | |
| |
| |
| |
Queues | |
| |
| |
| |
Trees | |
| |
| |
| |
Bits, Characters, Strings and Structures | |
| |
| |
| |
Introduction | |
| |
| |
| |
Structure Definitions | |
| |
| |
| |
Initializing Structures | |
| |
| |
| |
Using Structures with Functions | |
| |
| |
| |
typedef | |
| |
| |
| |
Example: High-Performance Card-shuffling and Dealing Simulation | |
| |
| |
| |
Bitwise Operators | |
| |
| |
| |
Bit Fields | |
| |
| |
| |
Character-handling Library | |
| |
| |
| |
String Conversion Functions | |
| |
| |
| |
Search Functions of the String-handling Library | |
| |
| |
| |
Memory Functions of the String-handling Library | |
| |
| |
| |
Another Function of the String-handling Library | |
| |
| |
| |
The Preprocessor | |
| |
| |
| |
Introduction | |
| |
| |
| |
The #include Preprocessor Directive | |
| |
| |
| |
The #define Preprocessor Directive: Symbolic Constants | |
| |
| |
| |
The #define Preprocessor Directive: Macros | |
| |
| |
| |
Conditional Compilation | |
| |
| |
| |
The #error and #pragma Preprocessor Directives | |
| |
| |
| |
The # and ## Operators | |
| |
| |
| |
Line Numbers | |
| |
| |
| |
Predefined Symbolic Constants | |
| |
| |
| |
Assertions | |
| |
| |
| |
C Legacy Code Topics | |
| |
| |
| |
Introduction | |
| |
| |
| |
Redirecting Input/Output on UNIX and DOS Systems | |
| |
| |
| |
Variable-Length Argument Lists | |
| |
| |
| |
Using Command-Line Arguments | |
| |
| |
| |
Notes on Compiling Multiple-Source-File Programs | |
| |
| |
| |
Program Termination with exit and atexit | |
| |
| |
| |
The volatile Type Qualifier | |
| |
| |
| |
Suffixes for Integer and Floating-Point Constants | |
| |
| |
| |
Signal Handling | |
| |
| |
| |
Dynamic Memory Allocation with calloc and realloc | |
| |
| |
| |
The Unconditional Branch: goto | |
| |
| |
| |
Unions | |
| |
| |
| |
Linkage Specifications | |
| |
| |
| |
Class string and String Stream Processing | |
| |
| |
| |
Introduction | |
| |
| |
| |
string Assignment and Concatenation | |
| |
| |
| |
Comparing strings | |
| |
| |
| |
Substrings | |
| |
| |
| |
Swapping strings | |
| |
| |
| |
string Characteristics | |
| |
| |
| |
Finding Characters in a string | |
| |
| |
| |
Replacing Characters in a string | |
| |
| |
| |
Inserting Characters into a string | |
| |
| |
| |
Conversion to C-Style char * Strings | |
| |
| |
| |
Iterators | |
| |
| |
| |
String Stream Processing | |
| |
| |
| |
Standard Template Library (STL) | |
| |
| |
| |
Introduction to the Standard Template Library (STL) | |
| |
| |
| |
Introduction to Containers | |
| |
| |
| |
Introduction to Iterators | |
| |
| |
| |
Introduction to Algorithms | |
| |
| |
| |
Sequence Containers | |
| |
| |
| |
vector Sequence Container | |
| |
| |
| |
list Sequence Container | |
| |
| |
| |
deque Sequence Container | |
| |
| |
| |
Associative Containers | |
| |
| |
| |
multiset Associative Container | |
| |
| |
| |
set Associative Container | |
| |
| |
| |
multimap Associative Container | |
| |
| |
| |
map Associative Container | |
| |
| |
| |
Container Adapters | |
| |
| |
| |
stack Adapter | |
| |
| |
| |
queue Adapter | |
| |
| |
| |
priority_queue Adapter | |
| |
| |
| |
Algorithms | |
| |
| |
| |
fill, fill_n, generate and generate_n | |
| |
| |
| |
equal, mismatch and lexicographical_compare | |
| |
| |
| |
remove, remove_if, remove_copy and remove_copy_if | |
| |
| |
| |
replace, replace_if, replace_copy and replace_copy_if | |
| |
| |
| |
Mathematical Algorithms | |
| |
| |
| |
Basic Searching and Sorting Algorithms | |
| |
| |
| |
swap, iter_swap and swap_ranges | |
| |
| |
| |
copy_backward, merge, unique and reverse | |
| |
| |
| |
inplace_merge, unique_copy and reverse_copy | |
| |
| |
| |
Set Operations | |
| |
| |
| |
lower_bound, upper_bound and equal_range | |
| |
| |
| |
Heapsort | |
| |
| |
| |
min and max | |
| |
| |
| |
Algorithms Not Covered in This Chapter | |
| |
| |
| |
Class bitset | |
| |
| |
| |
Function Objects | |
| |
| |
| |
Standard C++ Language Additions | |
| |
| |
| |
Introduction | |
| |
| |
| |
bool Data Type | |
| |
| |
| |
static_cast Operator | |
| |
| |
| |
const_cast Operator | |
| |
| |
| |
reinterpret_cast Operator | |
| |
| |
| |
namespaces | |
| |
| |
| |
Run-Time Type Information (RTTI) | |
| |
| |
| |
Operator Keywords | |
| |
| |
| |
explicit Constructors | |
| |
| |
| |
mutable Class Members | |
| |
| |
| |
Pointers to Class Members (.* and -]*) | |
| |
| |
| |
Multiple Inheritance and virtual Base Classes | |
| |
| |
| |
Closing Remarks | |
| |
| |
| |
Operator Precedence Chart | |
| |
| |
| |
ASCII Character Set | |
| |
| |
| |
Number Systems | |
| |
| |
| |
Introduction | |
| |
| |
| |
Abbreviating Binary Numbers as Octal Numbers and Hexadecimal Numbers | |
| |
| |
| |
Converting Octal Numbers and Hexadecimal Numbers to Binary Numbers | |
| |
| |
| |
Converting from Binary, Octal, or Hexadecimal to Decimal | |
| |
| |
| |
Converting from Decimal to Binary, Octal, or Hexadecimal | |
| |
| |
| |
Negative Binary Numbers: Two's Complement Notation | |
| |
| |
| |
C++ Internet and Web Resources | |
| |
| |
| |
Resources | |
| |
| |
| |
Tutorials | |
| |
| |
| |
FAQs | |
| |
| |
| |
Visual C++ | |
| |
| |
| |
comp.lang.c++ | |
| |
| |
| |
Compilers | |
| |
| |
| |
Development Tools | |
| |
| |
| |
Standard Template Library | |
| |
| |
Bibliography | |
| |
| |
Index | |