Home > Store

C++ How to Program (Early Objects Version), 9th Edition

Register your product to gain access to bonus material or receive a coupon.

C++ How to Program (Early Objects Version), 9th Edition

Book

  • Your Price: $177.08
  • List Price: $208.33
  • Usually ships in 24 hours.

About

Features

TOTAL LEARNING PACKAGE

MyProgrammingLab for C++ How to Program  is a total learning package. MyProgrammingLab is an online homework, tutorial, and assessment program that truly engages students in learning. It helps students better prepare for class, quizzes, and exams–resulting in better performance in the course–and provides educators a dynamic set of tools for gauging individual and class progress. And, MyProgrammingLab comes from Pearson, your partner in providing the best digital learning experience.

Through the power of practice and immediate personalized feedback, MyProgrammingLab helps students fully grasp the logic, semantics, and syntax of programming. A self-study and homework tool, a MyProgrammingLab course consists of hundreds of small practice problems organized around the structure of this textbook. For students, the system automatically detects errors in the logic and syntax of their code submissions and offers targeted hints that enable them to figure out what went wrong–and why. For instructors, a comprehensive roster tracks correct and incorrect answers and stores the code inputted by students for review.

Note: If you are purchasing the standalone text or electronic version, MyProgrammingLab does not come automatically packaged with the text. To purchase MyProgrammingLab, please visit: myprogramminglab.com or you can purchase a package of the physical text + MyProgrammingLab by searching the Pearson Higher Education web site.  MyProgrammingLab is not a self-paced technology and should only be purchased when required by an instructor.


Object-Oriented Programming

  • Early-objects approach. The book introduces the basic concepts and terminology of object technology in Chapter 1. You’ll develop your first customized classes and objects in Chapter 3. Presenting objects and classes early gets you “thinking about objects” immediately and mastering these concepts more thoroughly. (For courses that require a late-objects approach, consider C++ How to Program, Late Objects Version, which begins with six chapters on programming fundamentals (including two on control statements) and continues with seven chapters that gradually introduce object-oriented programming concepts.)
  • C++ Standard Library string. C++ offers two types of strings–string class objects (which we begin using in Chapter 3) and C strings. We’ve replaced most occurrences of C strings with instances of C++ class string to make programs more robust and eliminate many of the security problems of C strings. We continue to discuss C strings later in the book to prepare you for working with the legacy code that you’ll encounter in industry. In new development, you should favor string objects.
  • C++ Standard Library array. Our primary treatment of arrays now uses the Standard Library’s array class template instead of built-in, C-style, pointer-based arrays. We still cover built-in arrays because they remain useful in C++ and so that you’ll be able to read legacy code. C++ offers three types of arrays–arrays and vectors (which we start using in Chapter 7) and C-style, pointer-based arrays which we discuss in Chapter 8. As appropriate, we use class template array instead of C arrays throughout the book. In new development, you should favor class template array objects.
  • Crafting valuable classes. A key goal of this book is to prepare you to build valuable classes. In the Chapter 10 case study, you’ll build your own custom Array class, then in the Chapter 18 exercises you’ll convert it to a class template. You’ll truly appreciate the class concept. Chapter 10 begins with a test-drive of class template string so you can see an elegant use of operator overloading before you implement your own customized class with overloaded operators.
  • Case studies in object-oriented programming. We provide case studies that span multiple sections and chapters and cover the software development lifecycle. These include the GradeBook class in Chapters 3—7, the Time class in Chapter 9 and the Employee class in Chapters 11—12. Chapter 12 contains a detailed diagram and explanation of how C++ can implement polymorphism, virtual functions and dynamic binding “under the hood.”
  • Optional case study: Using the UML to develop an object-oriented design and C++ implementation of an ATM. The UML™ (Unified Modeling Language™) is the industry-standard graphical language for modeling object-oriented systems. We introduce the UML in the early chapters. Online Chapters 25 and 26 include an optional case study on object-oriented design using the UML. We design and implement the software for a simple automated teller machine (ATM). We analyze a typical requirements document that specifies the system to be built. We determine the classes needed to implement that system, the attributes the classes need to have, the behaviors the classes need to exhibit and we specify how the classes must interact with one another to meet the system requirements. From the design we produce a complete C++ implementation. Students often report that the case study helps them “tie it all together” and truly understand object orientation.
  • Exception handling. We integrate basic exception handling early in the book. Instructors can easily pull more detailed material forward from Chapter 17, Exception Handling: A Deeper Look.
  • Custom template-based data structures. We provide a rich multi-chapter treatment of data structures–see the Data Structures module in the chapter dependency chart (Fig. 6).
  • Three programming paradigms. We discuss structured programming, object-oriented programming and generic programming.

