C++ Primer Plus [NOOK Book]

Overview

This is the eBook version of the printed book. If the print book includes a CD-ROM, this content is not included within the eBook version.

If you are new to C++ programming, C++ Primer Plus, Fifth Edition is a friendly and easy-to-use self-study guide. You will cover the latest and most useful language enhancements, the Standard Template Library and ways to streamline object-oriented programming with C++. This guide also illustrates how to handle input and output, make programs ...

See more details below
C++ Primer Plus

Available on NOOK devices and apps  
  • NOOK Devices
  • NOOK HD/HD+ Tablet
  • NOOK
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK Study

Want a NOOK? Explore Now

NOOK Book (eBook)
$27.49
BN.com price
(Save 42%)$47.99 List Price

Overview

This is the eBook version of the printed book. If the print book includes a CD-ROM, this content is not included within the eBook version.

If you are new to C++ programming, C++ Primer Plus, Fifth Edition is a friendly and easy-to-use self-study guide. You will cover the latest and most useful language enhancements, the Standard Template Library and ways to streamline object-oriented programming with C++. This guide also illustrates how to handle input and output, make programs perform repetitive tasks, manipulate data, hide information, use functions and build flexible, easily modifiable programs. With the help of this book, you will:

  • Learn C++ programming from the ground up.
  • Learn through real-world, hands-on examples.
  • Experiment with concepts, including classes, inheritance, templates and exceptions.
  • Reinforce knowledge gained through end-of-chapter review questions and practice programming exercises.

C++ Primer Plus, Fifth Edition makes learning and using important object-oriented programming concepts understandable. Choose this classic to learn the fundamentals and more of C++ programming.

Read More Show Less

Editorial Reviews

Booknews
A book/CD-ROM tutorial presenting C++ from the ground up, for students with some programming experience. Material is covered with step-by- step lessons, examples, code, and figures, supplemented by summaries, review questions, exercises, and explained answers. This edition covers the Standard Template Library and contains a new chapter on string classes. The CD-ROM contains source code for all examples and limited editions of Metrowerks CodeWarrior Lite compilers. Annotation c. by Book News, Inc., Portland, Or.
Read More Show Less

Product Details

  • ISBN-13: 9780131388208
  • Publisher: Pearson Education
  • Publication date: 11/29/2004
  • Sold by: Barnes & Noble
  • Format: eBook
  • Edition number: 5
  • Pages: 1224
  • File size: 41 MB
  • Note: This product may take a few minutes to download.

Meet the Author

Stephen Prata teaches astronomy, physics, and computer science at the College of Marin in Kentfield, California. He received his B.S. from the California Institute of Technology and his Ph.D. from the University of California, Berkeley. Stephen has authored or coauthored more than a dozen books for The Waite Group. He wrote The Waite Group's New C Primer Plus, which received the Computer Press Association's 1990 Best How-to Computer Book Award, and The Waite Group's C++ Primer Plus, nominated for the Computer Press Association's Best How-to Computer Book Award in 1991.

Read More Show Less

Read an Excerpt

Introduction: C++ Primer PlusIntroductionPreface to the Fifth Edition

Learning C++ is an adventure of discovery, particularly because the language accommodates several programming paradigms, including object-oriented programming, generic programming, and the traditional procedural programming. C++ was a moving target as the language added new features, but now, with the ISO/ANSI C++ Standard, Second Edition (2003), in place, the language has stabilized. Contemporary compilers support most or all of the features mandated by the standard, and programmers have had time to get used to applying these features. The fifth edition of this book, C++ Primer Plus, reflects the ISO/ANSI standard and describes this matured version of C++.

C++ Primer Plus discusses the basic C language and presents C++ features, making this book self-contained. It presents C++ fundamentals and illustrates them with short, to-the-point programs that are easy to copy and experiment with. You'll learn about input/output (I/O), how to make programs perform repetitive tasks and make choices, the many ways to handle data, and how to use functions. You'll learn about the many features C++ has added to C, including the following:

  • Classes and objects
  • Inheritance
  • Polymorphism, virtual functions, and runtime type identification (RTTI)
  • Function overloading
  • Reference variables
  • Generic, or type-independent, programming, as provided by templates and the Standard Template Library (STL)
  • The exception mechanism for handling error conditions
  • Namespaces for managing names of functions, classes, and variables
The Primer Approach

C++ Primer Plus brings several virtues to the task of presenting all this material. It builds on the primer tradition begun by C Primer Plus nearly two decades ago and embraces its successful philosophy:

  • A primer should be an easy-to-use, friendly guide.
  • A primer doesn't assume that you are already familiar with all relevant programming concepts.
  • A primer emphasizes hands-on learning with brief, easily typed examples that develop your understanding, a concept or two at a time.
  • A primer clarifies concepts with illustrations.
  • A primer provides questions and exercises to let you test your understanding, making the book suitable for self-learning or for the classroom.

Following these principles, the book helps you understand this rich language and how to use it. For example:

  • It provides conceptual guidance about when to use particular features, such as using public inheritance to model what are known as is-a relationships.
  • It illustrates common C++ programming idioms and techniques.
  • It provides a variety of sidebars, including tips, cautions, things to remember, compatibility notes, and real-world notes.

The author and editors of this book do our best to keep the presentation to-the-point, simple, and fun. Our goal is that by the end of the book, you'll be able to write solid, effective programs and enjoy yourself doing so.

Sample Code Used in This Book

This book provides an abundance of sample code, most of it in the form of complete programs. Like the previous editions, this book practices generic C++ so that it is not tied to any particular kind of computer, operating system, or compiler. Thus, the examples were tested on a Windows XP system, a Macintosh OS X system, and a Linux system. Only a few programs were affected by compiler non-conformance issues. Compiler compliance with the C++ standard has improved since the previous edition of this book first appeared.

The sample code for the complete programs described in this book is available on the Sams website, at http://www.samspublishing.com. Enter this book's ISBN (without the hyphens) in the Search box and click Search. When the book's title is displayed, click the title to go to a page where you can download the code. You also can find solutions to selected programming exercises at this site.

How This Book Is Organized

This book is divided into 17 chapters and 10 appendixes, summarized here.

Chapter 1: Getting Started

Chapter 1 relates how Bjarne Stroustrup created the C++ programming language by adding object-oriented programming support to the C language. You'll learn the distinctions between procedural languages, such as C, and object-oriented languages, such as C++. You'll read about the joint ANSI/ISO work to develop a C++ standard. This chapter discusses the mechanics of creating a C++ program, outlining the approach for several current C++ compilers. Finally, it describes the conventions used in this book.

