书籍 absolute c++  second edition的封面

absolute c++ second editionPDF电子书下载

购买点数

20

出版社

出版时间

2222

ISBN

标注页数

0 页

PDF页数

979 页

标签

图书目录

Chapter 1 C++ BASICS 1

1.1 INTRODUCTION TO C+ 2

Origins of the C++ Language 2

C++ and Object-Oriented Programming 3

The Character Of C+++ 3

C++ Terminology y 4

A Sample C++ Program y 4

1.2 VARIABLES, EXPRESSIONS, AND ASSIGNMENT STATEMENTS 6

Identifiers 6

Variables 8

Assignment Statements 10

Pitfall: Uninitialized Variables 12

Tip: Use Meaningful Names 13

More Assignment Statements 13

Assignment Compatibility 14

Literals 15

Escape Sequences 17

Naming Constants 17

Arithmetic Operators and Expressions 19

Integer and Floating-Point Division 21

Pitfall: Division and whole Number 22

Type Casting 23

Increment and Decrement Operators 25

Pitfall: Order of Evaluation 27

1.3 CONSOLE NPT/OUPU 28

output Using cout 28

New Lines in Output 29

Tip: End Each Program with n or endl 30

Formaing for Numbers with a Decimal Point 31

Output with cerr 32

Input Using cin 32

Tip: Line Breaks in l/O 34

1.4 PROGRAM STYLE 35

Comments 35

1.5 LIBRARIES AND NAMESPACES 36

Libraries and include Directives 36

Namespaces 37

Pitfall: Problems with Libra Names 38

Chapter Summa 38

Answers to Self-Test Exercises 39

Programming Projects 41

Chapter 2 FLOW Of CONTROL 45

2.1 BOOLEAN EXPRESSION 46

Building Boolean Expressions 46

Pitfall: Strings of Inequalities 47

Evaluating Boolean Expressions 48

Precedence Rule 50

Pitfall: Integer Values Can Be Used as Boolean Values 54

2.2 BRANCHING MECHANISMS 57

if-else Statements 57

Compound Statements 57

Pitfall: Using in Place of - - 59

Omiing the else 61

Nested Statement 62

Multiway if-else Statement 62

The switch Statement 62

Pitfall: Forgeing a break in a switch Statement 66

Tip: Use switch Statements for Menu 66

Enumeration Types 66

The Conditional Operation 67

2.3 LOOPS 69

The while and do-while Statements 69

Increment and Deement Operators Revisited 72

The Comma Operator 75

The for Statement 76

Tip: Repeat-N-Times Loops 79

Pitfall: Extra Semicolon in a for Statement 79

Pitfall: infinite Loops 80

The break and continue Statement 83

Nested Loops 86

Chapter Summa 86

Answers to Self-Test Exercises 87

Programming Projects 92

Chapter 3 FUNCTION BASICS 95

3.1 PREDEFINED FUNCTIONS 96

Predefined Funions That Retu a Value 96

Predefined void Functions 101

A Random Number Generator 103

3.2 PROGRAMMER-DEFINED FUNCTIONS 108

Defining Functions That Return a Value 108

Alternate Form for Function Declarations 111

Pitfall: Arguments in the Wrong Order m 111

Pitfall: Use the Terms Parameterand Argument in 111

Functctions Calling Functions 112

Example: A Rounding Function 112

Functions That Return a Boolean Value 114

Defining void Functions 115

retuct Statements in void Funions 117

Preconditions and Postconditions 119

main is a Function 119

Recursive Functions 120

3.3 SCOPE RULES 121

Local Variables 122

Procedural Abstraion 122

Global Constants and Global Variables 125

Blocks 128

Nested Scopes 129

Tip: Use Funion Calls in Branching and Loop Statements 129

Variables Declared in a for Loop 130

Chapter Summary 131

Answers to Self-Test Exercises 131

Programming Projects 135

Chapter 4 PARAMETERS AND OVERLOADING 139

4.1 PARAMETERS 140

