C++ How to Program, Global Edition

Paul J. Deitel / Harvey Deitel  
Total pages
December 2016
Related Titles


For courses in C++ Programming

The best-selling C++ How to Program is accessible to readers with little or no programming experience, yet comprehensive enough for the professional programmer. The Deitels’ signature live-code approach presents the concepts in the context of full working programs followed by sample executions. The early objects approach gets readers thinking about objects immediately–allowing them to more thoroughly master the concepts. Emphasis is placed on achieving program clarity and building well-engineered software. Interesting, entertaining, and challenging exercises encourage students to make a difference and use computers and the Internet to work on problems. To keep readers up-to-date with leading-edge computing technologies, the Tenth Edition conforms to the C++11 standard and the new C++14 standard.


Focus on object-oriented programming

  • Early-objects approach. Accessible to even the most novice programmer, the book introduces the basic concepts and terminology of object technology in Chapter 1 and then asks readers to develop their first customised classes and objects in Chapter 3. Presenting objects and classes early gets readers thinking about objects immediately so they can master these concepts more thoroughly.
  • C++ Standard Library String. C++ offers two types of strings–string class objects (which are used beginning in Chapter 3) and C strings. Most occurrences of C strings are replaced with instances of C++ class string to make programs more robust and eliminate many of the security problems of C strings. C strings are discussed later in the book to prepare readers for working with the legacy code that they will encounter in industry.
  • C++ Standard Library array. C++ offers three types of arrays–arrays and vectors (which are used beginning in Chapter 7) and C-style, pointer-based arrays which are discussed in Chapter 8. The primary treatment of arrays uses the Standard Library’s array and vector class templates instead of built-in, C-style, pointerbased arrays. Built-in arrays are also covered because they remain useful in C++ and and will enable students to read legacy code.
  • Crafting valuable classes. To prepare readers to build valuable reusable classes, Chapter 10 begins with a test-drive of class template string–allowing students to see an elegant use of operator overloading before they implement their own customised class with overloaded operators. In the Chapter 10 case study, students will build their own custom Array class, then in the Chapter 18 exercises they will convert it to a class template.
  • Case studies in object-oriented programming. Several well-engineered, real-world case studies are presented, including the Account class in Chapter 3, Student class in Chapter 4, DollarAmount class in Chapter 5, GradeBook class in Chapter 7, the Time class in Chapter 9, the Employee class in Chapters 11—12, and more.
  • Optional case study: Using the UML to develop an object-oriented design and C++ implementation of an ATM. UMLTM (Unified Modeling LanguageTM) is introduced in the early chapters. Online Chapters 25 and 26 include an optional object-oriented design case study using the UML. To help them “tie it all together” and truly understand object orientation, students will learn to:
    • design and fully implement the software for a simple automated teller machine (ATM);
    • analyse a typical requirements document that specifies the system to be built;
    • determine the classes needed to implement that system, the attributes the classes need to have, the behaviors the classes need to exhibit and how objects of the classes must interact with one another to meet the system requirements;
    • produce a complete C++ implementation from the design.
  • Understanding how polymorphism works. Chapter 12 contains a detailed diagram and explanation of how C++ typically implements polymorphism, virtual functions and dynamic binding “under the hood.”
  • Object-oriented exception handling. Basic exception handling is integrated early in the book in Chapter 7. Instructors can easily pull more detailed material from Chapter 17, Exception Handling: A Deeper Look.
  • Custom template-based data structures. A rich multi-chapter treatment of data structures is provided–see the Data Structures module in the chapter dependency chart to plan your instruction.
  • Three programming paradigms. Structured programming, object-oriented programming, and

New to this Edition

