C++ For Dummies 5th Edition (TOC)

cpp for dummies 5th edition
Click Here To Download Book
Pages 431
Views 18916
Size 7.7 MB
Download 111
Table of Contents8


What’s in This Book18

What’s on the CD19

What Is C++?19

Conventions Used in This Book19

How This Book Is Organized20

And There’s More21

Part I: Introduction to C++ Programming21

Part II: Becoming a Functional C++ Programmer21

Part III: Introduction to Classes22

Part IV: Inheritance22

Part V: Optional Features22

Part VI: The Part of Tens22

Icons Used in This Book23

Where to Go from Here23

Part I: Introduction to C++ Programming 24

Chapter 1: Writing Your First C++ Program 26

Grasping C++ Concepts27

What’s a program?27

How do I program?28

Installing Dev-C++29

Setting the options32

Creating Your First C++ Program33

Entering the C++ code34

Building your program35

Executing Your Program37

Dev-C++ is not Windows38

Dev-C++ help38

Reviewing the Annotated Program38

Examining the framework for all C++ programs39

Clarifying source code with comments39

Basing programs on C++ statements40

Writing declarations41

Generating output42

Calculating Expressions42

Storing the results of expression43

Examining the remainder of Conversion.cpp43

Chapter 2: Declaring Variables Constantly 44

Declaring Variables44

Declaring Different Types of Variables45

Reviewing the limitations of integers in C++46

Solving the truncation problem47

Looking at the limits of floating-point numbers48

Declaring Variable Types50

Types of constants51

Special characters52

Are These Calculations Really Logical?53

Mixed Mode Expressions53

Chapter 3: Performing Mathematical Operations 56

Performing Simple Binary Arithmetic57

Decomposing Expressions58

Determining the Order of Operations59

Performing Unary Operations60

Using Assignment Operators62

Chapter 4: Performing Logical Operations64

Why Mess with Logical Operations?64

Using the Simple Logical Operators65

Storing logical values66

Using logical int variables68

on floating-point variables68

Expressing Binary Numbers70

The decimal number system71

Other number systems71

The binary number system71

Performing Bitwise Logical Operations73

The single bit operators74

Using the bitwise operators75

Asimple test76

Do something logical with logical calculations77

Chapter 5: Controlling Program Flow 78

Controlling Program Flow with the Branch Commands78

Executing Loops in a Program80

Looping while a condition is true81

Using the autoincrement/autodecrement feature82

Using the for loop84

Avoiding the dreaded infinite loop86

Applying special loop controls87

Nesting Control Commands90

Switching to a Different Subject?91

Part II: Becoming a Functional C++ Programmer94

Chapter 6: Creating Functions96

Writing and Using a Function96

Defining the sumSequence( ) function98

Calling the function sumSequence( )99

Divide and conquer99

Understanding the Details of Functions100

Understanding simple functions101

Understanding functions with arguments102

Overloading Function Names104

Defining Function Prototypes106

Variable Storage Types108

Including Include Files108

Chapter 7: Storing Sequences in Arrays110

Considering the Need for Arrays110

Using an array112

Initializing an array115

Accessing too far into an array116

Using arrays116

Defining and using arrays of arrays117

Using Arrays of Characters117

Creating an array of characters117

Creating a string of characters118

Manipulating Strings with Character120

String-ing Along Variables123

Chapter 8: Taking a First Look at C++ Pointers126

Variable Size126

What’s in an Address?127

Address Operators128

Using Pointer Variables129

Comparing pointers and houses131

Using different types of pointers131

Passing Pointers to Functions134

Passing by value134

Passing pointer values135

Passing by reference136

Making Use of a Block of Memory Called the Heap136

Limiting scope137

Examining the scope problem138

Providing a solution using the heap139

Chapter 9: Taking a Second Look at C++ Pointers142

Defining Operations on Pointer Variables142

Re-examining arrays in light of pointer variables143

Applying operators to the address of an array145

Expanding pointer operations to a string146

Justifying pointer-based string manipulation148

Applying operators to pointer types other than char148

Contrasting a pointer with an array149

Declaring and Using Arrays of Pointers150

Utilizing arrays of character strings151

Accessing the arguments to main( )153

Chapter 10: Debugging C++156

Identifying Types of Errors156

Choosing the WRITE Technique for the Problem157

Calling for the Debugger163

Defining the debugger164

Finding commonalities among us164

Running a test program165

Single-stepping through a program166

Part III: Introduction to Classes172

Chapter 11: Examining Object-Oriented Programming174

Abstracting Microwave Ovens174

Preparing functional nachos175

Preparing object-oriented nachos176

Classifying Microwave Ovens176

Why Classify?177

Chapter 12: Adding Class to C++178

Introducing the Class178

The Format of a Class179

Accessing the Members of a Class180

Chapter 13: Making Classes Work184

Activating Our Objects185

Simulating real-world objects185

Why bother with member functions?186

Adding a Member Function186

Creating a member function187

Naming class members188

Calling a Member Function188

Accessing a member function189

Accessing other members from a member function191

Your Microscope Works)192

Defining a Member Function in the Class194

Keeping a Member Function After Class196

Overloading Member Functions198

Chapter 14: Point and Stare at Objects200

Defining Arrays of and Pointers to Simple Things200

Declaring Arrays of Objects201

