Developers: Learn a New Programming Language or App Development with Deitel LiveLessons Videos!
Login  |  Register  |  Media Kit  |  Press  |  Contact Us  |   Twitter Become a Deitel Fan on Facebook  
Custom Search
C++ How to Program, 7/e Cover

ISBN: 0136117260
© 2010, pp. 1100

Order now at

Download Code
Examples and
Other Premium
Content for
Registered Users

Login or Register to download this book's code examples and other premium content.


C++ How to Program, 7/e

Harvey M. Deitel and Paul J. Deitel, both from Deitel & Associates, Inc.
© 2010, 1100 pp., paper (0-13-611726-0)


  • “Making a Difference” Exercise Sets. We encourage you to use computers and the Internet to research and solve problems that really matter. These new exercises are meant to increase awareness of important issues the world is facing. We hope you’ll approach them with your own values, politics and beliefs.
  • Prefer string Objects to C Strings. C++ offers two types of strings—string class objects (which we use starting in Chapter 3) and C-style, pointer-based strings. We continue to include some early discussions of C strings to give you practice with pointer manipulations, to illustrate dynamic memory allocation with new and delete and to prepare you for working with C strings in the “legacy code” that you’ll encounter in industry. In new development, you should favor string class objects. 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 that can be caused by manipulating C strings.
  • Prefer vectors to C Arrays. Similarly, C++ offers two types of arrays—vector class objects (which we use starting in Chapter 7) and C-style, pointer-based arrays. As appropriate, we use class template vector instead of C arrays throughout the book. However, we begin by discussing C arrays in Chapter 7 to prepare you for working with legacy code and to use as a basis for building your own customized Array class in Chapter 11, Operator Overloading.
  • New Companion Website ( This edition’s Companion Website includes a wealth of material to help you with your study of C++ programming. We provide an extensive number of VideoNotes that walk you through the code examples in 14 of the key chapters, solutions to many of the book’s exercises, bonus chapters, and more (see the Companion Website section later in this Preface).
  • Dynamic Memory Allocation. We moved dynamic memory allocation later in the book to Chapter 11, where it’s first needed. The “proxy class” discussion (which uses dynamic memory) has also been moved to Chapter 11.
  • Titled Programming Exercises. We’ve titled all the programming exercises. This and the previous two features help instructors tune assignments for their classes.
  • Eliminated “Magic” Numbers. We eliminated all uses of truly “magic” numbers and replaced them with named constants or enums as appropriate. In a few cases in which the context is absolutely clear, we don’t consider numbers to be “magic.”
  • Enhanced Use of const. We increased our use of const bookwide to encourage better software engineering.
  • Eliminated “return 0;”. According to the C++ standard, any main function that does not contain “return 0;” as its last statement is assumed to return 0. For this reason, we’ve eliminated “return 0;” from all but the first program in the book.
  • Use “using namespace std;”. Previously, we specified a using declaration for every individual item that we referenced from a C++ Standard Library header file. Since these items are well known and unlikely to have name collisions with other C++ libraries, we now use “using namespace std;” for all C++ Standard Library components from Chapter 3 forward. This simplifies the programs and saves many lines of code.
  • New Design. The book has a new interior design that graphically serves to organize, clarify and highlight the information, and enhances the book’s pedagogy.
  • Reorganized Optional OOD Case Study. We tuned the Object-Oriented Design/UML automated teller machine (ATM) case study and reorganized it into two optional chapters (25 and 26) that present the ATM’s design and complete code implementation. This is a nice business example that most students can relate to. Working through these two chapters as a unit will help you tie together many of the object-oriented programming (OOP) concepts you learn in Chapters 1–13. A key concept in OOP is the interactions among objects. In most textbooks, the code examples create and use only one or two objects. The ATM case study gives you the opportunity to examine the interactions among many objects that provide the functionality of a substantial system. For instructors who wish to cover the case study in a distributed manner, we’ve indicated where each section in Chapters 25 and 26 can be covered inline with earlier chapters in the book.
  • Function Pointer Exercises. We added several real-world function-pointers exercises. These are available at the Companion Website and at
  • Improved Terminology Sections. We’ve added page numbers for the defining occurrences of all terms in the terminology lists for easy reference.

New Features in the Next C++ Standard

  • We discuss four new language features that will be part of the next C++ standard and are already implemented by some of today’s C++ compilers. These include:
  • Initializer Lists for User-Defined Types. These enable objects of your own types to be initialized using the same syntax as built-in arrays.
  • Range-Based for Statement. A version of the for statement that iterates over all
    the elements of an array or container (such as an object of the vector class).
  • Lambda Expressions. These enable you to create anonymous functions that can
    be passed to other functions as arguments.
  • Concepts. These enable template programmers to specify the requirements for
    data types that will be used with a particular template. Compilers can then pro-
    vide more meaningful error messages when data types do not meet a template’s

Other Features

  • Other features of C++ How to Program, 7/e, include:
  • Game Programming. The computer-game industry’s revenues are already greater
    than those of the first-run movie business, creating lots of career opportunities.
    Chapter 27, Game Programming with Ogre, introduces game programming and
    graphics with the open source Ogre 3D graphics engine. We discuss basic issues
    involved in game programming. Then we show how to use Ogre to create a sim-
    ple game featuring a play mechanic similar to the classic video game Pong®, orig-
    inally developed by Atari. We demonstrate how to create a scene with 3D color
    graphics, smoothly animate moving objects, use timers to control animation
    speed, detect collisions between objects, add sound, accept keyboard input and
    display text output.
  • Future of C++. Chapter 23 considers the future of C++—we introduce the Boost
    C++ Libraries, Technical Report 1 (TR1) and C++0x. The free Boost open source
    libraries are created by members of the C++ community. Technical Report 1 de-
    scribes the proposed changes to the C++ Standard Library, many of which are
    based on current Boost libraries. The C++ Standards Committee is revising the
    C++ Standard. The main goals for the new standard are to make C++ easier to
    learn, improve library building capabilities, and increase compatibility with the
    C programming language. The last standard was published in 1998. The new
    standard is likely to be released in 2010 or 2011. It will include changes to the
    core language and many of the libraries in TR1. We overview the Boost libraries
    and provide code examples for the “regular expression” and “smart pointer” li-
    braries. Regular expressions are used to match specific character patterns in text.
    They can be used, for example, to validate data to ensure that it’s in a particular
    format, to replace parts of one string with another, or to split a string. Many com-
    mon bugs in C and C++ code are related to pointers, a powerful programming
    capability you’ll study in Chapter 8, Pointers. Smart pointers help you avoid er-
    rors by providing additional functionality to standard pointers.
  • Integrated Case Studies. We provide several case studies spanning multiple sections
    and chapters. These include the development of the GradeBook class in Chapters 3–
    7, the Time class in Chapters 9–10, the Employee class in Chapters 12–13, and the
    optional OOD/UML ATM case study in Chapters 25–26.
  • Integrated GradeBook Case Study. The GradeBook case study uses classes and ob-
    jects in Chapters 3–7 to incrementally build a GradeBook class that represents an
    instructor’s grade book and performs various calculations based on a set of student grades, such as calculating the average grade, finding the maximum and
    minimum, and printing a bar chart.
  • Unified Modeling Language™ 2 (UML 2). The Unified Modeling Language
    (UML) has become the preferred graphical modeling language for designers of
    object-oriented systems. We use UML class diagrams to visually represent classes
    and their inheritance relationships, and we use UML activity diagrams to dem-
    onstrate the flow of control in each of C++’s control statements. We use six types
    of UML diagrams in the optional OOD/UML ATM case study
  • Compilation and Linking Process for Multiple-Source-File Programs. Chapter 3
    includes a detailed diagram and discussion of the compilation and linking process
    that produces an executable program.
  • Function Call Stack Explanation. In Chapter 6, we provide a detailed discussion
    (with illustrations) of the function call stack and activation records to explain
    how C++ is able to keep track of which function is currently executing, how au-
    tomatic variables of functions are maintained in memory and how a function
    knows where to return after it completes execution.
  • Tuned Treatment of Inheritance and Polymorphism. Chapters 12–13 have been
    carefully tuned using an Employee class hierarchy to make the treatment of inher-
    itance and polymorphism clear and accessible for students who are new to OOP.
  • Discussion and Illustration of How Polymorphism Works “Under the Hood.”
    Chapter 13 contains a detailed diagram and explanation of how C++ can imple-
    ment polymorphism, virtual functions and dynamic binding internally. This
    gives students a solid understanding of how these capabilities really work.
  • Standard Template Library (STL). This might be one of the most important top-
    ics in the book in terms of your appreciation of software reuse. The STL defines
    powerful, template-based, reusable components that implement many common
    data structures and algorithms used to process those data structures. Chapter 22
    introduces the STL and discusses its three key components—containers, iterators
    and algorithms. We show that using STL components provides tremendous ex-
    pressive power, often reducing many lines of code to a single statement.
  • ISO/IEC C++ Standard Compliance. We’ve audited our presentation against the
    most recent ISO/IEC C++ standard document.
  • Debugger Appendices. We provide two Using the Debugger appendices on the
    book’s Companion Website—Appendix H, Using the Visual Studio Debugger,
    and Appendix I, Using the GNU C++ Debugger.
  • Code Testing on Multiple Platforms. We tested the code examples on various
    popular C++ platforms including GNU C++ on Linux and Microsoft and Visual
    C++ on Windows. For the most part, the book’s examples port to popular stan-
    dard-compliant compilers.


“Finally, an accurate and complete C++ book that everybody can understand. It will help you achieve a solid knowledge of C++ and of software engineering in general. A ‘must-have.’”
— José Antonio González Seco, Parliament of Andalusia, Spain

“As an instructor, I appreciate the thorough discussion of the C++ language, especially the comprehensive use of code examples and demonstration of best coding practices. For my consulting work I use the Deitel books as my primary reference.”—Dean Mathias, Utah St. U.

“ Chapter 12, Object-Oriented Programming: Inheritance, is so well done. It’s evident that the authors are diligent and focused on quality!”—David Topham, Ohlone College

“Each code example is completely reviewed. This is a critical step for students to learn good programming practices.”—Jack R. Hagemeister, Washington State University

“ The Deitel & Deitel How to Program Series provides a complete basis of fundamental instruction in all core aspects of C++. Comprehensive discussion and examples provide a solid grounding in the construction of C++ programs.”—Peter DePasquale, The College of New Jersey

“The virtual function figure and corresponding text explanation in Chapter 13, Polymorphism, is thorough and truly commendable .”—Gregory Dai, Kernel Development

“Very good, thorough and detailed coverage of exceptions from an object-oriented point of view.”—Dean Mathias, Utah State University

“Code examples are well presented and easy to read...Very impressive that so many resources identified…and mostly free, too!... Excellent introduction to Polymorphism. Clear and accurate.”
—David Topham, Ohlone College

“Aimed at someone new to C++, this is a good introduction to the C++ Standard Template Library (STL) with clear descriptions, examples and plenty of useful tips. The example code is excellent: clean, well documented, with extensive descriptions of what the code is doing and why.”
— Chris Cox, Adobe Systems

“Chapter 20 (Data Structures) is very good. The examples are accessible to CS, IT, software engineering and business students.”—Thomas J. Borrelli, Rochester Institute of Technology

“Chapter 15 provides a solid overview of the major features of the C++ Stream I/O fundamentals The examples are right on point.”—Peter DePasquale, The College of New Jersey

“The Pointers chapter clearly explains a complex subject. The Simpletron exercises are simply brilliant. The Polymorphism chapter explains one of the hardest topics to understand in OOP in a clear manner. Great job! The writing is excellent, the examples are well developed and the exercises are interesting.”— José Antonio González Seco, Parliament of Andalusia, Spain

Comments from the Sixth Edition Reviewers
“An excellent ‘objects first’ coverage of C++ that remains accessible to beginners. The example-driven presentation is enriched by the optional UML case study that contextualizes the material in an ongoing software engineering project.”
—Gavin Osborne, Saskatchewan Institute of Applied Science and Technology

“Introducing the UML early on is a great idea.”—Raymond Stephenson, Microsoft

“Good use of diagrams, especially of the activation call stack and recursive functions.”
—Amar Raheja, California State Polytechnic University, Pomona

“Terrific discussion of pointers—the best I have seen.”—Anne B. Horton, Lockheed Martin

“Great coverage of polymorphism and how the compiler implements polymorphism ‘under the hood.’ I wish I had such a clear presentation of data structures when I was a student.”
—Ed James-Beckham, Borland

“A nice introduction to searching and sorting, and Big-O.”—Robert Myers, Florida State Univ.

“Ogre is a free world-class rendering engine that has been used in several commercial games. The Ogre chapter is a great introduction, providing well documented and easy to understand examples that will have you creating your own simple computer games in no time.”
—Casey Borders (Creator of OgreAL), Sensis Corp.

“Getting a new user to the stage of creating a functional and playable Ogre-based computer game in 40 pages is a great achievement.”—Steve Streeting (Creator of Ogre), Torus Knot Software

“The Boost/C++0x chapter will get you up and running quickly with the memory management and regular expression libraries, plus whet your appetite for new C++ features being standardized.”
—Ed Brey, Kohler Co.

“Excellent introduction to the Standard Template Library (STL). The best book on C++ programming for the serious student!”—Richard Albright, Goldey-Beacom College

“Just when you think you are focused on learning one topic, suddenly you discover you’ve learned more than you expected.”—Chad Willwerth, University of Washington, Tacoma

“The most thorough C++ treatment I’ve seen. Replete with real-world case studies covering the full software development lifecycle. Code examples are extraordinary!
—Terrell Hull, Logicalis Integration Solutions

Safari Trial Subscriptuon

Update :: January 17, 2020