Keep your course current on the C++11 and C++14 standards.

  • Discussions of the new C++14 capabilities.
  • UPDATED: Integrating C++11 capabilities further into the code examples, because the latest compilers are now supporting these features.
  • UPDATED: Uniforming initialization with list initializer syntax.
  • UPDATED: Always using braces in control statements, even for single-statement bodies.
  • UPDATED: Replacing the Gradebook class with Account, Student and DollarAmount class case studies in Chapters 3, 4 and 5, respectively. DollarAmount processes monetary amounts precisely for business applications.
  • UPDATED: C++14 digit separators in large numeric literals.
  • UPDATED: Updating Type &x to Type& x and Type *x to Type* x in accordance with industry idiom.
  • UPDATED: Using C++11 scoped enums rather than traditional C enums.
  • UPDATED: Bringing terminology in line with the C++ standard.
  • UPDATED: Bolding key terms in summaries for easy reference.
  • UPDATED: Removing extra spaces inside [], (), <> and {} delimiters.
  • UPDATED: Replacing most print member functions with toString member functions to make classes more flexible–for example, returning a string gives the client code the option of displaying it on the screen, writing it to a file, concatenating it with other strings, etc.
  • UPDATED: Using ostringstream to create formatted strings for items like the string representations of a Time, rather than outputting formatted data directly to the standard output.
  • UPDATED: For simplicity, using the three-file architecture is deferred from Chapter 3 to Chapter 9, so all early class examples define the entire class in a header.
  • UPDATED: Reimplementation of Chapter 10’s Array class operator-overloading example with unique_ptrs in Chapter 24. Using raw pointers and dynamic-memory allocation with new and delete is a source of subtle programming errors, especially “memory leaks”–unique_ptr and the other smart pointer types help prevent such errors.
  • Using lambdas rather than function pointers in Chapter 16, Standard Library Algorithms. This will get readers comfortable with lambdas, which can be combined with various Standard Library algorithms to perform functional programming in C++.
  • UPDATED: Enhancing the treatment of Standard Library containers, iterators, and algorithms in Chapters 15 and 16 with additional C++11 and C++14 features.
  • UPDATED: Updating the Online Chapter 24, C++11 and C++14 Additional Topics, with discussions of regular expressions, shared_ptr and weak_ptr smart pointers, move semantics, multithreading, tuples, decltype, constexpr and more.

MyProgrammingLabTM is not included. Students, if MyProgrammingLab is a recommended/mandatory component of the course, please ask your instructor for the correct ISBN and course ID. MyProgrammingLab should only be purchased when required by an instructor. Instructors, contact your Pearson representative for more information.

MyProgrammingLab is an online learning system designed to engage students and improve results. MyProgrammingLab consists of a set of programming exercises correlated to the programming concepts in this book. Through hundreds of practice problems, the system automatically detects errors in the logic and syntax of their code submissions and offers targeted hints that enable students to figure out what went wrong–and why.

Exercise Editor now allows you to easily create new programming exercises. In addition to assigning the hundreds of programming exercise

Table of Contents

  • 1 Introduction to Computers and C++ 1
  • 2 Introduction to C++ Programming, Input/Output and Operators
  • 3 Introduction to Classes, Objects, Member Functions and Strings
  • 4 Algorithm Development and Control Statements: Part 1
  • 5 Control Statements: Part 2; Logical Operators
  • 6 Functions and an Introduction to Recursion
  • 7 Class Templates array and vector; Catching Exceptions
  • 8 Pointers
  • 9 Classes: A Deeper Look
  • 10 Operator Overloading; Class string
  • 11 Object-Oriented Programming: Inheritance
  • 12 Object-Oriented Programming: Polymorphism
  • 13 Stream Input/Output: A Deeper Look
  • 14 File Processing
  • 15 Standard Library Containers and Iterators
  • 16 Algorithms
  • 17 Exception Handling: A Deeper Look
  • 18 Introduction to Custom Templates
  • 19 Custom Templatized Data Structures
  • 20 Searching and Sorting
  • 21 Class string and String Stream Processing: A Deeper Look
  • 22 Bits, Characters, C Strings and structs
  • Chapters on the Web
  • A Operator Precedence and Associativity
  • B ASCII Character Set
  • C Fundamental Types
  • D Number Systems
  • D.1 Introduction
  • D.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
  • D.3 Converting Octal and Hexadecimal Numbers to Binary Numbers
  • D.4 Converting from Binary, Octal or Hexadecimal to Decimal
  • D.5 Converting from Decimal to Binary, Octal or Hexadecimal
  • D.6 Negative Binary Numbers: Two’s Complement Notation
  • E Preprocessor
  • E.1 Introduction
  • E.2 #include Preprocessing Directive
  • E.3 #define Preprocessing Directive: Symbolic Constants
  • E.4 #define Preprocessing Directive: Macros
  • E.5 Conditional Compilation
  • E.6 #error and #pragma Preprocessing Directives
  • E.7 Operators # and ##
  • E.8 Predefined Symbolic Constants
  • E.9 Assertions
  • E.10 Wrap-Up
  • Appendices on the Web
  • Index