C++ Object Oriented Programming Long Table of Contents

C++ Object Oriented Programming Long Table of Contents

Back to previous book promo page(with page numbers)

Chapter 1 — C++ iostreams, Structures, and Reference Variables…. 1

Introduction……….. 1
Object-Oriented Terminology……….. 2
The Two Versions of C++……….. 3
New C++ iostreams……….. 5
The Output Stream……….. 5
The Input Stream……….. 6
Chaining Extraction Operators……….. 7
Specific Extraction Operator Rules……….. 7
Always Prompt the User Before Inputting the Data from the Keyboard……….. 8
Some Common Errors……….. 8
Output of a Variable……….. 9
The setw() Function……….. 10
Labeling Output……….. 11
Some Additional Insertion Operator Details……….. 11
Insertion of Floating Point Numbers into an Output Stream……….. 12
Displaying Fatal Errors……….. 13
Input Files……….. 14
I/O Stream States……….. 16
Testing for Goodness……….. 17
Testing for Bad Data Entry……….. 17
The End of File……….. 19
Closing a File……….. 20
A Complete Example……….. 20
Loops to Input All Data in a File……….. 21
Sentinel Controlled Input Loops……….. 21
Keyboard Data Entry Sentinel Controlled Loops……….. 22
Menus as Sentinel Controlled Loops……….. 23
Primed Input Loops that Detect End of File……….. 24
A More Compact Loop That Detects End of File……….. 25
Creating Output Files……….. 26
The Input and Output of Character Data……….. 27
The Input and Output of Character Strings……….. 29
Method A — All Strings Have the Same Length……….. 30
Method B — String Contains Only the Needed Characters, But Is the Last Field on a Line……….. 31
Method C — All strings Are Delimited……….. 32
Outputting Character Strings……….. 33
The Fill Character and Inputting Numbers with Leading 0’s……….. 34
Structures and the iostreams……….. 35
Reference Variables……….. 36
Passing iostream Instances to Functions……….. 38
The Vital Role of the const Qualifier……….. 40
Application Section 42
Pgm01a — The Cost of Goods Sold Program……….. 42
Review Questions……….. 48
Stop! Do These Exercises Before Programming……….. 51
Programming Problems……….. 56

 

Chapter 2 — Mechanics of Larger Program Creation… 58

Introduction……….. 58
The bool Data Type……….. 58
Enumerated Data Types……….. 59
The Use of Default Arguments……….. 66
Function Overloading and the istrstream and ostrstream Classes……….. 68
The istrstream Class……….. 68
The ostrstream Class……….. 70
Function Ambiguity and Default Arguments……….. 70
Multiple Cpp Files Project……….. 72
User Written Header Files……….. 73
Mechanics of Header File Construction……….. 74
Placement of Header File Includes in a Cpp File……….. 75
#ifndef/#define Logic……….. 77
Application Section……….. 81
Pgm02a — Acme Pets ‘R Us Inquiry/Update Program……….. 81
Review Questions……….. 104
Stop! Do These Exercises Before Programming……….. 106
Programming Problems……….. 110

 

Chapter 3 — Pointers and Dynamic Memory Allocation 113

Introduction……….. 113
Pointer Basics……….. 114
Dynamic Memory Allocation……….. 115
The Location of the Heap……….. 117
Do We Need to Check for Successful Allocation?……….. 117
Dynamic Allocation Arrays……….. 118
Memory Leaks……….. 120
Checking for Memory Leaks with Visual C++ 6.0……….. 121
Checking for Memory Leaks with Borland C++ 5.0……….. 121
Dynamically Allocating Strings……….. 122
Arrays of Pointers — Turning a Pointer Back into a Reference……….. 123
The Use of the const Keyword with Pointers……….. 124
A Complete Example Using Dynamic Memory Allocation……….. 125
Review Questions……….. 135
Stop! Do These Exercises Before Programming……….. 138
Programming Problems……….. 140

 