Pedagogic Features

  • Rich coverage of C++ fundamentals. We include a clear two-chapter treatment of control statements and algorithm development.
  • Chapter 2 provides a simple introduction to C++ programming.
  • Examples. We include a broad range of example programs selected from computer science, business, simulation, game playing and other topics.
  • Audience. The examples are accessible to computer science, information technology, software engineering and business students in novice-level and intermediate level C++ courses. The book is also used by professional programmers.
  • Self-Review Exercises and Answers. Extensive self-review exercises and answers are included for self-study.
  • Interesting, entertaining and challenging exercises. Each chapter concludes with a substantial set of exercises, including simple recall of important terminology and concepts, identifying the errors in code samples, writing individual program statements, writing small portions of C++ classes and member and non-member functions, writing complete programs and implementing major projects. Exercises include our Making a Difference exercises, which encourage you to use computers and the Internet to research and solve significant social problems. We hope you’ll approach these exercises with your own values, politics and beliefs.
  • Illustrations and figures. Abundant tables, line drawings, UML diagrams, programs and program outputs are included.
  • VideoNotes. The Companion Website includes many hours of VideoNotes in which co-author Paul Deitel explains in detail key programs in the core chapters. We’ve created a jump table that maps each VideoNote to the corresponding figures in the book www.deitel.com/books/cpphtp9/jump_table.pdf

Other Features

  • Pointers. We provide thorough coverage of the built-in pointer capabilities and the intimate relationship among built-in pointers, C strings and built-in arrays.
  • Visual presentation of searching and sorting, with a simple explanation of Big O.
  • Printed book contains core content; additional content is online. A few online chapters and appendices are included. These are available in searchable PDF format on the book’s password-protected Companion Website.
  • Debugger appendices. We provide three debugger appendices on the book’s Companion Website–Appendix H, Using the Visual Studio Debugger, Appendix I, Using the GNU C++ Debugger and Appendix J, Using the Xcode Debugger.

Teaching Approach

  • C++ How to Program, 9/e, contains a rich collection of examples. We stress program clarity and concentrate on building well-engineered software.
  • Live-code approach. The book is loaded with “live-code” examples–most new concepts are presented in complete working C++ applications, followed by one or more executions showing program inputs and outputs. In the few cases where we use a code snippet, to ensure that it’s correct we tested it in a complete working program, then copied and pasted it into the book.
  • Syntax coloring. For readability, we syntax color all the C++ code, similar to the way most C++ integrated-development environments and code editors syntax color code.
  • Code highlighting. We place light-blue shaded rectangles around key code segments.
  • Using fonts for emphasis. We color the defining occurrence of each key term in bold blue text for easy reference. We emphasize on-screen components in the bold Helvetica font (e.g., the File menu) and C++ program text in the Lucida font (for example, int x = 5;).
  • Objectives. The opening quotes are followed by a list of chapter objectives.
  • Programming tips. We include programming tips to help you focus on key aspects of program development. These tips and practices represent the best we’ve gleaned from a combined seven decades of teaching and industry experience.
  • Summary Bullets. We present a section-by-section, bullet-list summary of the chapter. We include the page number of each term’s defining occurrence in the chapter for easy reference.
  • Index. We’ve included an extensive index, with defining occurrences of key terms highlighted with a bold blue page number.

Online Content