Call-by-Value Parameters 140

A Fit Look at Call-by-Reference Parameters 143

Call-by-Reference Mechanism in Detail 145

Constant Reference Parameters 147

Example: The swapValues Function 148

Tip: Think of Actions, Not Code 149

Mixed Parameter Lists 150

Tip: What Kind of Parameter to Use 151

Pitfall: Inadvertent Local Variables 152

Tip: Choosing Formal Parameter Names 155

Example: Buying Pizza 155

4.2 OVERLOADING AND DEFAULT ARGUMENTS 158

Introduction to overloading 159

Pitfall: Automatic Type Conversion and Overloading 161

Rules for Resolving overloading 163

Example: Revised Pizza-Buying Program 164

Default Arguments 167

4.3 TESTING AND DEBUGGING FUNCTIONS 169

The assert Mao 169

Stubs and Drivers 170

Chapter Summary 176

Answers to Self-Test Exercises 176

Programming Projects 176

Chapter5 ARRAYS 181

5.1 INTRODluCTION TO ARRAYS 182

Declaring and Referencing Arrays 182

Tip: Use for Loops with Aays 185

Pitfall: Aay Indexes Always Sta with Zero 185

Tip: Use a Defined Constant for the Size of an Aay 185

Aays in Memo 186

Pitfall: Aay Index Out of Range 187

Initializing Aays 189

5.2 ARRAYS IN FUNCTIONS 191

Indexed Variables as Funion Arguments 191

Entire Aays as Funion Arguments 193

TheconstParameter Modifier 196

Pitfall: Inconsistent Use of const Paramete 198

Functions That Retum an Array 198

Example: Production Graph 199

5.3 PROGRAONG WITH ARRAYS 204

Paially Filled Arrays 204

Tip: Do Not Skimp on Formal Paramete 205

Example: Searching an Array 207

Example: Soing an Array 210

5.4 MULTIDlAENSIONAL ARRAYS 214

Multidimensional Array Basics 214

Multidimensional Array Parameters 216

Example: Two-Dimensional Grading Program 217

Chapter Summa 222

Answers to Self-Test Exercises 223

Programming Projects 227

Chapter 6 STRUCTURES AND CLASSES 235

6.1 STRUCTURES 236

Structure Types 238

Pitfall: Forgeing a Semicolon in a Structure Definition 242

Structures as Function Arguments 242

Tip: Use Hierarchical Structures 243

Initializing Structures 246

6.2 CLASSES 249

Defining Classes and Member Functions 249

Encapsulation 254

Public and Private Members 255

Accessor and Mutator Functions 259

Tip: Separate Interface and implementation 261

Tip: A Test for Encapsulation 262

Structures versus Classes 263

Tip: Thinking Objects 265

Chapter Summary 265

Answers to Self-Test Exercises 266

Programming Projects 268

Chapter 7 CONSTRUCTORS AND OTHER TOOLS 271

7.1 CONSTRUCTORS 272

ConstructoTDefinitions 272

Pitfall: Constructors with No Arguments 277

Explicit Constructor Calls 279

Tip: Always Include a Default Constructor 279

Example: BonkAccount Class 282

Class Type Member Variables 288

7.2 MORE TOOLS 291

The const Parameter Modifier 292

Pitfall: Inconsistent Use of const 294

Inline Functions 298

Static Members 299

Nested and Local Class Definitions 304

7.3 VECTORS—A PREVIEWS OF THE STANDARD TEMPLATE LIBRARY 304

Vector Basics 305

Pitfall: Using Square Brackets beyond the Vector Size 308

Tip: Vector Assignment Is Well Behaved 309

Efficiency Issues 309

Chapter Summa 311

Answers to Self-Test Exercises 311

Programming Projects 314

Chapter 8 OPERATOR OVERLOADING, FRIENDS, AND REFERENCES 317

8.1 BASIC OPERATOR OVERLOADING 318

Overloading Basics 319

Tip: A Constructor Can Return an Object 324