Chapter 4 — An Introduction to Classes I 144

Introduction……….. 144
Class Syntax……….. 145
The Three Access Qualifiers……….. 146
Constructors and Destructors……….. 147
The Implementation File……….. 149
Access Functions……….. 150
Instantiating Classes……….. 152
Initializing Arrays of Objects……….. 154
Assigning Instances……….. 154
Objects (Instances of a Class) Can Be Passed to Functions and Returned……….. 156
Constant Member Functions……….. 157
Default Arguments……….. 159
Operations Functions — Handling I/O Operations — A First Look……….. 159
Practical Example 1 — The Class Rectangle (Pgm04a)……….. 161
Practical Example 2 — The Interval Timer Class (Pgm04b)……….. 170
Review Questions……….. 174
Stop! Do These Exercises Before Programming……….. 176
Programming Problems……….. 178

 

Chapter 5 — An Introduction to Classes II 186

Introduction……….. 186
Using Instances of Another Class as Data Members in Another Class……….. 186
Using #ifndef-#define Logic in Class Header Files……….. 187
The this Pointer……….. 189
When Classes Contain References or Pointers or Instances of Other Classes — Forward References……….. 191
Using Class enums……….. 195
Friend Functions……….. 197
Constant Data Members……….. 198
The Copy Constructor and How to Forbid Certain Constructors……….. 200
Reference Variables as Data Members……….. 203
Static Data Members and Static Member Functions……….. 205
Static Member Data……….. 205
Static Member Functions……….. 208
Inline Functions……….. 212
Implicit Type Conversions……….. 214
Summary of Constructor and Destructor Functions……….. 215
Practical Example 1 — Dice and Die Rolling……….. 216
Making Production Libraries……….. 224
Review Questions……….. 225
Stop! Do These Exercises Before Programming……….. 227
Programming Problems……….. 230

 

Chapter 6 — Operator Overloading… 240

Introduction……….. 240
Overloading Binary Operators……….. 241
Overloading the Math Binary Operators (such as + and –)……….. 241
Using Friend Functions to Handle Overloading Normal Data Types……….. 245
The Subtraction Operator……….. 246
Overloading the += and Similar Operators……….. 248
Overloading the Relational Operators……….. 248
Overloading the Insertion and Extraction Operators — << and >>……….. 249
The Assignment Operator……….. 250
Overloading the Unary Operators……….. 250
Overloading the Inc and Dec Operators……….. 251
Overloading the Unary – Operator……….. 252
The Time Class – A Complete Programming Example……….. 252
Review Questions……….. 266
Stop! Do These Exercises Before Programming……….. 267
Programming Problems……….. 269

 

Chapter 7 — Classes with Dynamic Memory Allocation 274

Introduction……….. 274
Coding the Copy Constructor and the Operator= Functions……….. 277
Overloading the [] Operator……….. 278
Overloading the & Address Operator……….. 279
Operator Conversion Functions……….. 280
Pgm07a — String Class Thus Far……….. 281
A Practical Example — Designing a Generic Growable Array Class……….. 287
Review Questions……….. 302
Stop! Do These Exercises Before Programming……….. 303
Programming Problems……….. 304

 

Chapter 8 — Inheritance 317

Introduction……….. 317
Principles of Inheritance……….. 319
Working With Inherited Member Functions……….. 323
Copy Constructors……….. 325
The Assignment Operator Implementation……….. 325
Problems When Client Programs Use Base Class Pointers……….. 326
Virtual Functions……….. 327
I/O Operations with Derived Classes Demand Virtual Functions……….. 332
Destructors……….. 337
How the Virtual Function Mechanism Is Implemented……….. 337
Early Binding and Late Binding……….. 338
Animals — A Complete Example with Dynamic Memory Allocation and Virtual Functions —
Pgm08b……….. 339
Review Questions 357
Stop! Do These Exercises Before Programming……….. 359
Programming Problems……….. 360

 