An access code to the Companion Website is available free when packaged with a new text. Companion Website access can also be purchased separately online. The book’s Companion Website, which is accessible at www.pearsonhighered.com/deitel contains the following chapters and appendices in searchable PDF format:

  • Chapter 24, C++11 Additional Topics
  • Chapter 25, ATM Case Study, Part 1: Object-Oriented Design with the UML
  • Chapter 26, ATM Case Study, Part 2: Implementing an Object-Oriented Design
  • Appendix F, C Legacy Code Topics
  • Appendix G, UML 2: Additional Diagram Types
  • Appendix H, Using the Visual Studio Debugger
  • Appendix I, Using the GNU C++ Debugger
  • Appendix J, Using the Xcode Debugger
  • Appendix K, Test Driving a C++ Program on Mac OS X. (The test drives for Windows and Linux are in Chapter 1.)

The Companion Website also includes:

  • Extensive VideoNotes–watch and listen as co-author Paul Deitel discusses key code examples in the core chapters of the book. VideoNotes are step-by-step video tutorials specifically designed to enhance the programming concepts presented in Deitel, C++ How to Program, 9e. Students can view the entire problem-solving process outside of the classroom–when they need help the most. VideoNotes are available with the purchase of a new copy of select titles. Go to www.pearsonhighered.com/videonotes for a brief VideoNotes demo.
  • Building Your Own Compiler exercise descriptions from Chapter 19 (posted at the Companion Website and at www.deitel.com/books/cpphtp9).
  • Chapter 1 test-drive for Mac OS X.

Description

  • Copyright 2014
  • Dimensions: 7" x 9-1/8"
  • Pages: 1072
  • Edition: 9th
  • Book
  • ISBN-10: 0-13-337871-3
  • ISBN-13: 978-0-13-337871-9

NOTE: You are purchasing a standalone product; MyProgrammingLab does not come packaged with this content. If you would like to purchase both the physical text and  MyProgrammingLab search for ISBN-10: 0133450732/ISBN-13: 9780133450736 . That package includes ISBN-10: 0133146146/ISBN-13: 9780133146141 and ISBN-10: 0133378713/ISBN-13: 9780133378719.

MyProgrammingLab should only be purchased when required by an instructor


For Introduction to Programming (CS1) and other more intermediate courses covering programming in C++. Also appropriate as a supplement for upper-level courses where the instructor uses a book as a reference for the C++ language.


This best-selling comprehensive text is aimed at readers with little or no programming experience. It teaches programming by presenting the concepts in the context of full working programs and takes an early-objects approach. The authors emphasize achieving program clarity through structured and object-oriented programming, software reuse and component-oriented software construction. The Ninth Edition encourages students to connect computers to the community, using the Internet to solve problems and make a difference in our world. All content has been carefully fine-tuned in response to a team of distinguished academic and industry reviewers.


MyProgrammingLab for C++ How to Program  is a total learning package. MyProgrammingLab is an online homework, tutorial, and assessment program that truly engages students in learning. It helps students better prepare for class, quizzes, and exams—resulting in better performance in the course—and provides educators a dynamic set of tools for gauging individual and class progress. And, MyProgrammingLab comes from Pearson, your partner in providing the best digital learning experience.


View the Deitel Buzz online to learn more about the newest publications from the Deitels.

Sample Content

Table of Contents

Chapters 24—26 and Appendices F—K are PDF documents posted online at the book’s Companion Website, which is accessible from www.pearsonhighered.com/deitel

Preface xxi

1 Introduction to Computers and C++ 1

1.1 Introduction 2

1.2 Computers and the Internet in Industry and Research 2

1.3 Hardware and Software 5

1.3.1 Moore’s Law 6

1.3.2 Computer Organization 6

1.4 Data Hierarchy 7

1.5 Machine Languages, Assembly Languages and High-Level Languages 9

1.6 C++ 10

1.7 Programming Languages 11

1.8 Introduction to Object Technology 14

1.9 Typical C++ Development Environment 17

1.10 Test-Driving a C++ Application 19

1.11 Operating Systems 25

1.11.1 Windows–A Proprietary Operating System 25

1.11.2 Linux–An Open-Source Operating System 26

1.11.3 Apple’s OS X; Apple’s iOS for iPhone®, iPad® and iPod Touch® Devices 26