Chapter 2: Setting Out to C++

Chapter 2 guides you through the process of creating simple C++ programs. You'll learn about the role of the main() function and about some of the kinds of statements that C++ programs use. You'll use the predefined cout and cin objects for program output and input, and you'll learn about creating and using variables. Finally, you'll be introduced to functions, C++'s programming modules.

Chapter 3: Dealing with Data

C++ provides built-in types for storing two kinds of data: integers (numbers with no fractional parts) and floating-point numbers (numbers with fractional parts). To meet the diverse requirements of programmers, C++ offers several types in each category. Chapter 3 discusses those types, including creating variables and writing constants of various types. You'll also learn how C++ handles implicit and explicit conversions from one type to another.

Chapter 4: Compound Types

C++ lets you construct more elaborate types from the basic built-in types. The most advanced form is the class, discussed in Chapters 9 through 13. Chapter 4 discusses other forms, including arrays, which hold several values of a single type; structures, which hold several values of unlike types; and pointers, which identify locations in memory. You'll also learn how to create and store text strings and to handle text I/O by using C-style character arrays and the C++ string class. Finally, you'll learn some of the ways C++ handles memory allocation, including using the new and delete operators for managing memory explicitly.

Chapter 5: Loops and Relational Expressions

Programs often must perform repetitive actions, and C++ provides three looping structures for that purpose: the for loop, the while loop, and the do while loop. Such loops must know when they should terminate, and the C++ relational operators enable you to create tests to guide such loops. In Chapter 5 you learn how to create loops that read and process input character-by-character. Finally, you'll learn how to create two-dimensional arrays and how to use nested loops to process them.

Chapter 6: Branching Statements and Logical Operators

Programs can behave intelligently if they can tailor their behavior to circumstances. In Chapter 6 you'll learn how to control program flow by using the if, if else, and switch statements and the conditional operator. You'll learn how to use logical operators to help express decision-making tests. Also, you'll meet the cctype library of functions for evaluating character relations, such as testing whether a character is a digit or a nonprinting character. Finally, you'll get an introductory view of file I/O.

Chapter 7: Functions: C++'s Programming Modules

Functions are the basic building blocks of C++ programming. Chapter 7 concentrates on features that C++ functions share with C functions. In particular, you'll review the general format of a function definition and examine how function prototypes increase the reliability of programs. Also, you'll investigate how to write functions to process arrays, character strings, and structures. Next, you'll learn about recursion, which is when a function calls itself, and see how it can be used to implement a divide-and-conquer strategy. Finally, you'll meet pointers to functions, which enable you to use a function argument to tell one function to use a second function.

Chapter 8: Adventures in Functions

Chapter 8 explores the new features C++ adds to functions. You'll learn about inline functions, which can speed program execution at the cost of additional program size. You'll work with reference variables, which provide an alternative way to pass information to functions. Default arguments let a function automatically supply values for function arguments that you omit from a function call. Function overloading lets you create functions having the same name but taking different argument lists. All these features have frequent use in class design. Also, you'll learn about function templates, which allow you to specify the design of a family of related functions.

Chapter 9: Memory Models and Namespaces

Chapter 9 discusses putting together multifile programs. It examines the choices in allocating memory, looking at different methods of managing memory and at scope, linkage, and namespaces, which determine what parts of a program know about a variable.

Chapter 10: Objects and Classes

A class is a user-defined type, and an object (such as a variable) is an instance of a class. Chapter 10 introduces you to object-oriented programming and to class design. A class declaration describes the information stored in a class object and also the operations (class methods) allowed for class objects. Some parts of an object are visible to the outside world (the public portion), and some are hidden (the private portion). Special class methods (constructors and destructors) come into play when objects are created and destroyed. You will learn about all this and other class details in this chapter, and you'll see how classes can be used to implement ADTs, such as a stack.

Chapter 11: Working with Classes

In Chapter 11 you'll further your understanding of classes. First, you'll learn about operator overloading, which lets you define how operators such as + will work with class objects. You'll learn about friend functions, which can access class data that's inaccessible to the world at large. You'll see how certain constructors and overloaded operator member functions can be used to manage conversion to and from class types.

Chapter 12: Classes and Dynamic Memory Allocation

Often it's useful to have a class member point to dynamically allocated memory. If you use new in a class constructor to allocate dynamic memory, you incur the responsibilities of providing an appropriate destructor, of defining an explicit copy constructor, and of defining an explicit assignment operator. Chapter 12 shows you how and discusses the behavior of the member functions generated implicitly if you fail to provide explicit definitions. You'll also expand your experience with classes by using pointers to objects and studying a queue simulation problem.

Chapter 13: Class Inheritance

One of the most powerful features of object-oriented programming is inheritance, by which a derived class inherits the features of a base class, enabling you to reuse the base class code. Chapter 13 discusses public inheritance, which models is-a relationships, meaning that a derived object is a special case of a base object. For example, a physicist is a special case of a scientist. Some inheritance relationships are polymorphic, meaning you can write code using a mixture of related classes for which the same method name may invoke behavior that depends on the object type. Implementing this kind of behavior necessitates using a new kind of member function called a virtual function. Sometimes using abstract base classes is the best approach to inheritance relationships. This chapter discusses these matters, pointing out when public inheritance is appropriate and when it is not.

Chapter 14: Reusing Code in C++

Public inheritance is just one way to reuse code. Chapter 14 looks at several other ways. Containment is when one class contains members that are objects of another class. It can be used to model has-a relationships, in which one class has components of another class. For example, an automobile has a motor. You also can use private and protected inheritance to model such relationships. This chapter shows you how and points out the differences among the different approaches. Also, you'll learn about class templates, which let you define a class in terms of some unspecified generic type, and then use the template to create specific classes in terms of specific types. For example, a stack template enables you to create a stack of integers or a stack of strings. Finally, you'll learn about multiple public inheritance, whereby a class can derive from more than one class.

Chapter 15: Friends, Exceptions, and More

Chapter 15 extends the discussion of friends to include friend classes and friend member functions. Then it presents several new developments in C++, beginning with exceptions, which provide a mechanism for dealing with unusual program occurrences, such an inappropriate function argument values and running out of memory. Then you'll learn about RTTI, a mechanism for identifying object types. Finally, you'll learn about the safer alternatives to unrestricted typecasting.

Chapter 16: The string Class and the Standard Template Library

