| |
| |
Preface | |
| |
| |
Why a New C++ Book? | |
| |
| |
What Else Is New about This Book? | |
| |
| |
Multiple Learning Paths: What Fits You Best | |
| |
| |
What If You Already Have a Programming Background? | |
| |
| |
What Is Not Covered? | |
| |
| |
Why Should Anyone Start with C++? | |
| |
| |
To Get Started... | |
| |
| |
Tips and Tricks: What Do I Watch Out For? | |
| |
| |
Acknowledgments | |
| |
| |
| |
Your First C++ Programs | |
| |
| |
Thinking like a Programmer | |
| |
| |
What's Different about C++? | |
| |
| |
Building a C++ Program | |
| |
| |
Installing Your Own C++ Compiler | |
| |
| |
| |
Print a Message | |
| |
| |
Advancing to the Next Print Line | |
| |
| |
| |
Print Multiple Lines | |
| |
| |
Storing Data: C++ Variables | |
| |
| |
Introduction to Data Types | |
| |
| |
| |
Convert Temperatures | |
| |
| |
A Word about Variable Names and Keywords | |
| |
| |
Chapter 1 Summary | |
| |
| |
| |
Decisions, Decisions | |
| |
| |
But First, a Few Words about Data Types | |
| |
| |
Decision Making in Programs | |
| |
| |
If and if-else | |
| |
| |
| |
Odd or Even? | |
| |
| |
Introducing Loops | |
| |
| |
| |
Print 1 to N | |
| |
| |
True and False in C++ | |
| |
| |
The Increment Operator (++) | |
| |
| |
Statements vs. Expressions | |
| |
| |
Introducing Boolean (Short-Circuit) Logic | |
| |
| |
| |
Testing a Person's Age | |
| |
| |
Introducing the Math Library | |
| |
| |
| |
Prime-Number Test | |
| |
| |
Chapter 2 Summary | |
| |
| |
| |
The Handy, All-Purpose "for" Statement | |
| |
| |
Loops Used for Counting | |
| |
| |
Introducing the "for" Loop | |
| |
| |
A Wealth of Examples | |
| |
| |
| |
Printing 1 to N with "for" | |
| |
| |
Statement Blocks with "for" | |
| |
| |
Declaring Loop Variables on the Fly | |
| |
| |
| |
Prime-Number Test with "for" | |
| |
| |
Comparative Languages 101: The Basic "for" Statement | |
| |
| |
Chapter 3 Summary | |
| |
| |
| |
Functions: Many Are Called | |
| |
| |
The Concept of Function | |
| |
| |
Function Calls and the Flow of the Program | |
| |
| |
The Basics of Using Functions | |
| |
| |
| |
Triangle-Number Function | |
| |
| |
| |
Prime-Number Function | |
| |
| |
Local and Global Variables | |
| |
| |
Recursive Functions | |
| |
| |
| |
Greatest Common Factor (GCF) | |
| |
| |
| |
Prime Factorization | |
| |
| |
| |
Random-Number Generator | |
| |
| |
Chapter 4 Summary | |
| |
| |
| |
Arrays: We've Got Their Number | |
| |
| |
A First Look at C++ Arrays | |
| |
| |
Initializing Arrays | |
| |
| |
Zero-Based Indexing | |
| |
| |
| |
Print Out Elements | |
| |
| |
| |
How Random Is Random? | |
| |
| |
Strings and Arrays of Strings | |
| |
| |
| |
Card Dealer #1 | |
| |
| |
| |
Card Dealer #2 | |
| |
| |
| |
Card Dealer #3 | |
| |
| |
A Word to the Wise | |
| |
| |
2-D Arrays: Into the Matrix | |
| |
| |
Chapter 5 Summary | |
| |
| |
| |
Pointers: Getting a Handle on Data | |
| |
| |
The Concept of Pointer | |
| |
| |
Declaring and Using Pointers | |
| |
| |
| |
The Double-It Function | |
| |
| |
Swap: Another Function Using Pointers | |
| |
| |
| |
Array Sorter | |
| |
| |
Pointer Arithmetic | |
| |
| |
Pointers and Array Processing | |
| |
| |
| |
Zero Out an Array | |
| |
| |
Chapter 6 Summary | |
| |
| |
| |
Strings: Analyzing the Text | |
| |
| |
Text Storage on the Computer | |
| |
| |
It Don't Mean a Thing If It Ain't Got That String | |
| |
| |
String-Manipulation Functions | |
| |
| |
| |
Building Strings | |
| |
| |
Reading String Input | |
| |
| |
| |
Get a Number | |
| |
| |
| |
Convert to Uppercase | |
| |
| |
Individual Characters vs. Strings | |
| |
| |
| |
Analyze Input | |
| |
| |
The New C++ String Class | |
| |
| |
| |
Building Strings with the string Type | |
| |
| |
Other Operations on the string Type | |
| |
| |
Chapter 7 Summary | |
| |
| |
| |
Files: Electronic Storage | |
| |
| |
Introducing File-Stream Objects | |
| |
| |
How to Refer to Disk Files | |
| |
| |
| |
Write Text to a File | |
| |
| |
| |
Display a Text File | |
| |
| |
Text Files vs. "Binary" Files | |
| |
| |
Introducing Binary Operations | |
| |
| |
| |
Random-Access Write | |
| |
| |
| |
Random-Access Read | |
| |
| |
Chapter 8 Summary | |
| |
| |
| |
Some Advanced Programming Techniques | |
| |
| |
Command-Line Arguments | |
| |
| |
| |
Display File from Command Line | |
| |
| |
Function Overloading | |
| |
| |
| |
Printing Different Types of Arrays | |
| |
| |
The do-while Loop | |
| |
| |
The switch-case Statement | |
| |
| |
Multiple Modules | |
| |
| |
Exception Handling | |
| |
| |
| |
Exception Handling with GCF | |
| |
| |
Chapter 9 Summary | |
| |
| |
| |
Getting Yourself Object Oriented | |
| |
| |
Why Get Object Oriented? | |
| |
| |
A String Parser | |
| |
| |
Objects vs. Classes | |
| |
| |
Another Example: The Fraction Class | |
| |
| |
Object Creation and Destruction | |
| |
| |
Inheritance, or Subclassing | |
| |
| |
Creating Shared Interfaces | |
| |
| |
Polymorphism: True Object Independence | |
| |
| |
Polymorphism and Virtual Functions | |
| |
| |
What about Reusability? | |
| |
| |
Chapter 10 Summary | |
| |
| |
| |
The Fraction Class | |
| |
| |
Point: A Simple Class | |
| |
| |
Private: Members Only (Protecting the Data) | |
| |
| |
| |
Testing the Point Class | |
| |
| |
Introducing the Fraction Class | |
| |
| |
Inline Functions | |
| |
| |
Find the Greatest Common Factor | |
| |
| |
Find the Lowest Common Multiple | |
| |
| |
| |
Fraction Support Functions | |
| |
| |
| |
Testing the Fraction Class | |
| |
| |
| |
Fraction Arithmetic: add and mult | |
| |
| |
Chapter 11 Summary | |
| |
| |
| |
Constructors: If You Build It... | |
| |
| |
Introducing Constructors | |
| |
| |
Multiple Constructors (Overloading) | |
| |
| |
The Default Constructor...and a Warning | |
| |
| |
| |
Point Class Constructors | |
| |
| |
| |
Fraction Class Constructors | |
| |
| |
Reference Variables and Arguments (&) | |
| |
| |
The Copy Constructor | |
| |
| |
| |
Fraction Class Copy Constructor | |
| |
| |
Chapter 12 Summary | |
| |
| |
| |
Operator Functions: Doing It with Class | |
| |
| |
Introducing Class Operator Functions | |
| |
| |
Operator Functions As Global Functions | |
| |
| |
Improve Efficiency with References | |
| |
| |
| |
Point Class Operators | |
| |
| |
| |
Fraction Class Operators | |
| |
| |
Working with Other Types | |
| |
| |
The Class Assignment Function (=) | |
| |
| |
The Test-for-Equality Function (==) | |
| |
| |
A Class "Print" Function | |
| |
| |
| |
The Completed Fraction Class | |
| |
| |
Chapter 13 Summary | |
| |
| |
| |
What's "new": The StringParser Class | |
| |
| |
The "new" Operator | |
| |
| |
Objects and "new" | |
| |
| |
Allocating Array Data | |
| |
| |
| |
Dynamic Memory in Action | |
| |
| |
Design for a Parser (Lexical Analyzer) | |
| |
| |
| |
The StringParser Class | |
| |
| |
Chapter 14 Summary | |
| |
| |
| |
What's "this": The String Class | |
| |
| |
Introducing the String Class | |
| |
| |
Introducing Class Destructors | |
| |
| |
| |
A Simple String Class | |
| |
| |
"Deep" Copying and the Copy Constructor | |
| |
| |
The "this" Keyword | |
| |
| |
Revisiting the Assignment Operator | |
| |
| |
Writing a Concatenation Function | |
| |
| |
| |
The Complete String Class | |
| |
| |
Chapter 15 Summary | |
| |
| |
| |
Inheritance: What a Legacy | |
| |
| |
Subclassing for Fun and Profit | |
| |
| |
| |
The FloatFraction Class | |
| |
| |
Problems with the FloatFraction Class | |
| |
| |
| |
The Completed FloatFraction Class | |
| |
| |
| |
The ProperFraction Class | |
| |
| |
Private and Protected Members | |
| |
| |
| |
Contained Members: Fraction Units | |
| |
| |
Chapter 16 Summary | |
| |
| |
| |
Polymorphism: Object Independence | |
| |
| |
A Different Approach to the FloatFraction Class | |
| |
| |
Virtual Functions to the Rescue! | |
| |
| |
| |
The Revised FloatFraction Class | |
| |
| |
"Pure Virtual" and Other Arcane Matters | |
| |
| |
Abstract Classes and Interfaces | |
| |
| |
Why cout Is Not Truly Polymorphic | |
| |
| |
| |
True Polymorphism: The Printable Class | |
| |
| |
A Final Word (or Two) | |
| |
| |
A Final Final Word | |
| |
| |
Chapter 17 Summary | |
| |
| |
| |
C++ Operators | |
| |
| |
| |
Intrinsic Data Types | |
| |
| |
| |
C++ Syntax Summary | |
| |
| |
Literal Constants | |
| |
| |
Basic Expression Syntax | |
| |
| |
Basic Statement Syntax | |
| |
| |
Control Structures | |
| |
| |
Special Control Statements | |
| |
| |
Data Declarations | |
| |
| |
Function Declarations | |
| |
| |
Class Declarations | |
| |
| |
| |
ASCII Codes | |
| |
| |
| |
Common Library Functions | |
| |
| |
String Functions | |
| |
| |
Data-Conversion Functions | |
| |
| |
Single-Character Functions | |
| |
| |
Math Functions | |
| |
| |
Randomization | |
| |
| |
| |
Glossary of Terms | |
| |
| |
Index | |