Returning by const Value 325

Tip: Retuing Member Variables of a Class Type 328

Overloading Una Operators 329

Overloading as Members Functions 330

Tip: A Class Has Access to All its objects 332

Overloading Function Application ( ) 333

Pitfall: Overloading , ll, and the Comma Operator 334

8.2 FRIEND FUNCTIONS AND AUTOMATk TYPE CONVERSION 334

Constructors for Automatic Type Conversion 334

Pitfall: Member Operators and Automatic Type Conversion 335

Friend Functions 336

Pitfall: Compilers without Friends 340

Friend Classes 340

8.3 REFERENCES AND MORE OVERLOADED OPERATORS 342

References 342

Pitfall: Returning a Reference to Ceain Member Variables 343

Overloading and 344

Tip: What Mode of Retued Value to Use 351

The Assignment Operator 353

Overloading the Increment and Deement Operato 354

Overloading the Array operator 357

Overloading Based on L-Value veus R-value 359

Chapter Summa 359

Answers to self-Test Exercises 360

Programming Projects 362

Chapter 9 STRINGS 367

9.1 AN ARRAY TYPE FOR STRINGS 368

C-String Values and C-String Variables 369

Pitfall:Using and- with C-Strings 373

Other Functions in <cstring> 375

C-String Input and Output 379

9.2 CHARACTER MANIPULATION TOOLS 382

Character l/O 382

The Member Functions get and put 382

Example: Checking Input Using a Newfine Function 385

Pitfall: Unexpected n in Input 386

The putback, peek, and ignore Member Functions 388

Character-Manipulating Functions 390

Pitfall: toupper and tolower Retu int Values 392

9.3 THE STANDARD CLASS string 394

Introduction to the Standard Class string 394

l/O with the Class string 396

Tip: More Versions of getline 401

Pitfall: Mixing cin variable; and getline 401

String Processing with the Class string 402

Example: Palindrome Testing 406

Converting between string Objes and C-Strings 411

Chapter Summa 411

Answers to Self-Test Exercises 412

Programming Projes 415

Chapter 10 POINTERS AND DYNAMIC ARRAYS 421

10.1 POINTERS 422

Pointer Variables 423

Basic Memo Management 431

Pitfall: Dangling Pointers 434

Dynamic Variables and Automatic Variables 434

Tip: Define Pointer Types 435

Pitfall: Pointers as Call-by-Value Parameters 437

Uses for Pointers 439

10.2 DYNAMIC ARRAYS 439

Array Variables and Pointer Variables 439

Creating and Using Dynamic Aays 441

Example: A Function That Retus an Aay 445

Pointer Arithmetic 447

Multidimensional Dynamic Aays 448

10.3 CLASSES POINTERS AND DYNAC ARRAYS 451

The -> Operator 451

The this Pointer 452

Overloading the Assignment Operator 453

Example: A Class for Paially Filled Aays 456

Destructors 463

Copy Constructors 465

Chapter Summary 469

Answers to Self-Test Exercises 470

Programming Projects 472

Chapter 11 SEPARATE COMPILATION AND NAMESPACES 475

11.1SEPARATE COMPILATION 476

Encapsulation Reviewed 477

Header Files and Implementation Files 478

Example: DigitalTime Class 486

Tip: Reusable Components 487

Using #ifndef 487

Tip: Defining Other Libraries 490

11.2 NAMESPACES 491

Namespaces and using Directives 491

Creating a Namespace 493

Using Declarations 496

Qualifying Names 498

Tip: Choosing a Name for a Namespace 500

Example: A Class Definition in a Namespace 501

Unnamed Namespaces 502

Pitfall: Confusing the Global Namespace and the Unnamed Namespace 509

Tip: Unnamed Namespaces Replace the static Qualifer 509

Tip: Hiding Helping Functions 509

Nested Namespaces 510

Tip: What Namespace Specification Should You Use? 510

Chapter Summa 514

Answers to Self-Test Exercises 514

Programming Projects 516