Chapter 16 discusses some useful class libraries recently added to the language. The string class is a convenient and powerful alternative to traditional C-style strings. The auto_ptr class helps manage dynamically allocated memory. The STL provides several generic containers, including template representations of arrays, queues, lists, sets, and maps. It also provides an efficient library of generic algorithms that can be used with STL containers and also with ordinary arrays. The valarray template class provides support for numeric arrays.

Chapter 17: Input, Output, and Files

Chapter 17 reviews C++ I/O and discusses how to format output. You'll learn how to use class methods to determine the state of an input or output stream and to see, for example, whether there has been a type mismatch on input or whether the end-of-file has been detected. C++ uses inheritance to derive classes for managing file input and output. You'll learn how to open files for input and output, how to append data to a file, how to use binary files, and how to get random access to a file. Finally, youlearn how to apply standard I/O methods to read from and write to strings.

Appendix A: Number Bases

Appendix A discusses octal, hexadecimal, and binary numbers.

Appendix B: C++ Reserved Words

Appendix B lists C++ keywords.

Appendix C: The ASCII Character Set

Appendix C lists the ASCII character set, along with decimal, octal, hexadecimal, and binary representations.

Appendix D: Operator Precedence

Appendix D lists the C++ operators in order of decreasing precedence.

Appendix E: Other Operators

Appendix E summarizes the C++ operators, such as the bitwise operators, not covered in the main body of the text.

Appendix F: The string Template Class

Appendix F summarizes string class methods and functions.

Appendix G: The STL Methods and Functions

Appendix G summarizes the STL container methods and the general STL algorithm functions.

Appendix H: Selected Readings and Internet Resources

Appendix H lists some books that can further your understanding of C++.

Appendix I: Converting to ANSI/ISO Standard C++

Appendix I provides guidelines for moving from C and older C++ implementations to ANSI/ISO C++.

Appendix J: Answers to Review Questions

Appendix J contains the answers to the review questions posed at the end of each chapter.

Note to Instructors

