did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780672326974

C++ Primer Plus

by
  • ISBN13:

    9780672326974

  • ISBN10:

    0672326973

  • Edition: 5th
  • Format: Paperback
  • Copyright: 2005-01-01
  • Publisher: Sams
  • View Upgraded Edition
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $59.99 Save up to $6.00
  • Digital
    $53.99
    Add to Cart

    DURATION
    PRICE

Supplemental Materials

What is included with this book?

Summary

With more than 100,000 copies sold in four previous editions, C++ Primer Plus has established a reputation as a carefully tested, well-crafted, and complete tutorial on a subject core to programmers and developers. This computer industry classic teaches principles of programming, including structured code and top-down design. Classes, inheritance, templates, and exceptions, as well as the latest object-oriented programming techniques, are covered.

Author Biography

Stephen Prata teaches astronomy, physics, and computer science at the College of Marin in Kentfield, California.

Table of Contents

Introduction 1(10)
Getting Started
11(18)
Learning C++: What Lies Before You
11(1)
The Origins of C++: A Little History
12(5)
The C Language
13(1)
C Programming Philosophy
13(1)
The C++ Shift: Object-Oriented Programming
14(1)
C++ and Generic Programming
15(1)
The Genesis of C++
16(1)
Portability and Standards
17(2)
The Mechanics of Creating a Program
19(8)
Creating the Source Code File
20(2)
Compilation and Linking
22(5)
Summary
27(2)
Setting Out to C++
29(36)
C++ Initiation
29(14)
The main ( ) Function
31(3)
C++ Comments
34(1)
The C++ Preprocessor and the iostream File
35(1)
Header Filenames
36(1)
Namespaces
37(1)
C++ Output with cout
38(3)
C++ Source Code Formatting
41(2)
C++ Statements
43(4)
Declaration Statements and Variables
43(2)
Assignment Statements
45(1)
A New Trick for cout
46(1)
More C++ Statements
47(3)
Using cin
47(1)
Concatenating with cout
48(1)
cin and cout: A Touch of Class
48(2)
Functions
50(12)
Using a Function That Has a Return Value
50(4)
Function Variations
54(1)
User-Defined Functions
55(3)
Using a User-Defined Function That Has a Return Value
58(2)
Placing the using Directive in Multifunction Programs
60(2)
Summary
62(1)
Review Questions
63(1)
Programming Exercises
64(1)
Dealing with Data
65(44)
Simple Variables
66(22)
Names for Variables
66(2)
Integer Types
68(1)
The short, int, and long Integer Types
68(5)
Unsigned Types
73(2)
Choosing an Integer Type
75(1)
Integer Constants
76(2)
How C++ Decides What Type a Constant Is
78(1)
The char Type: Characters and Small Integers
79(8)
The bool Type
87(1)
The const Qualifier
88(1)
Floating-Point Numbers
89(6)
Writing Floating-Point Numbers
89(2)
Floating-Point Types
91(2)
Floating-Point Constants
93(1)
Advantages and Disadvantages of Floating-Point Numbers
94(1)
C++ Arithmetic Operators
95(10)
Order of Operation: Operator Precedence and Associativity
96(1)
Division Diversions
97(2)
The Modulus Operator
99(1)
Type Conversions
100(5)
Summary
105(1)
Review Questions
106(1)
Programming Exercises
107(2)
Compound Types
109(68)
Introducing Arrays
110(4)
Program Notes
112(1)
Initialization Rules for Arrays
113(1)
Strings
114(11)
Concatenating String Constants
116(1)
Using Strings in an Array
116(2)
Adventures in String Input
118(1)
Reading String Input a Line at a Time
119(5)
Mixing String and Numeric Input
124(1)
Introducing the String Class
125(6)
Assignment, Concatenation and Appending
126(1)
More string Class Operations
127(2)
More on string Class I/O
129(2)
Introducing Structures
131(8)
Using a Structure in a Program
133(2)
Can a Structure Use a string Class Member?
135(1)
Other Structure Properties
136(1)
Arrays of Structures
137(2)
Bit Fields in Structures
139(1)
Unions
139(2)
Enumerations
141(3)
Setting Enumerator Values
142(1)
Value Ranges for Enumerations
143(1)
Pointers and the Free Store
144(12)
Declaring and Initializing Pointers
147(2)
Pointer Danger
149(1)
Pointers and Numbers
150(1)
Allocating Memory with new
150(2)
Freeing Memory with delete
152(1)
Using new to Create Dynamic Arrays
153(3)
Pointers, Arrays, and Pointer Arithmetic
156(16)
Program Notes
157(5)
Pointers and Strings
162(4)
Using new to Create Dynamic Structures
166(4)
Automatic Storage, Static Storage, and Dynamic Storage
170(2)
Summary
172(1)
Review Questions
173(1)
Programming Exercises
174(3)
Loops and Relational Expressions
177(54)
Introducing for Loops
178(20)
for Loop Parts
179(6)
Back to the for Loop
185(2)
Changing the Step Size
187(1)
Inside Strings with the for Loop
188(1)
The Increment (++) and Decrement (- -) Operators
189(1)
Side Effects and Sequence Points
190(1)
Prefixing Versus Postfixing
191(1)
The Increment/Decrement Operators and Pointers
191(1)
Combination Assignment Operators
192(1)
Compound Statements, or Blocks
193(2)
The Comma Operator (or More Syntax Tricks)
195(3)
Relational Expressions
198(7)
A Mistake You'll Probably Make
199(2)
Comparing C-Style Strings
201(3)
Comparing string Class Strings
204(1)
The while Loop
205(6)
Program Notes
207(1)
for Versus while
207(2)
Just a Moment---Building a Time-Delay Loop
209(2)
The do while Loop
211(2)
Loops and Text Input
213(10)
Using Unadorned cin for Input
214(1)
cin.get (char) to the Rescue
215(1)
Which cin.get ()?
216(1)
The End-of-File Condition
217(3)
Yet Another Version of cin.get ()
220(3)
Nested Loops and Two-Dimensional Arrays
223(4)
Initializing a Two-Dimensional Array
225(2)
Summary
227(1)
Review Questions
228(1)
Programming Exercises
229(2)
Branching Statements and Logical Operators
231(48)
The if Statement
231(7)
The if else Statement
233(2)
Formatting if else Statement
235(1)
The if else if else Construction
236(2)
Logical Expressions
238(9)
The Logical OR Operator: II
238(1)
The Logical AND Operator: &&
239(5)
The Logical NOT Operator: !
244(2)
Logical Operator Facts
246(1)
Alternative Representations
247(1)
The cctype Library of Character Functions
247(3)
The ?: Operator
250(1)
The switch Statement
251(5)
Using Enumerators as Labels
255(1)
switch and if else
256(1)
The break and continue Statements
256(3)
Program Notes
258(1)
Number-Reading Loops
259(3)
Program Notes
262(1)
Simple File Input/Output
262(11)
Text I/O and Text Files
263(1)
Writing to a Text File
264(4)
Reading from a Text File
268(5)
Summary
273(1)
Review Questions
274(2)
Programming Exercises
276(3)
Functions: C++'s Programming Modules
279(58)
Function Review
280(6)
Defining a Function
281(2)
Prototyping and Calling a Function
283(3)
Function Arguments and Passing by Value
286(7)
Multiple Arguments
288(2)
Another Two-Argument Function
290(3)
Functions and Arrays
293(15)
How Pointers Enable Array-Processing Functions
294(1)
The Implications of Using Arrays as Arguments
295(2)
More Array Function Examples
297(6)
Functions Using Array Ranges
303(2)
Pointers and const
305(3)
Functions and Two-Dimensional Arrays
308(1)
Functions and C-Style Strings
309(4)
Functions with C-Style String Arguments
310(2)
Functions That Return C-Style Strings
312(1)
Functions and Structures
313(9)
Passing and Returning Structures
314(2)
Another Example of Using Functions with Structures
316(4)
Passing Structure Addresses
320(2)
Functions and string Class Objects
322(2)
Recursion
324(3)
Recursion with a Single Recursive Call
324(2)
Recursion with Multiple Recursive Calls
326(1)
Pointers to Functions
327(5)
Function Pointer Basics
328(2)
A Function Pointer Example
330(2)
Summary
332(1)
Review Questions
333(1)
Programming Exercises
334(3)
Adventures in Functions
337(56)
C++ Inline Functions
337(3)
Reference Variables
340(22)
Creating a Reference Variable
341(3)
References as Function Parameters
344(3)
Reference Properties and Oddities
347(4)
Using References with a Structure
351(4)
Using References with a Class Object
355(3)
Another Object Lesson: Objects, Inheritance, and References
358(3)
When to Use Reference Arguments
361(1)
Default Arguments
362(3)
Program Notes
364(1)
Function Overloading
365(5)
An Overloading Example
367(3)
When to Use Function Overloading
370(1)
Function Templates
370(18)
Overloaded Templates
374(2)
Explicit Specializations
376(4)
Instantiations and Specializations
380(2)
Which Function Version Does the Compiler Pick?
382(6)
Summary
388(1)
Review Questions
389(1)
Programming Exercises
390(3)
Memory Models and Namespaces
393(52)
Separate Compilation
393(6)
Storage Duration, Scope, and Linkage
399(21)
Scope and Linkage
399(1)
Automatic Storage Duration
400(6)
Static Duration Variables
406(9)
Specifiers and Qualifiers
415(3)
Functions and Linkage
418(1)
Language Linking
419(1)
Storage Schemes and Dynamic Allocation
419(1)
The Placement new Operator
420(4)
Program Notes
423(1)
Namespaces
424(13)
Traditional C++ Namespaces
424(2)
New Namespace Features
426(7)
A Namespace Example
433(4)
Namespaces and the Future
437(1)
Summary
437(1)
Review Questions
438(3)
Programming Exercises
441(4)
Objects and Classes
445(56)
Procedural and Object-Oriented Programming
446(1)
Abstraction and Classes
447(16)
What Is a Type?
447(1)
Classes in C++
448(5)
Implementing Class Member Functions
453(5)
Using Classes
458(4)
Reviewing Our Story to Date
462(1)
Class Constructors and Destructors
463(14)
Declaring and Defining Constructors
464(1)
Using Constructors
465(1)
Default Constructors
466(1)
Destructors
467(1)
Improving the Stock Class
468(7)
Constructors and Destructors in Review
475(2)
Knowing Your Objects: The this Pointer
477(6)
An Array of Objects
483(3)
The Interface and Implementation Revisited
486(1)
Class Scope
487(2)
Class Scope Constants
488(1)
Abstract Data Types
489(6)
Summary
495(1)
Review Questions
496(1)
Programming Exercises
496(5)
Working with Classes
501(60)
Operator Overloading
502(1)
Time on Our Hands: Developing an Operator Overloading Example
503(12)
Adding an Addition Operator
506(4)
Overloading Restrictions
510(2)
More Overloaded Operators
512(3)
Introducing Friends
515(9)
Creating Friends
516(2)
A Common Kind of Friend: Overloading the << Operator
518(6)
Overloaded Operators: Member Versus Nonmember Functions
524(1)
More Overloading: A Vector Class
525(16)
Using a State Member
533(2)
Overloading Arithmetic Operators for the Vector Class
535(2)
An Implementation Comment
537(1)
Taking the Vector Class on a Random Walk
538(3)
Automatic Conversions and Type Casts for Classes
541(15)
Program Notes
547(1)
Conversion Functions
547(6)
Conversions and Friends
553(3)
Summary
556(2)
Review Questions
558(1)
Programming Exercises
558(3)
Classes and Dynamic Memory Allocation
561(72)
Dynamic Memory and Classes
562(45)
A Review Example and Static Class Members
562(9)
Implicit Member Functions
571(8)
The New, Improved String Class
579(11)
Things to Remember When Using new in Constructors
590(3)
Observations About Returning Objects
593(3)
Using Pointers to Objects
596(10)
Reviewing Techniques
606(1)
A Queue Simulation
607(19)
A Queue Class
608(10)
The Customer Class
618(3)
The Simulation
621(5)
Summary
626(1)
Review Questions
627(2)
Programming Exercises
629(4)
Class Inheritance
633(68)
Beginning with a Simple Base Class
634(11)
Deriving a Class
636(2)
Constructors: Access Considerations
638(3)
Using a Derived Class
641(2)
Special Relationships Between Derived and Base Classes
643(2)
Inheritance: An Is-a Relationship
645(2)
Polymorphic Public Inheritance
647(21)
Developing the Brass and BrassPlus Classes
648(12)
Static and Dynamic Binding
660(1)
Pointer and Reference Type Compatibility
660(2)
Virtual Member Functions and Dynamic Binding
662(2)
Things to Know About Virtual Methods
664(4)
Access Control: protected
668(2)
Abstract Base Classes
670(7)
Applying the ABC Concept
672(5)
ABC Philosophy
677(1)
Inheritance and Dynamic Memory Allocation
677(8)
Case 1: Derived Class Doesn't Use new
677(2)
Case 2: Derived Class Does Use new
679(2)
An Inheritance Example with Dynamic Memory Allocation and Friends
681(4)
Class Design Review
685(11)
Member Functions That the Compiler Generates for You
686(1)
Other Class Method Considerations
687(4)
Public Inheritance Considerations
691(4)
Class Function Summary
695(1)
Summary
696(1)
Review Questions
697(1)
Programming Exercises
698(3)
Reusing Code in C++
701(86)
Classes with Object Members
701(11)
The valarray Class: A Quick Look
702(1)
The Student Class Design
703(2)
The Student Class Example
705(7)
Private Inheritance
712(11)
The Student Class Example (New Version)
713(10)
Multiple Inheritance
723(21)
How Many Workers?
728(4)
Which Method?
732(11)
MI Synopsis
743(1)
Class Templates
744(33)
Defining a Class Template
744(4)
Using a Template Class
748(2)
A Closer Look at the Template Class
750(6)
An Array Template Example and Non-Type Arguments
756(2)
Template Versatility
758(4)
Template Specializations
762(3)
Member Templates
765(3)
Templates as Parameters
768(2)
Template Classes and Friends
770(7)
Summary
777(2)
Review Questions
779(2)
Programming Exercises
781(6)
Friends, Exceptions, and More
787(70)
Friends
787(11)
Friend Classes
788(5)
Friend Member Functions
793(3)
Other Friendly Relationships
796(2)
Nested Classes
798(7)
Nested Classes and Access
800(1)
Nesting in a Template
801(4)
Exceptions
805(34)
Calling abort ( )
805(2)
Returning an Error Code
807(1)
The Exception Mechanism
808(4)
Using Objects as Exceptions
812(4)
Unwinding the Stack
816(6)
More Exception Features
822(2)
The exception Class
824(5)
Exceptions, Classes, and Inheritance
829(5)
When Exceptions Go Astray
834(3)
Exception Cautions
837(2)
RTTI
839(9)
What Is RTTI For?
840(1)
How Does RTTI Work?
840(8)
Type Cast Operators
848(4)
Summary
852(1)
Review Questions
853(1)
Programming Exercises
854(3)
The string Class and the Standard Template Library
857(94)
The string Class
857(16)
Constructing a String
858(4)
string Class Input
862(2)
Working with Strings
864(6)
What Else Does the string Class Offer?
870(3)
The auto_ptr Class
873(4)
Using auto_ptr
874(2)
auto_ptr Considerations
876(1)
The STL
877(13)
The vector Template Class
878(2)
Things to Do to Vectors
880(5)
More Things to Do to Vectors
885(5)
Generic Programming
890(32)
Why Iterators?
890(4)
Kinds of Iterators
894(3)
Iterator Hierarchy
897(1)
Concepts, Refinements, and Models
898(7)
Kinds of Containers
905(10)
Associative Containers
915(7)
Function Objects (aka Functors)
922(8)
Functor Concepts
923(3)
Predefined Functors
926(2)
Adaptable Functors and Function Adapters
928(2)
Algorithms
930(10)
Algorithm Groups
931(1)
General Properties of Algorithms
932(1)
The STL and the string Class
933(1)
Functions Versus Container Methods
934(2)
Using the STL
936(4)
Other Libraries
940(6)
vector and valarray
940(6)
Summary
946(2)
Review Questions
948(1)
Programming Exercises
949(2)
Input, Output, and Files
951(90)
An Overview of C++ Input and Output
952(6)
Streams and Buffers
952(3)
Streams, Buffers, and the iostream File
955(2)
Redirection
957(1)
Output with cout
958(25)
The Overloaded << Operator
958(3)
The Other ostream Methods
961(3)
Flushing the Output Buffer
964(1)
Formatting with cout
965(18)
Input with cin
983(20)
How cin >> Views Input
985(2)
Stream States
987(4)
Other istream Class Methods
991(8)
Other istream Methods
999(4)
File Input and Output
1003(27)
Simple File I/O
1004(3)
Stream Checking and is_open ( )
1007(1)
Opening Multiple Files
1008(1)
Command-Line Processing
1008(3)
File Modes
1011(10)
Random Access
1021(9)
Incore Formatting
1030(2)
What Now?
1032(1)
Summary
1033(1)
Review Questions
1034(2)
Programming Exercises
1036(5)
APPENDIX A: Number Bases
1041(6)
Decimal Numbers (Base 10)
1041(1)
Octal Integers (Base 8)
1041(1)
Hexadecimal Numbers (Base 16)
1042(1)
Binary Numbers (Base 2)
1043(1)
Binary and Hex
1043(4)
APPENDIX B: C++ Reserved Words
1047(4)
C++ Keywords
1047(1)
Alternative Tokens
1048(1)
C++ Library Reserved Names
1048(3)
APPENDIX C: The ASCII Character Set
1051(6)
APPENDIX D: Operator Precedence
1057(6)
APPENDIX E: Other Operators
1063(12)
Bitwise Operators
1063(7)
The Shift Operators
1063(2)
The Logical Bitwise Operators
1065(2)
Alternative Representations of Bitwise Operators
1067(1)
A Few Common Bitwise Operator Techniques
1068(2)
Member Dereferencing Operators
1070(5)
APPENDIX F: The string Template Class
1075(20)
Thirteen Types and a Constant
1076(1)
Data Information, Constructors, and Odds and Ends
1077(6)
Default Constructors
1079(1)
Constructors That Use Arrays
1079(1)
Constructors That Use Part of an Array
1080(1)
Copy Constructors
1080(1)
Constructors That Use n Copies of a Character
1081(1)
Constructors That Use a Range
1082(1)
Memory Miscellany
1082(1)
String Access
1083(1)
Basic Assignment
1084(1)
String Searching
1084(4)
The find ( ) Family
1084(1)
The rfind ( ) Family
1085(1)
The find_first_of ( ) Family
1086(1)
The find_last_of ( ) Family
1086(1)
The find_first_not_of ( ) Family
1087(1)
The find_last_not_of ( ) Family
1087(1)
Comparison Methods and Functions
1088(1)
String Modifiers
1089(4)
Methods for Appending and Adding
1089(1)
More Assignment Methods
1090(1)
Insertion Methods
1091(1)
Erase Methods
1091(1)
Replacement Methods
1092(1)
Other Modifying Methods: copy ( ) and swap ( )
1093(1)
Output and Input
1093(2)
APPENDIX G: The STL Methods and Functions
1095(34)
Members Common to All Containers
1095(3)
Additional Members for Vectors, Lists, and Deques
1098(3)
Additional Members for Sets and Maps
1101(1)
STL Functions
1102(27)
Nonmodifying Sequence Operations
1103(4)
Mutating Sequence Operations
1107(8)
Sorting and Related Operations
1115(11)
Numeric Operations
1126(3)
APPENDIX H: Selected Readings and Internet Resources
1129(4)
Selected Readings
1129(2)
Internet Resources
1131(2)
APPENDIX I: Converting to ANSI/ISO Standard C++
1133(8)
Use Alternatives for Some Preprocessor Directives
1133(3)
Use const Instead of #define to Define Constants
1133(2)
Use inline Instead of #define to Define Short Functions
1135(1)
Use Function Prototypes
1136(1)
Use Type Casts
1136(1)
Become Familiar with C++ Features
1137(1)
Use the New Header Organization
1137(1)
Use Namespaces
1137(1)
Use the autoptr Template
1138(1)
Use the string Class
1139(1)
Use the STL
1139(2)
APPENDIX J: Answers to the Review Questions
1141(24)
Answers to Review Questions for Chapter 2
1141(1)
Answers to Review Questions for Chapter 3
1142(1)
Answers to Review Questions for Chapter 4
1143(1)
Answers to Review Questions for Chapter 5
1144(1)
Answers to Review Questions for Chapter 6
1145(2)
Answers to Review Questions for Chapter 7
1147(1)
Answers to Review Questions for Chapter 8
1148(2)
Answers to Review Questions for Chapter 9
1150(1)
Answers to Review Questions for Chapter 10
1151(3)
Answers to Review Questions for Chapter 11
1154(1)
Answers to Review Questions for Chapter 12
1155(2)
Answers to Review Questions for Chapter 13
1157(2)
Answers to Review Questions for Chapter 14
1159(1)
Answers to Review Questions for Chapter 15
1160(1)
Answers to Review Questions for Chapter 16
1161(1)
Answers to Review Questions for Chapter 17
1162(3)
Index 1165

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

Introduction: C++ Primer Plus 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 Plusdiscusses 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 Plusbrings several virtues to the task of presenting all this material. It builds on the primer tradition begun byC Primer Plusnearly 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 asis-arelationships. 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 th

Rewards Program