1.11.4 Google’s Android 27

1.12 The Internet and World Wide Web 27

1.13 Some Key Software Development Terminology 29

1.14 C++11 and the Open Source Boost Libraries 31

1.15 Keeping Up to Date with Information Technologies 32

1.16 Web Resources 33

2 Introduction to C++ Programming; Input/Output and Operators 38

2.1 Introduction 39

2.2 First Program in C++: Printing a Line of Text 39

2.3 Modifying Our First C++ Program 43

2.4 Another C++ Program: Adding Integers 44

2.5 Memory Concepts 48

2.6 Arithmetic 49

2.7 Decision Making: Equality and Relational Operators 53

2.8 Wrap-Up 57

3 Introduction to Classes, Objects and Strings 66

3.1 Introduction 67

3.2 Defining a Class with a Member Function 67

3.3 Defining a Member Function with a Parameter 70

3.4 Data Members, set Member Functions and get Member Functions 74

3.5 Initializing Objects with Constructors 79

3.6 Placing a Class in a Separate File for Reusability 83

3.7 Separating Interface from Implementation 87

3.8 Validating Data with set Functions 92

3.9 Wrap-Up 97

4 Control Statements: Part 1; Assignment, ++ and -- Operators 104

4.1 Introduction 105

4.2 Algorithms 105

4.3 Pseudocode 106

4.4 Control Structures 107

4.5 if Selection Statement 110

4.6 if…else Double-Selection Statement 112

4.7 while Repetition Statement 116

4.8 Formulating Algorithms: Counter-Controlled Repetition 118

4.9 Formulating Algorithms: Sentinel-Controlled Repetition 124

4.10 Formulating Algorithms: Nested Control Statements 134

4.11 Assignment Operators 139

4.12 Increment and Decrement Operators 140

4.13 Wrap-Up 143

5 Control Statements: Part 2; Logical Operators 157

5.1 Introduction 158

5.2 Essentials of Counter-Controlled Repetition 158

5.3 for Repetition Statement 159

5.4 Examples Using the for Statement 163

5.5 do…while Repetition Statement 168

5.6 switch Multiple-Selection Statement 169

5.7 break and continue Statements 178

5.8 Logical Operators 180

5.9 Confusing the Equality (==) and Assignment (=) Operators 185

5.10 Structured Programming Summary 186

5.11 Wrap-Up 191

6 Functions and an Introduction to Recursion 201

6.1 Introduction 202

6.2 Program Components in C++ 203

6.3 Math Library Functions 204

6.4 Function Definitions with Multiple Parameters 205

6.5 Function Prototypes and Argument Coercion 210

6.6 C++ Standard Library Headers 212

6.7 Case Study: Random Number Generation 214

6.8 Case Study: Game of Chance; Introducing enum 219

6.9 C++11 Random Numbers 224

6.10 Storage Classes and Storage Duration 225

6.11 Scope Rules 228

6.12 Function Call Stack and Activation Records 231

6.13 Functions with Empty Parameter Lists 235

6.14 Inline Functions 236

6.15 References and Reference Parameters 237

6.16 Default Arguments 240

6.17 Unary Scope Resolution Operator 242

6.18 Function Overloading 243

6.19 Function Templates 246

6.20Recursion 248

6.21 Example Using Recursion: Fibonacci Series 252

6.22 Recursion vs. Iteration 255

6.23 Wrap-Up 258

7 Class Templates array and vector; Catching Exceptions 278

7.1 Introduction 279

7.2 arrays 279

7.3 Declaring arrays 281

7.4 Examples Using arrays 281

7.4.1 Declaring an array and Using a Loop to Initialize the array’s Elements 281

7.4.2 Initializing an array in a Declaration with an Initializer List 282

7.4.3 Specifying an array’s Size with a Constant Variable and Setting array Elements with Calculations 283

7.4.4 Summing the Elements of an array 286

7.4.5 Using Bar Charts to Display array Data Graphically 286

7.4.6 Using the Elements of an array as Counters 288

7.4.7 Using arrays to Summarize Survey Results 289

7.4.8 Static Local arrays and Automatic Local arrays 291