Chapter 9 — Abstract Base Classes.. 365

Introduction……….. 365
Abstract Base Class — Shapes — a Complete Example — Pgm09a……….. 365
The Abstract Base Class Shape and Its Derived Classes Development Steps……….. 365
The Actual Implementation of Shape and Its Derived Classes……….. 375
Writing the Client Tester Program Pgm09a……….. 385
Multiple Inheritance……….. 389
Adding Multiple Base Classes to Shapes……….. 391
Review Questions……….. 392
Stop! Do These Exercises Before Programming……….. 392
Programming Problems……….. 393

 

Chapter 10 — Applications of OOP… 399

Introduction……….. 399
The Microsoft I/O Stream Classes……….. 399
Putting OOP to Use — the Double Linked List Data Structure……….. 407
Designing a Double Linked List Class……….. 409
Methods of Storing the Client Data in a Node……….. 409
Method A. Storing a Copy of the Client’s Data in the Node……….. 409
Method B. Storing a Pointer to the Client’s Data in the Node……….. 410
Method C. Storing a void Pointer to the Client’s Data in the Node……….. 411
Method D. Storing a Pointer to a Common Base Class from which the Client’s Data Is Derived……….. 412
Designing the Double Linked List Class Storing void Pointers……….. 413
Providing a Find Matching List Item Function……….. 414
Handling the Insertions into the List……….. 416
Deleting the Current Node……….. 420
The Generic DoubleLinkedList Class Storing void Pointers ……….. 422
Writing Client Programs that Use the Double Linked List Class……….. 432
Designing a Double Linked List Class That Stores BaseObj Pointers……….. 446
Review Questions……….. 470
Stop! Do These Exercises Before Programming……….. 471
Programming Problems……….. 473

 

Chapter 11 — C++ Error Handling 476

Introduction……….. 476
Typecasting — Static and Dynamic……….. 476
Invoking Derived Class Functions That Are Not Virtual or Defined in the Base Class……….. 477
To Use dynamic_cast with the Microsoft VC6.0 Compiler……….. 478
Run-Time Type Information……….. 478
The C++ Error Handling System 479
Details of the try-catch-throw Mechanism……….. 484
Replacing the Default terminate() Function and the Default unexpected() Functions……….. 485
Overloading the new and delete Functions……….. 487
Throwing Class Instances……….. 488
Handling Error Situations Where Multiple Dynamic Memory Allocations Exist……….. 491
Review Questions……….. 494
Stop! Do These Exercises Before Programming……….. 496
Programming Problems……….. 498

 

Chapter 12 — Templates 500

Introduction……….. 500
Specializing a Template……….. 503
Template Classes……….. 504
Pgm12a — a Practical Example of a Template Class……….. 505
Review Questions……….. 530
Stop! Do These Exercises Before Programming……….. 530
Programming Problems……….. 531

 

Chapter 13 — Binary I/O and Manipulator Functions 532

Introduction……….. 532
Dealing with Binary Files……….. 532
C++ Mechanics of Binary File Operations……….. 533
Physical I/O Versus Logical I/O Operations………… 535
Example 1: Reading and Writing Several Arrays to/from One Binary File……….. 539
Example 2: Processing an Array of Cost Records Blazingly Fast……….. 540
Example 3: Using Dynamic Allocation for an Array of Unknown Number of Records……….. 541
Pgm13a — Speed Testing of Binary File Processing……….. 542
Multiple Projects in a Single Workspace……….. 545
Overview of Direct Access File Processing Operations……….. 557
The Relative Record Number Method……….. 557
The Remainder Method……….. 558
The Indexed Sequential Access Method (ISAM)……….. 560
Handling Variable Length Records……….. 561
Handling Update Files in C++……….. 562
Pgm13b — The Master File Update Program — Relative Record Method……….. 562
Structure Alignment……….. 569
Writing Your Own Manipulator Functions……….. 573
Review Questions……….. 575
Stop! Do These Exercises Before Programming……….. 577
Programming Problems……….. 580

 