Chapter 12 STREAMS AND FILE l/O 519

12.1 l/O STREAMS 521

File l/O 521

Pitfall: Restrictions on Stream Variables 526

Appending to a File 526

Tip: Another Syntax for Opening a File 528

Tip: Check That a File Was Opened Successfully 529

Character l/O 532

Checking for the End of a File 533

12.2 TOOLS FOR STREAM l/O 537

File Names as Input 537

Formaing output with Stream Functions 538

Manipulators 542

Saving Flag Seings 543

More Output Stream Member Functions 544

Example: Cleaning Up a File Format 546

Example: Editing a Text File 548

12.3 STREAM HIERARCHIES: A PREVIEW OF INHERITANCE 551

Inheritance among Stream Classes 551

Example: Another newline Function 553

12.4 RANDOM ACCESS TO FILES 557

Chapter Summa 559

Answe to Self-Test Exercises 559

Programming Projects 562

Chapter 13 RECURSION 571

13.1 RECURSIVE void FUNCTIONS 573

Example: Vertical Numbers 573

Tracing a Recursive Call 576

A Closer look at Recuion 579

Pitfall: Infinite Recursion 580

Stacks for Recuion 582

Pitfall: Stack overflow 584

Recursion versus iteration 584

13.2 RECURSIVE FUNCTIONS THAT RETURN A VALUE 585

General Form for a Recursive Function That Retus a Value 585

Example: Another Powers Function 586

13.3 THINKING RECURSIVELY 591

Recursive Design Techniques 591

Bina Search 592

Chapter Summa 601

Answe to Self-Test Exercises 601

Programming Projects 606

Chapter 14 INHERITANCE 609

14.1 INHERITANCE BASICSDerived Classes 610

Constructo in Derived Classes 620

Pitfall: Use of Private Member Variables from the Base Class 622

Pitfall: Private Member Functions Are Effectively Not Inherited 624

The protected Qualifier 624

Redefinition of Member Functions 627

Redefining veus Overloading 629

Access to a Redefined Base Function 630

Functions That Are Not Inherited 631

14.2 PROGRAMANING WITH INHERITANCE 633

Assignment Operato and Copy Constructors in Derived Classes 633

Destructors in Derived Classes 634

Example: Paially Filled Array with Backup 634

Pitfall: Same Object on Both Sides of the Assignment Operator 643

Example: Alteate Implementation of PFArrayDBak 644

Tip: A Class Has Access to Private Membe of All Objects of the Class 647

Tip: “Is a” versus “Has a” 647

Protected and Private Inheritance 648

Multiple Inheritance 649

Chapter Summa 650

Answe to Self-Test Exercises 650

Programming Projects 652

Chapter15 POLYMORPHISM AND VIRTUAL FUNCTIONS 655

15.1 VIRTUAL FUNCTION BASICS 656

LAte Binding 656

Virtual Functions in C+++ 657

Tip: The Virtual Property Is Inherited 664

Tip: When to Use a Virtual Function 664

Pitfall: Omiing the Definition of a Virtual Member Function 665

Abstract Classes and Pure Viual functions 665

Example: An Abstract Class 667

15.2 POINTERS AND VIRTU FUNCTIONS 669

Virtual Functions and Extended Type Compatibility 669

Pitfall: The Slicing Problem 674

Tip: Make Destructo Viual 675

Downcasting and Upcasting 676

How C++ Implements Viual Functions 678

Chapter Summa 679

Answe to Self-Test Exeises 679

Programming Projects 680

Chapter 16 TEMPLATES 683

16.1 FUNCTION TEMPLATES 684

Syntax for Function Templates 686

Pitfall: Compiler Complitions 689

Tip: How to Define Templates 690

Example: A Generic Soing Funion 692

Pitfall: Using a Template with an Inappropriate Type 696

16.2 CLASS TEMPLATES 698

Syntax for Class Templates 698

Example: An Aay Template Class 703

The vector and basic-string Templates 709