Declaring Pointers to Objects202

Dereferencing an object pointer203

Pointing toward arrow pointers204

Passing Objects to Functions204

Calling a function with an object value205

Calling a function with an object pointer206

Calling a function by using the reference operator208

Why Bother with Either Pointers or References?209

Returning to the Heap209

Comparing Pointers to References210

Why Not Use References Rather Than Pointers?210

Linking Up with Linked Lists212

Performing other operations on a linked list213

Hooking up with a LinkedListData program214

ARay of Hope: A List of Containers Linked to the C++ Library217

Chapter 15: Protecting Members: Do Not Disturb218

Protecting Members218

Why you need protected members218

Discovering how protected members work219

Making an Argument for Using Protected Members221

Protecting the internal state of the class221

Using a class with a limited interface222

Giving Non-Member Functions Access to Protected Members222

Chapter 16: “Why Do You Build Me Up226

Just to Tear Me Down, Baby?”226

Creating Objects226

Using Constructors227

Why you need constructors227

Making constructors work229

Dissecting a Destructor234

Why you need the destructor234

Working with destructors234

Chapter 17: Making Constructive Arguments238

Outfitting Constructors with Arguments238

Justifying constructors239

Using a constructor239

Overloading the Constructor240

Defaulting Default Constructors244

Constructing Class Members245

Constructing a complex data member245

Constructing a constant data member249

Constructing the Order of Construction250

Local objects construct in order251

Static objects construct only once251

All global objects construct before main( )252

Global objects construct in no particular order252

Members construct in the order in which they are declared253

of the constructors254

Chapter 18: Copying the Copy Copy Copy Constructor256

Copying an Object256

Why you need the copy constructor256

Using the copy constructor257

The Automatic Copy Constructor259

Creating Shallow Copies versus Deep Copies261

It’s a Long Way to Temporaries265

Avoiding temporaries, permanently266

Referring to the copy constructor’s referential argument267

Chapter 19: Static Members: Can Fabric Softener Help?268

Defining a Static Member268

Why you need static members268

Using static members269

Referencing static data members270

Uses for static data members272

Declaring Static Member Functions272

What Is This About, Anyway?275

Part IV: Inheritance276

Chapter 20: Inheriting a Class278

Do I Need My Inheritance?279

How Does a Class Inherit?280

Using a subclass282

Constructing a subclass282

Destructing a subclass284

Having a HAS_A Relationship284

Chapter 21: Examining Virtual Member Functions286

Are They for Real?286

Why You Need Polymorphism289

How Polymorphism Works291

Implementing Abstract Classes296

Describing the abstract class concept298

Making an honest class out of an abstract class299

Passing abstract classes301

Declaring pure virtual functions — is it really necessary?302

Factoring C++ Source Code303

Dividing the program — Student304

Defining a namespace305

Implementing Student306

Dividing the program — GraduateStudent307

Implementing an application308

Project file310

Creating a project file under Dev-C++310

Part V: Optional Features315

Chapter 23: A New Assignment Operator317

Should You Decide to Accept It317

Comparing Operators with Functions317

Inserting a New Operator318

Creating Shallow Copies Is a Deep Problem319

Overloading the Assignment Operator320

Protecting the Escape Hatch323

Chapter 24: Using Stream I/O325

How Stream I/O Works325

The fstream Subclasses327

Reading Directly from a Stream332

What’s Up with endl?334

Using the strstream Subclasses334

Manipulating Manipulators337

Chapter 25: Handling Errors — Exceptions341

Justifying a New Error Mechanism?343

Examining the Exception Mechanism344

What Kinds of Things Can I Throw?347

Chapter 26: Inheriting Multiple Inheritance351

Describing the Multiple Inheritance Mechanism351

Straightening Out Inheritance Ambiguities353

Adding Virtual Inheritance354

Constructing the Objects of Multiple Inheritance361

Voicing a Contrary Opinion361

Chapter 27: Tempting C++ Templates363

Generalizing a Function into a Template365

Template Classes367

Do I Really Need Template Classes?370

Tips for Using Templates373

Chapter 28: Standardizing on the Standard Template Library375

The string Container376

The list Containers378


Using Maps383

Part VI: The Part of Tens387

Chapter 29: Ten Ways to Avoid Adding Bugs to Your Program389

Enabling All Warnings and Error Messages389

Insisting on Clean Compiles390

Adopting a Clear and Consistent Coding Style391

Limiting the Visibility391

Commenting Your Code While You Write It393

Single-Stepping Every Path at Least Once393

Avoid Overloading Operators394

Heap Handling394

Using Exceptions to Handle Errors394

Avoiding Multiple Inheritance395

Chapter 30: The Ten Most Important Optional Features 397

of Dev-C++397

Customize Editor Settings to Your Taste397

Highlight Matching Braces/Parentheses398

Enable Exception Handling399

Include Debugging Information (Sometimes)399

Create a Project File400

Customize the Help Menu400

Reset Breakpoints after Editing the File400

Avoid Illegal Filenames401

Include #include Files in Your Project401

Executing the Profiler401

Appendix: About the CD405

System Requirements405

Using the CD with Microsoft Windows406

Using the CD with Linux407

What You’ll Find408

Development tools408

Program source code409

IfYou’ve Got Problems (Of the CD Kind)409