One of the goals of this edition of C++ Primer Plus is to provide a book that can be used as either a teach-yourself book or as a textbook. Here are some of the features that support using C++ Primer Plus, Fifth Edition, as a textbook:

  • This book describes generic C++, so it isn't dependent on a particular implementation.
  • The contents track the ISO/ANSI C++ standards committee's work and include discussions of templates, the STL, the string class, exceptions, RTTI, and namespaces.
  • It doesn't assume prior knowledge of C, so it can be used without a C prerequisite. (Some programming background is desirable, however.)
  • Topics are arranged so that the early chapters can be covered rapidly as review chapters for courses that do have a C prerequisite.
  • Chapters include review questions and programming exercises. Appendix J provides the answers to the review questions. Solutions to selected programming exercises can be found at the Sams website (http://www.samspublishing.com).
  • The book introduces several topics that are appropriate for computer science courses, including abstract data types (ADTs), stacks, queues, simple lists, simulations, generic programming, and using recursion to implement a divide-and-conquer strategy.
  • Most chapters are short enough to cover in a week or less.
  • The book discusses when to use certain features as well as how to use them. For example, it links public inheritance to is-a relationships and composition and private inheritance to has-a relationships, and it discusses when to use virtual functions and when not to.
Conventions Used in This Book

This book uses several typographic conventions to distinguish among various kinds of text:

  • Code lines, commands, statements, variables, filenames, and program output appear in a computer typeface: #include int main(){ using namespace std; cout << "What's up, Doc!\ n"; return 0;}
  • Program input that you should type appears in bold computer typeface: Please enter your name:Plato
  • Placeholders in syntax descriptions appear in an italic computer typeface. You should replace a placeholder with the actual filename, parameter, or whatever element it represents.
  • Italic type is used for new terms.

This book includes several elements intended to illuminate specific points:

Compatibility Note - Most compilers are not yet 100% compliant with the ISO/ANSI Standard, and these notes warn you of discrepancies you may encounter.

Remember - These notes highlight points that are important to remember.

Real-World Note - Several professional programmers offer observations based on their experiences.

Sidebar - A sidebar provides a deeper discussion or additional background to help illuminate a topic.

Tip - Tips present short, helpful guides to particular programming situations.

Caution - A caution alerts you to potential pitfalls.

Note - The notes provide a catch-all category for comments that don't fall into one of the other categories.

Systems Used to Develop This Book's Programming Examples

For the record, the examples in this book were developed using Microsoft Visual C++ 7.1 (the version that comes with Microsoft Visual Studio .NET 2003) and Metrowerks CodeWarrior Development Studio 9 on a Pentium PC with a hard disk and running under Windows XP Professional. Most programs were checked using the Borland C++ 5.5 command-line compiler and GNU gpp 3.3.3 on the same system, using Comeau 4.3.3 and GNU g++ 3.3.1 on an IBM-compatible Pentium running SuSE 9.0 Linux, and using Metrowerks Development Studio 9 on a Macintosh G4 under OS 10.3. This book reports discrepancies stemming from lagging behind the standard generically, as in "older implementations use ios::fixed instead of ios_base::fixed." This book reports some bugs and idiosyncrasies in older compilers that would prove troublesome or confusing; most of these have been fixed in current releases.

C++ offers a lot to the programmer; learn and enjoy!

© Copyright Pearson Education. All rights reserved.

Read More Show Less

Table of Contents

Introduction.

1. Getting Started.

Learning C++: What Lies Before You.

The Origins of C++: A Little History.

The C Language.

C Programming Philosophy.

The C++ Shift: Object-Oriented Programming.

C++ and Generic Programming.

The Genesis of C++.

Portability and Standards.

The Mechanics of Creating a Program.

Creating the Source Code File.

Compilation and Linking.

Summary.

2. Setting Out to C++.

C++ Initiation.

The main() Function.

C++ Comments.

The C++ Preprocessor and the iostream File.

Header Filenames.

Namespaces.

C++ Output with cout.

C++ Source Code Formatting.

C++ Statements.

Declaration Statements and Variables.

Assignment Statements.

A New Trick for cout.

More C++ Statements.

Using cin.

Concatenating with cout.

cin and cout: A Touch of Class.

Functions.

Using a Function That Has a Return Value.

Function Variations.

User-Defined Functions.

Using a User-Defined Function That Has a Return Value.

Placing the using Directive in Multifunction Programs.

Summary.

Review Questions.

Programming Exercises.

3. Dealing with Data.

Simple Variables.

Names for Variables.

Integer Types.

The short, int, and long Integer Types.

Unsigned Types.

Choosing an Integer Type.

Integer Constants.

How C++ Decides What Type a Constant Is.

The char Type: Characters and Small Integers.

The bool Type.

The const Qualifier.

Floating-Point Numbers.

Writing Floating-Point Numbers.

Floating-Point Types.

Floating-Point Constants.

Advantages and Disadvantages of Floating-Point Numbers.

C++ Arithmetic Operators.

Order of Operation: Operator Precedence and Associativity.

Division Diversions.

The Modulus Operator.

Type Conversions.

Summary.

Review Questions.

Programming Exercises.

4. Compound Types.

Introducing Arrays.

Program Notes.

Initialization Rules for Arrays.

Strings.

Concatenating String Constants.

Using Strings in an Array.

Adventures in String Input.

Reading String Input a Line at a Time.

Mixing String and Numeric Input.

Introducing the string Class.

Assignment, Concatenation, and Appending.

More string Class Operations.

More on string Class I/O.

Introducing Structures.

Using a Structure in a Program.

Can a Structure Use a string Class Member?

Other Structure Properties.

Arrays of Structures.

Bit Fields in Structures.

Unions.

Enumerations.

Setting Enumerator Values.

Value Ranges for Enumerations.

Pointers and the Free Store.

Declaring and Initializing Pointers.

Pointer Danger.

Pointers and Numbers.

Allocating Memory with new.

Freeing Memory with delete.

Using new to Create Dynamic Arrays.

Pointers, Arrays, and Pointer Arithmetic.

Program Notes.

Pointers and Strings.

Using new to Create Dynamic Structures.

Automatic Storage, Static Storage, and Dynamic Storage.

Summary.

Review Questions.

Programming Exercises.

5. Loops and Relational Expressions.

Introducing for Loops.

for Loop Parts.

Back to the for Loop.

Changing the Step Size.

Inside Strings with the for Loop.

The Increment (++) and Decrement (--) Operators.

Side Effects and Sequence Points.

Prefixing Versus Postfixing.

The Increment/Decrement Operators and Pointers.

Combination Assignment Operators.

Compound Statements, or Blocks.

The Comma Operator (or More Syntax Tricks).

Relational Expressions.

A Mistake You'll Probably Make.

Comparing C-Style Strings.

Comparing string Class Strings.

The while Loop.

Program Notes.

for Versus while.

Just a Moment-Building a Time-Delay Loop.

The do while Loop.

Loops and Text Input.

Using Unadorned cin for Input.

cin.get(char) to the Rescue.

Which cin.get()?

The End-of-File Condition.

Yet Another Version of cin.get().

Nested Loops and Two-Dimensional Arrays.

Initializing a Two-Dimensional Array.

Summary.

Review Questions.

Programming Exercises.

6. Branching Statements and Logical Operators.

The if Statement.

The if else Statement.

Formatting if else Statements.

The if else if else Construction.

Logical Expressions.

The Logical OR Operator:

The Logical AND Operator: &&

The Logical NOT Operator: !

Logical Operator Facts.

Alternative Representations.

The cctype Library of Character Functions.

The ?: Operator.

The switch Statement.

Using Enumerators as Labels.

switch and if else.

The break and continue Statements.

Program Notes.

Number-Reading Loops.

Program Notes.

Simple File Input/Output.

Text I/O and Text Files.

Writing to a Text File.

Reading from a Text File.

Summary.

Review Questions.

Programming Exercises.

7. Functions: C++'s Programming Modules.

Function Review.

Defining a Function.

Prototyping and Calling a Function.

Function Arguments and Passing by Value.

Multiple Arguments.

Another Two-Argument Function.

Functions and Arrays.

How Pointers Enable Array-Processing Functions.

The Implications of Using Arrays as Arguments.

More Array Function Examples.

Functions Using Array Ranges.

Pointers and const.

Functions and Two-Dimensional Arrays.

Functions and C-Style Strings.

Functions with C-Style String Arguments.

Functions That Return C-Style Strings.

Functions and Structures.

Passing and Returning Structures.

Another Example of Using Functions with Structures.

Passing Structure Addresses.

Functions and string Class Objects.

Recursion.

Recursion with a Single Recursive Call.

Recursion with Multiple Recursive Calls.

Pointers to Functions.

Function Pointer Basics.

A Function Pointer Example.

Summary.

Review Questions.

Programming Exercises.

8. Adventures in Functions.

C++ Inline Functions.

Reference Variables.

Creating a Reference Variable.

References as Function Parameters.

Reference Properties and Oddities.

Using References with a Structure.

Using References with a Class Object.

Another Object Lesson: Objects, Inheritance, and References.

When to Use Reference Arguments.

Default Arguments.

Program Notes.

Function Overloading.

An Overloading Example.

When to Use Function Overloading.

Function Templates.

Overloaded Templates.

Explicit Specializations.

Instantiations and Specializations.

Which Function Version Does the Compiler Pick?

Summary.

Review Questions.

Programming Exercises.

9. Memory Models and Namespaces.

Separate Compilation.

Storage Duration, Scope, and Linkage.

Scope and Linkage.

Automatic Storage Duration.

Static Duration Variables.

Specifiers and Qualifiers.

Functions and Linkage.

Language Linking.

Storage Schemes and Dynamic Allocation.

The Placement new Operator.

Program Notes.

Namespaces.

Traditional C++ Namespaces.

New Namespace Features.

A Namespace Example.

Namespaces and the Future.

Summary.

Review Questions.

Programming Exercises.

10. Objects and Classes.

Procedural and Object-Oriented Programming.

Abstraction and Classes.

What Is a Type?

Classes in C++.

Implementing Class Member Functions.

Using Classes.

Reviewing Our Story to Date.

Class Constructors and Destructors.

Declaring and Defining Constructors.

Using Constructors.

Default Constructors.

Destructors.

Improving the Stock Class.

Constructors and Destructors in Review.

Knowing Your Objects: The this Pointer.

An Array of Objects.

The Interface and Implementation Revisited.

Class Scope.

Class Scope Constants.

Abstract Data Types.

Summary.

Review Questions.

Programming Exercises.

11. Working with Classes.

Operator Overloading.

Time on Our Hands: Developing an Operator Overloading Example.

Adding an Addition Operator.

Overloading Restrictions.

More Overloaded Operators.

Introducing Friends.

Creating Friends.

A Common Kind of Friend: Overloading the << Operator.

Overloaded Operators: Member Versus Nonmember Functions.

More Overloading: A Vector Class.

Using a State Member.

Overloading Arithmetic Operators for the Vector Class.

An Implementation Comment.

Taking the Vector Class on a Random Walk.

Automatic Conversions and Type Casts for Classes.

Program Notes.

Conversion Functions.

Conversions and Friends.

Summary.

Review Questions.

Programming Exercises.

12. Classes and Dynamic Memory Allocation.

Dynamic Memory and Classes.

A Review Example and Static Class Members.

Implicit Member Functions.

The New, Improved String Class.

Things to Remember When Using new in Constructors.

Observations About Returning Objects.

Using Pointers to Objects.

Reviewing Techniques.

A Queue Simulation.

A Queue Class.

The Customer Class.

The Simulation.

Summary.

Review Questions.

Programming Exercises.

13. Class Inheritance.

Beginning with a Simple Base Class.

Deriving a Class.

Constructors: Access Considerations.

Using a Derived Class.

Special Relationships Between Derived and Base Classes.

Inheritance: An Is-a Relationship.

Polymorphic Public Inheritance.

Developing the Brass and BrassPlus Classes.

Static and Dynamic Binding.

Pointer and Reference Type Compatibility.

Virtual Member Functions and Dynamic Binding.

Things to Know About Virtual Methods.

Access Control: protected.

Abstract Base Classes.

Applying the ABC Concept.

ABC Philosophy.

Inheritance and Dynamic Memory Allocation.

Case 1: Derived Class Doesn't Use new.

Case 2: Derived Class Does Use new.

An Inheritance Example with Dynamic Memory Allocation and Friends.

Class Design Review.

Member Functions That the Compiler Generates for You.

Other Class Method Considerations.

Public Inheritance Considerations.

Class Function Summary.

Summary.

Review Questions.

Programming Exercises.

14. Reusing Code in C++.

Classes with Object Members.

The valarray Class: A Quick Look.

The Student Class Design.

The Student Class Example.

Private Inheritance.

The Student Class Example (New Version).

Multiple Inheritance.

How Many Workers?

Which Method?

MI Synopsis.

Class Templates.

Defining a Class Template.

Using a Template Class.

A Closer Look at the Template Class.

An Array Template Example and Non-Type Arguments.

Template Versatility.

Template Specializations.

Member Templates.

Templates as Parameters.

Template Classes and Friends.

Summary.

Review Questions.

Programming Exercises.

15. Friends, Exceptions, and More.

Friends.

Friend Classes.

Friend Member Functions.

Other Friendly Relationships.

Nested Classes.

Nested Classes and Access.

Nesting in a Template.

Exceptions.

Calling abort().

Returning an Error Code.

The Exception Mechanism.

Using Objects as Exceptions.

Unwinding the Stack.

More Exception Features.

The exception Class.

Exceptions, Classes, and Inheritance.

When Exceptions Go Astray.

Exception Cautions.

RTTI.

What Is RTTI For?

How Does RTTI Work?

Type Cast Operators.

Summary.

Review Questions.

Programming Exercises.

16. The string Class and the Standard Template Library.

The string Class.

Constructing a String.

string Class Input.

Working with Strings.

What Else Does the string Class Offer?

The auto_ptr Class.

Using auto_ptr.

auto_ptr Considerations.

The STL.

The vector Template Class.

Things to Do to Vectors.

More Things to Do to Vectors.

Generic Programming.

Why Iterators?

Kinds of Iterators.

Iterator Hierarchy.

Concepts, Refinements, and Models.

Kinds of Containers.

Associative Containers.

Function Objects (aka Functors).

Functor Concepts.

Predefined Functors.

Adaptable Functors and Function Adapters.

Algorithms.

Algorithm Groups.

General Properties of Algorithms.

The STL and the string Class.

Functions Versus Container Methods.

Using the STL.

Other Libraries.

vector and valarray.

Summary.

Review Questions.

Programming Exercises.

17. Input, Output, and Files.

An Overview of C++ Input and Output.

Streams and Buffers.

Streams, Buffers, and the iostream File.

Redirection.

Output with cout.

The Overloaded << Operator.

The Other ostream Methods.

Flushing the Output Buffer.

Formatting with cout.

Input with cin.

How cin >> Views Input.

Stream States.

Other istream Class Methods.

Other istream Methods.

File Input and Output.

Simple File I/O.

Stream Checking and is_open().

Opening Multiple Files.

Command-Line Processing.

File Modes.

Random Access.

Incore Formatting.

What Now?

Summary.

Review Questions.

Programming Exercises.

Appendix A. Number Bases.

Decimal Numbers (Base 10).

Octal Integers (Base 8).

Hexadecimal Numbers (Base 16).

Binary Numbers (Base 2).

Binary and Hex.

Appendix B. C++ Reserved Words.

C++ Keywords.

Alternative Tokens.

C++ Library Reserved Names.

Appendix C. The ASCII Character Set.

Appendix D. Operator Precedence.

Appendix E. Other Operators.

Bitwise Operators.

The Shift Operators.

The Logical Bitwise Operators.

Alternative Representations of Bitwise Operators.

A Few Common Bitwise Operator Techniques.

Member Dereferencing Operators.

Appendix F. The string Template Class.

Thirteen Types and a Constant.

Data Information, Constructors, and Odds and Ends.

Default Constructors.

Constructors That Use Arrays.

Constructors That Use Part of an Array.

Copy Constructors.

Constructors That Use n Copies of a Character.

Constructors That Use a Range.

Memory Miscellany.

String Access.

Basic Assignment.

String Searching.

The find() Family.

The rfind() Family.

The find_first_of() Family.

The find_last_of() Family.

The find_first_not_of() Family.

The find_last_not_of() Family.

Comparison Methods and Functions.

String Modifiers.

Methods for Appending and Adding.

More Assignment Methods.

Insertion Methods.

Erase Methods.

Replacement Methods.

Other Modifying Methods: copy() and swap().

Output and Input.

Appendix G. The STL Methods and Functions.

Members Common to All Containers.

Additional Members for Vectors, Lists, and Deques.

Additional Members for Sets and Maps.

STL Functions.

Nonmodifying Sequence Operations.

Mutating Sequence Operations.

Sorting and Related Operations.

Numeric Operations.

Appendix H. Selected Readings and Internet Resources.

Selected Readings.

Internet Resources.

Appendix I. Converting to ANSI/ISO Standard C++.

Use Alternatives for Some Preprocessor Directives.

Use const Instead of #define to Define Constants.

Use inline Instead of #define to Define Short Functions.

Use Function Prototypes.

Use Type Casts.

Become Familiar with C++ Features.

Use the New Header Organization.

Use Namespaces.

Use the autoptr Template.

Use the string Class.

Use the STL.

Appendix J. Answers to the Review Questions.

Answers to Review Questions for Chapter 2.

Answers to Review Questions for Chapter 3.

Answers to Review Questions for Chapter 4.

Answers to Review Questions for Chapter 5.

Answers to Review Questions for Chapter 6.

Answers to Review Questions for Chapter 7.

Answers to Review Questions for Chapter 8.

Answers to Review Questions for Chapter 9.

Answers to Review Questions for Chapter 10.

Answers to Review Questions for Chapter 11.

Answers to Review Questions for Chapter 12.

Answers to Review Questions for Chapter 13.

Answers to Review Questions for Chapter 14.

Answers to Review Questions for Chapter 15.

Answers to Review Questions for Chapter 16.

Answers to Review Questions for Chapter 17.

Index.

Read More Show Less

Preface

Introduction

Preface to the Fifth Edition

Learning C++ is an adventure of discovery, particularly because the language accommodates several programming paradigms, including object-oriented programming, generic programming, and the traditional procedural programming. C++ was a moving target as the language added new features, but now, with the ISO/ANSI C++ Standard, Second Edition (2003), in place, the language has stabilized. Contemporary compilers support most or all of the features mandated by the standard, and programmers have had time to get used to applying these features. The fifth edition of this book, C++ Primer Plus, reflects the ISO/ANSI standard and describes this matured version of C++.

C++ Primer Plus discusses the basic C language and presents C++ features, making this book self-contained. It presents C++ fundamentals and illustrates them with short, to-the-point programs that are easy to copy and experiment with. You'll learn about input/output (I/O), how to make programs perform repetitive tasks and make choices, the many ways to handle data, and how to use functions. You'll learn about the many features C++ has added to C, including the following:

  • Classes and objects
  • Inheritance
  • Polymorphism, virtual functions, and runtime type identification (RTTI)
  • Function overloading
  • Reference variables
  • Generic, or type-independent, programming, as provided by templates and the Standard Template Library (STL)
  • The exception mechanism for handling error conditions
  • Namespaces for managing names of functions, classes, and variables

The Primer Approach

C++ Primer Plus brings several virtues to the task of presenting all this material. It builds on the primer tradition begun by C Primer Plus nearly two decades ago and embraces its successful philosophy:

  • A primer should be an easy-to-use, friendly guide.
  • A primer doesn't assume that you are already familiar with all relevant programming concepts.
  • A primer emphasizes hands-on learning with brief, easily typed examples that develop your understanding, a concept or two at a time.
  • A primer clarifies concepts with illustrations.
  • A primer provides questions and exercises to let you test your understanding, making the book suitable for self-learning or for the classroom.

Following these principles, the book helps you understand this rich language and how to use it. For example:

  • It provides conceptual guidance about when to use particular features, such as using public inheritance to model what are known as is-a relationships.
  • It illustrates common C++ programming idioms and techniques.
  • It provides a variety of sidebars, including tips, cautions, things to remember, compatibility notes, and real-world notes.

The author and editors of this book do our best to keep the presentation to-the-point, simple, and fun. Our goal is that by the end of the book, you'll be able to write solid, effective programs and enjoy yourself doing so.

Sample Code Used in This Book

This book provides an abundance of sample code, most of it in the form of complete programs. Like the previous editions, this book practices generic C++ so that it is not tied to any particular kind of computer, operating system, or compiler. Thus, the examples were tested on a Windows XP system, a Macintosh OS X system, and a Linux system. Only a few programs were affected by compiler non-conformance issues. Compiler compliance with the C++ standard has improved since the previous edition of this book first appeared.

The sample code for the complete programs described in this book is available on the Sams website, at http://www.samspublishing.com. Enter this book's ISBN (without the hyphens) in the Search box and click Search. When the book's title is displayed, click the title to go to a page where you can download the code. You also can find solutions to selected programming exercises at this site.

How This Book Is Organized

This book is divided into 17 chapters and 10 appendixes, summarized here.

Chapter 1: Getting Started

Chapter 1 relates how Bjarne Stroustrup created the C++ programming language by adding object-oriented programming support to the C language. You'll learn the distinctions between procedural languages, such as C, and object-oriented languages, such as C++. You'll read about the joint ANSI/ISO work to develop a C++ standard. This chapter discusses the mechanics of creating a C++ program, outlining the approach for several current C++ compilers. Finally, it describes the conventions used in this book.

Chapter 2: Setting Out to C++

Chapter 2 guides you through the process of creating simple C++ programs. You'll learn about the role of the main() function and about some of the kinds of statements that C++ programs use. You'll use the predefined cout and cin objects for program output and input, and you'll learn about creating and using variables. Finally, you'll be introduced to functions, C++'s programming modules.

Chapter 3: Dealing with Data

C++ provides built-in types for storing two kinds of data: integers (numbers with no fractional parts) and floating-point numbers (numbers with fractional parts). To meet the diverse requirements of programmers, C++ offers several types in each category. Chapter 3 discusses those types, including creating variables and writing constants of various types. You'll also learn how C++ handles implicit and explicit conversions from one type to another.

Chapter 4: Compound Types

C++ lets you construct more elaborate types from the basic built-in types. The most advanced form is the class, discussed in Chapters 9 through 13. Chapter 4 discusses other forms, including arrays, which hold several values of a single type; structures, which hold several values of unlike types; and pointers, which identify locations in memory. You'll also learn how to create and store text strings and to handle text I/O by using C-style character arrays and the C++ string class. Finally, you'll learn some of the ways C++ handles memory allocation, including using the new and delete operators for managing memory explicitly.

Chapter 5: Loops and Relational Expressions

Programs often must perform repetitive actions, and C++ provides three looping structures for that purpose: the for loop, the while loop, and the do while loop. Such loops must know when they should terminate, and the C++ relational operators enable you to create tests to guide such loops. In Chapter 5 you learn how to create loops that read and process input character-by-character. Finally, you'll learn how to create two-dimensional arrays and how to use nested loops to process them.

Chapter 6: Branching Statements and Logical Operators

Programs can behave intelligently if they can tailor their behavior to circumstances. In Chapter 6 you'll learn how to control program flow by using the if, if else, and switch statements and the conditional operator. You'll learn how to use logical operators to help express decision-making tests. Also, you'll meet the cctype library of functions for evaluating character relations, such as testing whether a character is a digit or a nonprinting character. Finally, you'll get an introductory view of file I/O.

Chapter 7: Functions: C++'s Programming Modules

Functions are the basic building blocks of C++ programming. Chapter 7 concentrates on features that C++ functions share with C functions. In particular, you'll review the general format of a function definition and examine how function prototypes increase the reliability of programs. Also, you'll investigate how to write functions to process arrays, character strings, and structures. Next, you'll learn about recursion, which is when a function calls itself, and see how it can be used to implement a divide-and-conquer strategy. Finally, you'll meet pointers to functions, which enable you to use a function argument to tell one function to use a second function.

Chapter 8: Adventures in Functions

Chapter 8 explores the new features C++ adds to functions. You'll learn about inline functions, which can speed program execution at the cost of additional program size. You'll work with reference variables, which provide an alternative way to pass information to functions. Default arguments let a function automatically supply values for function arguments that you omit from a function call. Function overloading lets you create functions having the same name but taking different argument lists. All these features have frequent use in class design. Also, you'll learn about function templates, which allow you to specify the design of a family of related functions.

Chapter 9: Memory Models and Namespaces

Chapter 9 discusses putting together multifile programs. It examines the choices in allocating memory, looking at different methods of managing memory and at scope, linkage, and namespaces, which determine what parts of a program know about a variable.

Chapter 10: Objects and Classes

A class is a user-defined type, and an object (such as a variable) is an instance of a class. Chapter 10 introduces you to object-oriented programming and to class design. A class declaration describes the information stored in a class object and also the operations (class methods) allowed for class objects. Some parts of an object are visible to the outside world (the public portion), and some are hidden (the private portion). Special class methods (constructors and destructors) come into play when objects are created and destroyed. You will learn about all this and other class details in this chapter, and you'll see how classes can be used to implement ADTs, such as a stack.

Chapter 11: Working with Classes

In Chapter 11 you'll further your understanding of classes. First, you'll learn about operator overloading, which lets you define how operators such as + will work with class objects. You'll learn about friend functions, which can access class data that's inaccessible to the world at large. You'll see how certain constructors and overloaded operator member functions can be used to manage conversion to and from class types.

Chapter 12: Classes and Dynamic Memory Allocation

Often it's useful to have a class member point to dynamically allocated memory. If you use new in a class constructor to allocate dynamic memory, you incur the responsibilities of providing an appropriate destructor, of defining an explicit copy constructor, and of defining an explicit assignment operator. Chapter 12 shows you how and discusses the behavior of the member functions generated implicitly if you fail to provide explicit definitions. You'll also expand your experience with classes by using pointers to objects and studying a queue simulation problem.

Chapter 13: Class Inheritance

One of the most powerful features of object-oriented programming is inheritance, by which a derived class inherits the features of a base class, enabling you to reuse the base class code. Chapter 13 discusses public inheritance, which models is-a relationships, meaning that a derived object is a special case of a base object. For example, a physicist is a special case of a scientist. Some inheritance relationships are polymorphic, meaning you can write code using a mixture of related classes for which the same method name may invoke behavior that depends on the object type. Implementing this kind of behavior necessitates using a new kind of member function called a virtual function. Sometimes using abstract base classes is the best approach to inheritance relationships. This chapter discusses these matters, pointing out when public inheritance is appropriate and when it is not.

Chapter 14: Reusing Code in C++

Public inheritance is just one way to reuse code. Chapter 14 looks at several other ways. Containment is when one class contains members that are objects of another class. It can be used to model has-a relationships, in which one class has components of another class. For example, an automobile has a motor. You also can use private and protected inheritance to model such relationships. This chapter shows you how and points out the differences among the different approaches. Also, you'll learn about class templates, which let you define a class in terms of some unspecified generic type, and then use the template to create specific classes in terms of specific types. For example, a stack template enables you to create a stack of integers or a stack of strings. Finally, you'll learn about multiple public inheritance, whereby a class can derive from more than one class.

Chapter 15: Friends, Exceptions, and More

Chapter 15 extends the discussion of friends to include friend classes and friend member functions. Then it presents several new developments in C++, beginning with exceptions, which provide a mechanism for dealing with unusual program occurrences, such an inappropriate function argument values and running out of memory. Then you'll learn about RTTI, a mechanism for identifying object types. Finally, you'll learn about the safer alternatives to unrestricted typecasting.

Chapter 16: The string Class and the Standard Template Library

Chapter 16 discusses some useful class libraries recently added to the language. The string class is a convenient and powerful alternative to traditional C-style strings. The auto_ptr class helps manage dynamically allocated memory. The STL provides several generic containers, including template representations of arrays, queues, lists, sets, and maps. It also provides an efficient library of generic algorithms that can be used with STL containers and also with ordinary arrays. The valarray template class provides support for numeric arrays.

Chapter 17: Input, Output, and Files

Chapter 17 reviews C++ I/O and discusses how to format output. You'll learn how to use class methods to determine the state of an input or output stream and to see, for example, whether there has been a type mismatch on input or whether the end-of-file has been detected. C++ uses inheritance to derive classes for managing file input and output. You'll learn how to open files for input and output, how to append data to a file, how to use binary files, and how to get random access to a file. Finally, youlearn how to apply standard I/O methods to read from and write to strings.

Appendix A: Number Bases

Appendix A discusses octal, hexadecimal, and binary numbers.

Appendix B: C++ Reserved Words

Appendix B lists C++ keywords.

Appendix C: The ASCII Character Set

Appendix C lists the ASCII character set, along with decimal, octal, hexadecimal, and binary representations.

Appendix D: Operator Precedence

Appendix D lists the C++ operators in order of decreasing precedence.

Appendix E: Other Operators

Appendix E summarizes the C++ operators, such as the bitwise operators, not covered in the main body of the text.

Appendix F: The string Template Class

Appendix F summarizes string class methods and functions.

Appendix G: The STL Methods and Functions

Appendix G summarizes the STL container methods and the general STL algorithm functions.

Appendix H: Selected Readings and Internet Resources

Appendix H lists some books that can further your understanding of C++.

Appendix I: Converting to ANSI/ISO Standard C++

Appendix I provides guidelines for moving from C and older C++ implementations to ANSI/ISO C++.

Appendix J: Answers to Review Questions

Appendix J contains the answers to the review questions posed at the end of each chapter.

Note to Instructors

One of the goals of this edition of C++ Primer Plus is to provide a book that can be used as either a teach-yourself book or as a textbook. Here are some of the features that support using C++ Primer Plus, Fifth Edition, as a textbook:

  • This book describes generic C++, so it isn't dependent on a particular implementation.
  • The contents track the ISO/ANSI C++ standards committee's work and include discussions of templates, the STL, the string class, exceptions, RTTI, and namespaces.
  • It doesn't assume prior knowledge of C, so it can be used without a C prerequisite. (Some programming background is desirable, however.)
  • Topics are arranged so that the early chapters can be covered rapidly as review chapters for courses that do have a C prerequisite.
  • Chapters include review questions and programming exercises. Appendix J provides the answers to the review questions. Solutions to selected programming exercises can be found at the Sams website (http://www.samspublishing.com).
  • The book introduces several topics that are appropriate for computer science courses, including abstract data types (ADTs), stacks, queues, simple lists, simulations, generic programming, and using recursion to implement a divide-and-conquer strategy.
  • Most chapters are short enough to cover in a week or less.
  • The book discusses when to use certain features as well as how to use them. For example, it links public inheritance to is-a relationships and composition and private inheritance to has-a relationships, and it discusses when to use virtual functions and when not to.

Conventions Used in This Book

This book uses several typographic conventions to distinguish among various kinds of text:

  • Code lines, commands, statements, variables, filenames, and program output appear in a computer typeface: #include <iostream>int main(){ using namespace std; cout << "What's up, Doc!\ n"; return 0;}
  • Program input that you should type appears in bold computer typeface: Please enter your name:Plato
  • Placeholders in syntax descriptions appear in an italic computer typeface. You should replace a placeholder with the actual filename, parameter, or whatever element it represents.
  • Italic type is used for new terms.

This book includes several elements intended to illuminate specific points:


Compatibility Note - Most compilers are not yet 100% compliant with the ISO/ANSI Standard, and these notes warn you of discrepancies you may encounter.



Remember - These notes highlight points that are important to remember.



Real-World Note - Several professional programmers offer observations based on their experiences.



Sidebar - A sidebar provides a deeper discussion or additional background to help illuminate a topic.



Tip - Tips present short, helpful guides to particular programming situations.



Caution - A caution alerts you to potential pitfalls.



Note - The notes provide a catch-all category for comments that don't fall into one of the other categories.


Systems Used to Develop This Book's Programming Examples

For the record, the examples in this book were developed using Microsoft Visual C++ 7.1 (the version that comes with Microsoft Visual Studio .NET 2003) and Metrowerks CodeWarrior Development Studio 9 on a Pentium PC with a hard disk and running under Windows XP Professional. Most programs were checked using the Borland C++ 5.5 command-line compiler and GNU gpp 3.3.3 on the same system, using Comeau 4.3.3 and GNU g++ 3.3.1 on an IBM-compatible Pentium running SuSE 9.0 Linux, and using Metrowerks Development Studio 9 on a Macintosh G4 under OS 10.3. This book reports discrepancies stemming from lagging behind the standard generically, as in "older implementations use ios::fixed instead of ios_base::fixed." This book reports some bugs and idiosyncrasies in older compilers that would prove troublesome or confusing; most of these have been fixed in current releases.

C++ offers a lot to the programmer; learn and enjoy!

© Copyright Pearson Education. All rights reserved.

Read More Show Less

Customer Reviews

Average Rating 4
( 8 )
Rating Distribution

5 Star

(4)

4 Star

(1)

3 Star

(1)

2 Star

(2)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 10 Customer Reviews
  • Anonymous

    Posted March 3, 2004

    Insightful text, poor graphics

    The best way to rate Stephen Prata's C++ Primer, Fourth edition, is to compare it to the classic 'C++, How to Program,' Fourth edition, by Deitel & Deitel. I find that there is a place for both on my bookshelf. Although both are books for the beginning to intermediate C++ programmer, there's a big difference in how they cover the material. Prata covers just about the same ground as Deitel & Deitel , but with a more conversational ease and natural flow. Reading Prata is almost like having someone explain a topic to you in person. Prata includes helpful notes, including the idiosyncracies of the popular compilers, that will save you lots of wasted effort, and maybe your sanity as well. Prata writes a book that you can read with ease, confident that he will get to all the important topics. It is all there, and very accessible. C++ Primer Plus, Fourth edition, could have earned a five star rating from this reviewer were it not for numerous typographical errors and exceedingly poor graphics. For example, Figure 13.5 (page 598), which attempts to provide a graphic overview of the important topic of Virtual Function Tables, is made unreadable by the application of a gradient fill which obliterates much of the text. Other diagrams in the book are similarly defaced by amateurish and inappropriate use of gradient fills and excessive borders. This is quite disappointing in a book that has undergone four editions and a second reprint, August 2002, 'with corrections.' Furthermore, there's no CD-ROM packaged with the Fourth edition, although example code is said to available at the publisher's website. In summary, this is an excellent text marred by poor production values (typos and illegible graphics). Never the less, it is exceedingly good at presenting the foundations and advanced topics of C++ in an accessible style. I highly reccommend this book.

    4 out of 4 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Posted December 3, 2008

    An Excellent Book!

    C++ Primer is an excelently constructed book, I am 13 years old and interested in programming. I had ordered this book and am learning decently. Stephen Prata does an excellent job telling readers alternative way around problems and how to flex through different situations depending on what software or operating system you have, Wich i may add is another positive aspect to this book, its not limited to one specific Compiler, Operating system, Or whatever.<BR/><BR/> I am highley satisfied with this book, and reccomend it to anyone who feels the urge to learn C++. Alot of hard work was put into this book.<BR/>One thing a may add to warn though, is the binding of the book, Try to excersise caution and go easy with the book.

    3 out of 3 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 30, 2008

    An incredible book!

    It is staggering just how much work and insight has gone into this book. Whereas others frequently adopt the 'don't worry about why, just type this' approach, Prata explains the how and the why, but it comes across as a conversation - free flowing and easy to read - unlike so many other books on this complex topic. Truly a work of art!

    1 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 25, 2007

    A reviewer

    This book is excellent book, especially for beginners. Clear, easy-to-understand explaination every concept and feature of the C++ programming language. I consider this is the best ever written for learning C++, highly recommanded for anyone who seriously wants to learn C++

    1 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted December 13, 2003

    A great C++ book

    A very good book.. A classic. A must read and have

    1 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted March 27, 2001

    Excelent book

    This book has everything I need. It gives you some insight in programming.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted December 11, 2008

    No text was provided for this review.

  • Anonymous

    Posted December 26, 2008

    No text was provided for this review.

  • Anonymous

    Posted June 24, 2011

    No text was provided for this review.

  • Anonymous

    Posted May 13, 2010

    No text was provided for this review.

Sort by: Showing all of 10 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)