16.3 TEMPALTES AND INHERITANCE 709

Example: Template Class for a Partially Filled Array with Backup 710

Chapter Summary 716

Answers to Self-Test Exercises 716

Programming Projects 720

Chapter 17 LINKED DATA STRUCTURES 721

17.1 NODES AND LINKED LISTS 723

Nodes 723

Linked Lists 728

Inserting a Node at the Head of a List 730

Pitfall: Losing Nodes 733

Inseing and Removing Nodes Inside a List 734

Pitfall: Using the Assignment Operator with Dynamic Data Structures 738

Searching a Linked List 738

Example: A Generic Soing Template Version of Linked List Tools 743

17.2 LINKED LIST APPLICATIONS 747

Example: A Stack Template Class 748

Example: A Queue Template Class 755

Tip: A Comment on Namespaces 758

Friend Classes and Similar Alternatives 759

17.3 ITERATORS 762

Pointers as Iterators 762

Iterator Classes 763

Example: An Iterator Class 764

17.4 TREES 771

Tree Propeies 772

Example: A Tree Template Class 775

Chapter Summa 780

Answers to Self-Test Exercises 780

Programming Projects 788

Chapter18 EXCEPTION HANDLING 793

18.1 EXCEPTION HANDLING BASICS 795

A Toy Example of Exception Handling 795

Defining Your Own Exception Classes 804

Multiple Throws and Catches 806

Pitfall: Catch the More Specific Exception First 808

Tip: Exception Classes Can Be Trivial 809

Throwing an Exception in a Function 810

Exception Specification 810

Pitfall: Exception Specification in Derived Classes 814

18.2 PROGRAMMING TECHNIQUES FOR EXCEPTION HANDLING 815

When to Throw an Exception 815

Pitfall: Uncaught Exceptions 817

Pitfall: Nested try-catch Blocks 817

Pitfall: overuse of Exceptions 818

Exception Class Hierarchies 818

Testing for Available Memo 818

Rethrowing an Exception 819

Chapter Summa 819

Answers to Self-Test Exercises 820

Programming Projects 821

Chapter19 STANDARD TEMPLATE LIBRARY 823

19.1 ITERATORS 825

Iterator Basi 825

Kinds of Iterators 831

Constant and Mutable Iterators 834

Revee Iterators 836

Pitfall: Compiler Problems 838

Other Kinds of Iterato 838

19.2 CONTAINERS 839

Sequential Containers 839

Pitfall: Iterato and Removing Elements 844

Tip: Type Definitions in Containers 844

The Container Adapters stack and queue 845

The Associative Containe set and nap 846

Efficiency 851

19.3 GENERc: ALGORITHMS 853

Running Times and Big-ONotation 854

Container Access Running Times 858

Nonmodifying Sequence Algorithms 859

Modifying Sequence Algorithms 863

Set Algorithms 865

Soing Algorithms 865

Chapter Summa 867

Answers to Self-Test Exercises 868

Programming Projects 870

Chapter 20 PATENS AND UML 875

20.1 PATTERNS 876

Adapter Patte 877

The Model-View-Controller Paern 877

Example: A Soing Pattern 879

Efficiency of the Soing Pattern 885

Tip: Pragmatics and Paes 886

Pattern Formalism 886

20.2 UML 887

Histo of UML 887

UML Class Diagrams 888

Class Interactions 889

Chapter Summa 889

Answe to Self-Test Exercises 889

Programming Projects 891

Appendix 1 C+++ Keywords 893

Appendix 2 Precedence of operators 895

Appendix 3 The ASCII Character Set 899

Appendix 4 Some Libra Functions 901

Arithmetic Funions 901

Input and Output Member functions 902

Charaer Functions 903

C-String Functions 904

string Class Functions 906

Random Number Generator 907

Trigonometric functions 908

Appendix5 Old and New Header Files 909

Further Reading 911

lndex 913

查看更多关于的内容

相关书籍
出版社其它书籍
在线购买PDF电子书
下载此书RAR压缩包