7.5 Range-Based for Statement 293

7.6 Case Study: Class GradeBook Using an array to Store Grades 295

7.7 Sorting and Searching arrays 302

7.8 Multidimensional arrays 304

7.9 Case Study: Class GradeBook Using a Two-Dimensional array 307

7.10 Introduction to C++ Standard Library Class Template vector 314

7.11 Wrap-Up 320

8 Pointers 334

8.1 Introduction 335

8.2 Pointer Variable Declarations and Initialization 335

8.3 Pointer Operators 337

8.4 Pass-by-Reference with Pointers 339

8.5 Built-In Arrays 344

8.6 Using const with Pointers 346

8.6.1 Nonconstant Pointer to Nonconstant Data 347

8.6.2 Nonconstant Pointer to Constant Data 347

8.6.3 Constant Pointer to Nonconstant Data 348

8.6.4 Constant Pointer to Constant Data 349

8.7 sizeof Operator 350

8.8 Pointer Expressions and Pointer Arithmetic 353

8.9 Relationship Between Pointers and Built-In Arrays 355

8.10 Pointer-Based Strings 358

8.11 Wrap-Up 361

9 Classes: A Deeper Look; Throwing Exceptions 377

9.1 Introduction 378

9.2 Time Class Case Study 379

9.3 Class Scope and Accessing Class Members 385

9.4 Access Functions and Utility Functions 386

9.5 Time Class Case Study: Constructors with Default Arguments 387

9.6 Destructors 393

9.7 When Constructors and Destructors Are Called 393

9.8 Time Class Case Study: A Subtle Trap–Returning a Reference or a Pointer to a private Data Member 397

9.9 Default Memberwise Assignment 400

9.10 const Objects and const Member Functions 402

9.11 Composition: Objects as Members of Classes 404

9.12 friend Functions and friend Classes 410

9.13 Using the this Pointer 412

9.14 static Class Members 418

9.15 Wrap-Up 423

10 Operator Overloading; Class string 433

10.1 Introduction 434

10.2 Using the Overloaded Operators of Standard Library Class string 435

10.3 Fundamentals of Operator Overloading 438

10.4 Overloading Binary Operators 439

10.5 Overloading the Binary Stream Insertion and Stream Extraction Operators 440

10.6 Overloading Unary Operators 444

10.7 Overloading the Unary Prefix and Postfix ++ and -- Operators 445

10.8 Case Study: A Date Class 446

10.9 Dynamic Memory Management 451

10.10 Case Study: Array Class 453

10.10.1 Using the Array Class 454

10.10.2 Array Class Definition 458

10.11 Operators as Member vs. Non-Member Functions 466

10.12 Converting Between Types 466

10.13 explicit Constructors and Conversion Operators 468

10.14 Overloading the Function Call Operator () 470

10.15 Wrap-Up 471

11 Object-Oriented Programming: Inheritance 482

11.1 Introduction 483

11.2 Base Classes and Derived Classes 483

11.3 Relationship between Base and Derived Classes 486

11.3.1 Creating and Using a CommissionEmployee Class 486

11.3.2 Creating a BasePlusCommissionEmployee Class Without Using Inheritance 491

11.3.3 Creating a CommissionEmployee—BasePlusCommissionEmployee Inheritance Hierarchy 497

11.3.4 CommissionEmployee—BasePlusCommissionEmployee Inheritance Hierarchy Using protected Data 501

11.3.5 CommissionEmployee—BasePlusCommissionEmployee

Inheritance Hierarchy Using private Data 504

11.4 Constructors and Destructors in Derived Classes 509

11.5 public, protected and private Inheritance 511

11.6 Software Engineering with Inheritance 512

11.7 Wrap-Up 512

12 Object-Oriented Programming: Polymorphism 517

12.1 Introduction 518

12.2 Introduction to Polymorphism: Polymorphic Video Game 519

12.3 Relationships Among Objects in an Inheritance Hierarchy 519

12.3.1 Invoking Base-Class Functions from Derived-Class Objects 520

12.3.2 Aiming Derived-Class Pointers at Base-Class Objects 523