Chapter 14 — Persistent Data Objects.. 584

Introduction……….. 584
A First Attempt That Fails……….. 584
A Second Attempt That Fails……….. 585
A Third Attempt That Fails……….. 585
Making a Class Persistent the MFC Way……….. 586
Review Questions……….. 602
Stop! Do These Exercises Before Programming……….. 602
Programming Problems……….. 604

 

Appendix A — A Review of Array and Structure Processing… 606

A Review of Single Dimensioned Array Operations……….. 606
Using an Array for Direct Lookup Operations……….. 606
Parallel Arrays and Sequential Searches — Inquiry Programs……….. 607
Inserting Another Element into an Unsorted Array……….. 608
Ordered (Sorted) Lists……….. 609
The Binary Search Method……….. 610
Inserting New Data into a Sorted List……….. 611
A Review of Two-dimensional Array Processing……….. 613
Defining Multidimensional Arrays……….. 613
Physical Memory Layout Versus Logical Layout……….. 614
Initialization of Multidimensional Arrays……….. 615
Passing Multidimensional Arrays to Functions……….. 616
Loading a Multidimensional Array from an Input File……….. 617
Working with Multidimensional Arrays……….. 618
A Review of Structures……….. 622
Defining Structures……….. 622
Creating Instances of a Structure……….. 623
A Structure Can Contain Instances of Other Structures……….. 624
How are Structure Instances Initialized?……….. 625
How are Structure Members Accessed?……….. 625
Rules of Use for Structure Variables……….. 626

Appendix B – A Review of Pointers.. 630

Introduction……….. 630
Pointer Basics……….. 630
Defining Pointer Variables……….. 630
Initializing Pointers……….. 632
Dereferencing a Pointer……….. 633
The Rules of Pointer Arithmetic……….. 633
The Impact of Pointers on a Program……….. 639
The Use of Hybrids and Dual Incrementing……….. 640
Arrays of Pointers……….. 640
Handling Command Line Parameters in the main() Function……….. 642
The Use of the const Keyword with Pointers……….. 643

Appendix C — How to Use Microsoft’s Visual C++ 6… 644

Preface……….. 644
Step 0 — Get Organized……….. 644
Step 1 — Building the Program Project……….. 646
Step 1 — A. Bring up Windows and launch VC6……….. 646
Developer Studio Terms……….. 646
Your First Design Decision……….. 647
Step 1 — B Starting a New Workspace……….. 647
Step 1 — C Create new source cpp files to be contained in the project……….. 648
Step 1 — C Alternate Adding existing files to the project……….. 649
Step 2 — Transporting Programs to and from School Computers……….. 650
Step 3 — Opening an Existing Project……….. 651
Step 4 — Compiling the Program……….. 651
Step 5 — Handling Compile Errors……….. 652
Step 6 — Where is the executable file (*.exe) located?……….. 652
Step 7 — Running The Program……….. 652
Step 7A No input file — I will type in the input data when the program asks for it……….. 653
Step 7B — I want to use a file of provided test data but the program is not actually using an input file — it uses cin……….. 653
Step 7C — Using an Actual File Stream, an ifstream Instance……….. 654
Step 8 — Program Debugging and Execution……….. 655
What Can You Examine Using the Debugger?……….. 656
Checking the Contents of Variables……….. 657
Step 9 — The Help System……….. 657
Step 10 — Some VC6 Options……….. 658
Step 11 — Getting the hard copy documentation for programs to hand in to your instructor — or how to run your program at the DOS prompt……….. 659
Under Win2000……….. 660
Running Your Program from a DOS Prompt……….. 661

Appendix D — How to Use Microsoft’s Visual C++ 7 .Net Compiler… 665

Index……. 689

Back to previous book promo page

Share Button