12.3.3 Derived-Class Member-Function Calls via Base-Class Pointers 524

12.3.4 Virtual Functions and Virtual Destructors 526

12.4 Type Fields and switch Statements 533

12.5 Abstract Classes and Pure virtual Functions 533

12.6 Case Study: Payroll System Using Polymorphism 535

12.6.1 Creating Abstract Base Class Employee 536

12.6.2 Creating Concrete Derived Class SalariedEmployee 540

12.6.3 Creating Concrete Derived Class CommissionEmployee 542

12.6.4 Creating Indirect Concrete Derived Class BasePlusCommissionEmployee 544

12.6.5 Demonstrating Polymorphic Processing 546

12.7 (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood” 550

12.8 Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info 553

12.9 Wrap-Up 557

13 Stream Input/Output: A Deeper Look 562

13.1 Introduction 563

13.2 Streams 564

13.2.1 Classic Streams vs. Standard Streams 564

13.2.2 iostream Library Headers 565

13.2.3 Stream Input/Output Classes and Objects 565

13.3 Stream Output 567

13.3.1 Output of char * Variables 568

13.3.2 Character Output Using Member Function put 568

13.4 Stream Input 569

13.4.1 get and getline Member Functions 569

13.4.2 istream Member Functions peek, putback and ignore 572

13.4.3 Type-Safe I/O 572

13.5 Unformatted I/O Using read, write and gcount 572

13.6 Introduction to Stream Manipulators 573

13.6.1 Integral Stream Base: dec, oct, hex and setbase 574

13.6.2 Floating-Point Precision (precision, setprecision) 574

13.6.3 Field Width (width, setw) 576

13.6.4 User-Defined Output Stream Manipulators 577

13.7 Stream Format States and Stream Manipulators 578

13.7.1 Trailing Zeros and Decimal Points (showpoint) 579

13.7.2 Justification (left, right and internal) 580

13.7.3 Padding (fill, setfill) 582

13.7.4 Integral Stream Base (dec, oct, hex, showbase) 583

13.7.5 Floating-Point Numbers; Scientific and Fixed Notation (scientific, fixed) 584

13.7.6 Uppercase/Lowercase Control (uppercase) 585

13.7.7 Specifying Boolean Format (boolalpha) 585

13.7.8 Setting and Resetting the Format State via Member Function flags 586

13.8 Stream Error States 587

13.9 Tying an Output Stream to an Input Stream 590

13.10 Wrap-Up 590

14 File Processing 599

14.1 Introduction 600

14.2 Files and Streams 600

14.3 Creating a Sequential File 601

14.4 Reading Data from a Sequential File 605

14.5 Updating Sequential Files 611

14.6 Random-Access Files 611

14.7 Creating a Random-Access File 612

14.8 Writing Data Randomly to a Random-Access File 617

14.9 Reading from a Random-Access File Sequentially 619

14.10 Case Study: A Transaction-Processing Program 621

14.11 Object Serialization 628

14.12 Wrap-Up 628

15 Standard Library Containers and Iterators 638

15.1 Introduction 639

15.2 Introduction to Containers 640

15.3 Introduction to Iterators 644

15.4 Introduction to Algorithms 649

15.5 Sequence Containers 649

15.5.1 vector Sequence Container 650

15.5.2 list Sequence Container 658

15.5.3 deque Sequence Container 662

15.6 Associative Containers 664

15.6.1 multiset Associative Container 665

15.6.2 set Associative Container 668

15.6.3 multimap Associative Container 669

15.6.4 map Associative Container 671

15.7 Container Adapters 673

15.7.1 stack Adapter 673

15.7.2 queue Adapter 675

15.7.3 priority_queue Adapter 676

15.8 Class bitset 677

15.9 Wrap-Up 679

16 Standard Library Algorithms 690

16.1 Introduction 691

16.2 Minimum Iterator Requirements 691

16.3 Algorithms 693

16.3.1 fill, fill_n, generate and generate_n 693

16.3.2 equal, mismatch and lexicographical_compare 695

16.3.3 remove, remove_if, remove_copy and remove_copy_if 697

16.3.4 replace, replace_if, replace_copy and replace_copy_if 700

16.3.5 Mathematical Algorithms 702

16.3.6 Basic Searching and Sorting Algorithms 706

16.3.7 swap, iter_swap and swap_ranges 710

16.3.8 copy_backward, merge, unique and reverse 711

16.3.9 inplace_merge, unique_copy and reverse_copy 714

16.3.10 Set Operations 716

16.3.11 lower_bound, upper_bound and equal_range 719

16.3.12Heapsort 721

16.3.13 min, max, minmax and minmax_element 724

16.4 Function Objects 726

16.5 Lambda Expressions 729

16.6 Standard Library Algorithm Summary 730

16.7 Wrap-Up 732

17 Exception Handling: A Deeper Look 740

17.1 Introduction 741

17.2 Example: Handling an Attempt to Divide by Zero 741

17.3 Rethrowing an Exception 747

17.4 Stack Unwinding 748

17.5 When to Use Exception Handling 750

17.6 Constructors, Destructors and Exception Handling 751

17.7 Exceptions and Inheritance 752

17.8 Processing new Failures 752

17.9 Class unique_ptr and Dynamic Memory Allocation 755

17.10 Standard Library Exception Hierarchy 758

17.11 Wrap-Up 759

18 Introduction to Custom Templates 765

18.1 Introduction 766

18.2 Class Templates 766

18.3 Function Template to Manipulate a Class-Template Specialization Object 771

18.4 Nontype Parameters 773

18.5 Default Arguments for Template Type Parameters 773

18.6 Overloading Function Templates 774

18.7 Wrap-Up 774

19 Custom Templatized Data Structures 777

19.1 Introduction 778

19.2 Self-Referential Classes 779

19.3 Linked Lists 780

19.4Stacks 794

19.5Queues 799

19.6Trees 803

19.7 Wrap-Up 811

20 Searching and Sorting 822

20.1 Introduction 823

20.2 Searching Algorithms 824

20.2.1 Linear Search 824

20.2.2 Binary Search 827

20.3 Sorting Algorithms 831

20.3.1 Insertion Sort 832

20.3.2 Selection Sort 834

20.3.3 Merge Sort (A Recursive Implementation) 837

20.4 Wrap-Up 843

21 Class string and String Stream Processing: A Deeper Look 849

21.1 Introduction 850

21.2 string Assignment and Concatenation 851

21.3 Comparing strings 853

21.4 Substrings 856

21.5 Swapping strings 856

21.6 string Characteristics 857

21.7 Finding Substrings and Characters in a string 859

21.8 Replacing Characters in a string 861

21.9 Inserting Characters into a string 863

21.10 Conversion to Pointer-Based char * Strings 864

21.11 Iterators 865

21.12 String Stream Processing 867

21.13 C++11 Numeric Conversion Functions 870

21.14 Wrap-Up 871

22 Bits, Characters, C Strings and structs 879

22.1 Introduction 880

22.2 Structure Definitions 880

22.3 typedef 882

22.4 Example: Card Shuffling and Dealing Simulation 882

22.5 Bitwise Operators 885

22.6 Bit Fields 894

22.7 Character-Handling Library 897

22.8 C String-Manipulation Functions 903

22.9 C String-Conversion Functions 910

22.10 Search Functions of the C String-Handling Library 915

22.11 Memory Functions of the C String-Handling Library 919

22.12 Wrap-Up 923

23 Other Topics 938

23.1 Introduction 939

23.2 const_cast Operator 939

23.3 mutable Class Members 941

23.4 namespaces 943

23.5 Operator Keywords 946

23.6 Pointers to Class Members (.* and ->*) 948

23.7 Multiple Inheritance 950

23.8 Multiple Inheritance and virtual Base Classes 955

23.9 Wrap-Up 959

List of Chapters on the Web 965

A Operator Precedence and Associativity 967

B ASCII Character Set 969

C Fundamental Types 970

D Number Systems 972

D.1 Introduction 973

D.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers 976

D.3 Converting Octal and Hexadecimal Numbers to Binary Numbers 977

D.4 Converting from Binary, Octal or Hexadecimal to Decimal 977

D.5 Converting from Decimal to Binary, Octal or Hexadecimal 978

D.6 Negative Binary Numbers: Two’s Complement Notation 980

E Preprocessor 985

E.1 Introduction 986

E.2 #include Preprocessing Directive 986

E.3 #define Preprocessing Directive: Symbolic Constants 987

E.4 #define Preprocessing Directive: Macros 987

E.5 Conditional Compilation 989

E.6 #error and #pragma Preprocessing Directives 990

E.7 Operators # and ## 991

E.8 Predefined Symbolic Constants 991

E.9 Assertions 992

E.10Wrap-Up 992

List of Appendices on the Web 997

Index 999

Online Chapters and Appendices

Chapters 24—26 and Appendices F—K are PDF documents posted online at the book’s Companion Website, which is accessible from www.pearsonhighered.com/deitel

24 C++11 Additional Features 24-1

25 ATM Case Study, Part 1: Object-Oriented Design with the UML 25-1

25.1 Introduction 25-2

25.2 Introduction to Object-Oriented Analysis and Design 25-2

25.3 Examining the ATM Requirements Document 25-3

25.4 Identifying the Classes in the ATM Requirements Document 25-10

25.5 Identifying Class Attributes 25-17

25.6 Identifying Objects’ States and Activities 25-21

25.7 Identifying Class Operations 25-25

25.8 Indicating Collaboration Among Objects 25-32

25.9 Wrap-Up 25-39

26 ATM Case Study, Part 2: Implementing an Object-Oriented Design 26-1

26.1 Introduction 26-2

26.2 Starting to Program the Classes of the ATM System 26-2

26.3 Incorporating Inheritance into the ATM System 26-8

26.4 ATM Case Study Implementation 26-15

26.4.1 Class ATM 26-16

26.4.2 Class Screen 26-23

26.4.3 Class Keypad 26-25

26.4.4 Class CashDispenser 26-26

26.4.5 Class DepositSlot 26-28

26.4.6 Class Account 26-29

26.4.7 Class BankDatabase 26-31

26.4.8 Class Transaction 26-35

26.4.9 Class BalanceInquiry 26-37

26.4.10 Class Withdrawal 26-39

26.4.11 Class Deposit 26-44

26.4.12 Test Program ATMCaseStudy.cpp 26-47

26.5 Wrap-Up 26-47

F C Legacy Code Topics F-1

F.1 Introduction F-2

F.2 Redirecting Input/Output on UNIX/Linux/Mac OS X and Windows Systems F-2

F.3 Variable-Length Argument Lists F-3

F.4 Using Command-Line Arguments F-5

F.5 Notes on Compiling Multiple-Source-File Programs F-7

F.6 Program Termination with exit and atexit F-9

F.7 Type Qualifier volatile F-10

F.8 Suffixes for Integer and Floating-Point Constants F-10

F.9 Signal Handling F-11

F.10 Dynamic Memory Allocation with calloc and realloc F-13

F.11 Unconditional Branch: goto F-14

F.12 Unions F-15

F.13 Linkage Specifications F-18

F.14 Wrap-Up F-19

G UML 2: Additional Diagram Types G-1

G.1 Introduction G-1

G.2 Additional Diagram Types G-2

H Using the Visual Studio Debugger H-1

H.1 Introduction H-2

H.2 Breakpoints and the Continue Command H-2

H.3 Locals and Watch Windows H-8

H.4 Controlling Execution Using the Step Into, Step Over, Step Out and Continue Commands H-11

H.5 Autos Window H-13

H.6 Wrap-Up H-14

I Using the GNU C++ Debugger I-1

I.1 Introduction I-2

I.2 Breakpoints and the run, stop, continue and print Commands I-2

I.3 print and set Commands I-8

I.4 Controlling Execution Using the step, finish and next Commands I-10

I.5 watch Command I-13

I.6 Wrap-Up I-15

J Using the Xcode Debugger J-1

K Test Driving a C++ Program on Mac OS X K-1 [Note: The test drives for Windows and Linux are in Chapter 1.]

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020