作者:empty 页数:1303 出版社:empty |
The cover theme for the DE IT EI*HowTo PROGRAM SERIES emphasizes social consciousness issues suchas going green, clean energy, recycling。sustainability and more.Within the text, in addition to conventional programming exercises, we lve included our Making a Difference exercise set to raise awarenessWe hope that whar you learn inC++Hou to Prag raam a, 8/e wil help you to make a difference.found in rainforests The US.Na ronal Cancer Insitu rc has found abour 210 Drain for et plants peithat are eHec tv e agaist cancer cll Fewer than one prent of ra info tet pants peces have been tes edfor medical use.
Rainforests are being def a rested at an alarming rate.According to a March 2010 report by the UnitedNations Food and Agriculture Organization, deforestation has slowed over the last 10 yearsbut more than 30 million acres of forests are still lost annually, and theyre not easily renewedThe United Nations Environment Programme Pant for the Plane:Bil on Tree Campaign is one omany reforestation initiatives.To learn more about how you can make a difference, visit
Deitel&Associates, Inc., is an internationally recognized authoring and corporate training organizationThe company offers instructor-led courses delivered at dient sites worldwide on programming languageand other software topics such asC++, Visual C++, C.Java , Cam, VisualBasic, jective-C*, XML APython.JavaScript, ject technology, Inte met and web programming, and Android and iPhone appHigher Education publi ations and Dive Into*Series corpora retraining.e-mail deite18deite 1.coorvisitwaw.deitel.con/training/.FollowDeitelonFacebaok*atww.deite1.com/deitelfanand on Twitter*O deitel
RainforestsThe worlds rainforests are often referred to as the Far ths lungs. the'jewelsof the Earth and the'worlds largest pharmacy Appr a x imately 50%of theworld's tropical rainforests are in Central and South Americ i, over 33%are inAsia and Oceania f which consists of Australia, NewZealand and various Southp here vast amounts of carbon dioxide-a gas that many scientists blame forglal warmingand they provide approximately 40%of the world'saoxygenThey regulate waterflow to surrounding areas preventing mudslides and croloss.Rainforests also support the livelihoods of 1.6bilion people, provid ifood, freshwater, medicines and more.Approximately 25%of Western mei cines used to treat infections, viruses.cancer and more are derived from plant
Contents
Prefacexxi
1.1
1.4
1.15Wrap-Up
Introduction to Computers and C++
Introduction
Computers:Hardware and Software
Data Hierarchy
Computer Organization
Introduction
Essentials of Counter-Controlled Repetition
for Repetition Statement
Examples Using the for Statement
Machine Languages, Assembly Languages and High-Level Languages
Introduction to Objec r Technology
Operating Systems
Programming Languages
C++and aTypical C++Development Environment
Test-Driving aC++Application
Web 2.0:Going Social
Sofi ware Technologies
Future of C++:TR 1, the New C++Standard and the OpenSource
Boost Libraries
Keeping Up-to-Date with Information Technologic s
2Introduction to C++Programming37
2.1Introduction
一巧First Program inC++:Printing a Line of TextModifying Our First C++ProgramAnother C++Program:Adding IntegersMemory Concepts
27DecisionMaking:Equality and Rel tional Operators号
Introduction to Classes, Objects and Strings
Introduction
Defining a Class with a Member Function
Defining a Member Function with a Parameter
Data Members, set Functions and get Functions
Initializing Objects with Constructors
Placing a Class in a Separate File for Reusability
Separating Interface from Implementation
Validating Data with set Functions
Wrap-Up
4Control Statements:Part 1
4.1Introduction
4.2Algorithms
4.3Pseudocode
4.4Control Structures
4.5if Selection Statement
4.6if.e1se Double-Selection Statement
47while Repetition Statement
4.8FormulatingAlgorithms:Counter-ControlledRepetition
4.9FormulatingAlgorithms:Sentinel-ControlledRepetition
4.10Formulating Algorithms:Nested Control Statements
4.11Assignment Operators
4.12Increment and Decrement Operators
4.13Wrap-Up
5Control Statements:Part 2
5.5do.while Repetition Statement
5.6switch Multiple-Selection Statement
5.7break and continue Statements
5.8Logical Operators
5.9Confusing the Equality(-) and Assignment(-) Operators
5.10Structured Programming Summary
5.11Wrap-Up
Functions and an Introduction to Recursion
Introduction
Program Components inC++
Math Library Functions
Function Definitions with Multiple Parameters
Function Prototypes and Argument Coercion
C++Standard Library Headers
Case Study:Random Number Genc ration
Case Study:Game of Chance:Introducing enum
Storage Classes
Scope Rules
Function Call Stack and Activation Records
Functions with Empty Parameter Lists
Inline Functions
References and Reference Parameters
Default Arguments
Unary Scope Resolution Operator
Function Overloading
Function Templates
Recursion
Example Using Recursion:Fibonacci Series
Recursion vs.Iteration
Wrap-Up
7Arrays and Vectors
Declaring an Array and Using a Loop to In it alize
the Array's Elem nents
Initializing an Array in a Declaration with an
Initializer List
Specifying an Array's Size with a Const an r Variable
and Setting Array Elements with Calculations
Summing the F lements of an Array
Using Bar Charts to Display Array Data Graphically
Using the Elements of an Array as Counters
Using Arrays to Summarize Survey Results
Sr aric Local Arrays and Au romatic Local Arrays
Passing Arrays to Functions
private Data Member
Case Study:Class GradeBook Using an Array to Store Grades
Searching Arrays with Linear Search
Sorting Arrays with Insertion Sort
Multidimensional Arrays
CaseStudy:ClassGradeBookUsingaTwo-DimensionalArray
Introduction to C++Standard Library Class Template vector
Wrap-Up
8Pointers
8.1Introduc rion
8.2Pointer Variable Declarations and Initial zation
8.3Pointer Operators
8.4Pass-by-Reference with Pointers
8.5Using const with Pointers
8.6Selection Sort Using Pass-by-Reference
8.7sizeof Opet at or
8.8Pointer Expressions and Pointer Arithmetic
8.9Relationship Between Pointers and Arrays
8.10Pointer-Based String Processing
8.11Arrays of Pointers
8.12Function Pointers
8.13
Wrap-Up
9Classes:A Deeper Look, Part 1
9.1Introduction
9.2Tine Class Case Study
9.3Class Scope and Accessing Class Members
9.4Separating Interface from Implementation
9.5Access Functions and Utility Functions
9.6Tine Class Case Study:Constructors wth Default Arguments
9.7Destructors
9.8When Constructors and Destructors Are Called
9.9TimeClassCaseStudy:ASubileTrap-ReturningaReferencetoa
9.10Default Member wise Assignment405
9.11Wrap-Up407
10Classes:A Deeper Look, Part 2414
10.1Introduction415
const(Constant) Objects and const Member Functions
Composition:Objects as Members of Classes
friend Functions and friend Classes
Using the this Pointer
static Class Members
Proxy Classes
Operator Overloading; Class string
Introduction
11.10.1 Using the Array Class
11.10.2 Array Class Definition
12.4.1C rearing and Using a Commission Employee Class
12.4.2 Creating a Base Plus Commission Employee Class Without
12.4.3 Creating a Commission Employee-
12.4.4
12.4.5 Commission Employee-Base Plus Commission Employee
13.3.1 Invoking Base-Class Functions from
13.3.2540
13.3.3
13.3.4 Virtual Functions543
13.6.1552
13.6.2 Creating Concrete Derived Class Salaried Emp1oyee556
13.6.3 Creating Concrete Derived Class Commission Employee558
13.6.4 Creating Indirect Concrete Derived Class
13.6.5 Demonstrating Polymorphic Processing562
Binding“Under the Hood 566
Type Information with Down casting.dynamic_cast, typeid
and type_info569
Using the Overloaded Operators of Standard Library Class string
Fundamentals of Operator Overloading
Overloading Binary Operators
Overloading the Binary Stream Insertion and Stream Extraction
Operators
11.6Overloading Unary Operators
11.7Overloading the Unary Prefix and Postfix++and-Operators
11.8Case Study:A Date Class
11.9 Dynamic Memory Management
11.10 Case Study:Array Class
11.11 Operators as Member Functions vs.Non-Member Functions
11.12Convertingberween Types
11.13exp1icit Constructors
11.14 Building a String Class
11.15Wrap-Up
12Object-OrientedProgramming:Inheritance499
12.1Introduction500
12.2Base Classes and Derived Classes500
12.3protected Members503
12.4Relationship between Base Classes and Derived Classes503
xiiContents
12.5Constructors and Destructors in Derived Classes527
12.6public, protected and private Inheritance527
12.7Software Engineering with Inheritance528
12.8Wrap-Up529
13Object-OrientedProgramming:Polymorphism534
13.1Introduction535
13.2Introduction to Polymorphism:Polymorphic VideoGame536
13.3Relationships Among Objects in an Inheritance Hierarchy536
13.4Type Fields and switch Statements549
13.5Abstract Classes and Pure virtual Functions549
13.6Case Study:Payroll System Using Polymorphism551
13.7(Optional) Polymorphism, Virtual Functions and Dynamic
13.8Case Study:Payroll System Using Polymorph im and Runtime
13.9Virtual Destructors573
13.10Wrap-Up573
Templates579
14.1Introduction580
14.2Function Templates580
14.3Overloading Function Templates583
14.4 Class Templates584
Using Inheritance
Base Plus Commission E ployee In her i cance Hierarchy
Commission Emp1oyeeBasePlus Commission Employee
Inheritance Hierarchy Using protected Dara
Inheritance Hierarchy Using private Data
Derived-Class Objects
Aiming Derived-Class Pointers at Base-Class Objects
Derived-Class Member-Function Calls via
Base-Class Pointers
Creating Abstract BaseClass Employee
Base Plus Commission Employee
15.9Tyingan OutputStream co an InputStream
15.10Wrap-Up
15.2.1
Classic Streams vs.Standard Streams
15.2.2io stream Library Headers
15.2.3 Stream Input/Output Classes and Objects
Str cam Output
15.3.1Output of char*Variables
15.3.2
Stream Input
15.4.1
15.4.2
15.4.3 Type-Safe I/O
Unformatted I/O Using read, write and gcount
Introduction to Stream Manipulators
15.6.1
15.6.2
15.6.3 Field Width(width, set w)
15.6.4
Stream Format States and Stream Manipulators
15.7.1
15.7.2
15.7.3 Padding(fi 11, set fi 11)
15.7.4
15.7.5
15.7.6
15.7.7 Specifying Boolean Format(bool alpha)
15.7.8
Stream Error States
16Exception Handling:A Deeper Look
16.1Introduction
xivContents
16.2 Example:Handling an Attempt to Divide by Zero
16.3When to Use Exception Handling
16.4Re throwing an Exception
16.5Exception Specifications
16.6Processing Unexpected Exceptions
16.7Stack Unwinding
16.8Contruct ors, Deru ctors and Exception Handing
16.9 Exceptions and Inheritance
16.10 Processing new Failures
16.11 Class unique_ptr and Dynamic Memory Allocation
16.12 Standard Library Exception Hierarchy
16.13Wrap-Up
17File Processing
17.1Introduction
17.2Files and Streams
17.3Creating a Sequential File
17.4Reading Data from a Sequential File
17.5Updating Sequential Files
17.6Random-Access Files
17.7Creating a Random-Access File
17.8 Writing Data Randomly to a Random-Access File
17.9 Reading from a Random-Access File Sequen i ally
17.10 Case Study:A Transaction-Processing Program
17.11 Object Serialization
17.12Wrap-Up
18.9 Inserting Characters into a string
18.10 Conversion to C-Style Pointer-Based char*Strings
18.11 Iterators
Character Output Using Member Function put
get and get line Member Functions
istream Member Functions peek.put back and ignore
Integral Stream Base:dec, oct, hex and set base
Floating-Point Precision{precision, setprecision)
User-De in ed OutputStream Manipulators
Trailing Zeros and Decimal Points(show point)
Justification(Teft, right and interna 7)
Integral Stream Base(dec, oct, hex, show base)
Floating-Point Numbers; Scientific and Fixed
Notation(scientific, fixed)
Uppercase/Lowercase Conc rol(uppercase)
Setting and Resetting the Format State via
Member Function flags
Class string and StringStream Processing
Introduction
string Assignment and Concatenation
Comparing strings
Substrings
Swapping strings
string Characteristics
Finding Substrings and Characters in a string
Replacing Characters in a string
18.12 StringStream Processing
18.13Wrap-Up
Searching and Sorting
19.1Introduction
19.2Searching Algorithms
E ficiency of Linear Search
19.2.2 Binary Search
Sorting Algorithms
19.3.1Effciency of Selection Sort
19.3.2Efficiency of Insertion Sort
22.5.1vector Sequence Container
22.5.21ist Sequence Container
22.5.3deque Sequence Container
22.6.1 multiset Associative Container
22.62set Associative Container
22.6.3mu1timap Associative Container
22.6.4map Associative Container
22.7.1 stack Adapter
22.7.2queue Adapter
22.7.3 priority_queue Adapter
22.8.1
22.8.2
19.3.3 MergeSort(A Recursive Implementation)
Wrap-Up
20Custom Temp lat ized DataStructures
20.1Introduction
20.2Self-Referential Classes
20.3Dynamic Memory Allocation and DataStructures
20.4Linked Lists
20.5Stacks
20.6Qu cues
20.7Trees
20.8Wrap-Up
21Bits, Characters, C Strings and structs
21.1Introduction
21.2Structure Definitions
21.3typedef
21.4Example:CardS huflngandDealigSimuation
21.5Bitwise Operators
21.6 BitFields
21.7Character-Handling Library
21.8Pointer-Based Sting Manipulation Functions
21.9 Pointer-Based String-Conversion Functions
21.10 Search Functions of the Pointer-Based String-Handling Library
21.11 Memory Functions of the Pointer-Based String-Handling Library
21.12Wrap-Up
xviContents
22
Standard Template Library(STL)850
22.1Introduction to the Standard Template Library(STL)851
22.2Introduction to Containers853
22.3Introduction to Iterators856
22.4Introduction to Algorithms861
22.5Sequence Conca in ers863
22.6Associative Containers877
22.7Container Adapters885
22.8Algorithms890
22.9 Class bitset920
22.10 Function Objects924
22.11Wrap-Up927
fi 11, fil 1_n, generate and generate_n
equal, mismatch and 1exico graphical_compare
22.8.3 remove, remove_if.remove_copy and remove_copy_if
22.8.4replace, replace_if, replace_copy and replace_copy_if
22.8.5Mathematical Algorithms900
22.8.6 Basic Searching and Sorting Algor thms903
22.8.7swap, iter_swap and swap_ranges905
22.8.8copy_backward, merge, unique and reverse906
22.8.9inp1ace_merge, unique_copy and reverse_copy909
22.8.10Ser Operations910
22.8.111ower_bound, upper_bound and equal_range913
22.8.12 Heapsort915
22.8.13minandmax918
22.8.14STL Algorithms Nor Covered in This Chapter919
23Boost Libraries, Technical Report land C++0x 936
23.1Introduction937
Deitel Online C++and Related Resource Centers
Boost Libraries
Boost Libraries Overview
23.5.1 RegularExpression Example
23.5.2
23.5.3 Replacing and Splitting Strings
23.6.1 Reference Counted shared_ptr
23.6.2weak_ptr; shared_ptr Observer
Object-Oriented Design with the UML
23.5 Regular Expressions with the regex Library
23.6Smart Pointers
23.7Technical Report 1
23.8C++0x
23.9Core Language Changes
23.10Wrap-Up
24Other Topics
24.1Introduction
24.2const_cast Operator
24.3mu table Class Members
24.4namespaces
24.5Operator Keywords
24.6Pointers to Class Members(.*and->*)
24.7Multiple Inheritance
24.8Multiple Inheritance and virtual Base Classes
24.9Wrap-Up
Chapters on the Web
Validating UserInput with Regular Expressions
AOperator Precedence and Associativity
BASCII Character Set
CFundamental Types
DNumber Systems
D.1Introduction
xvi liContents
Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
Converting Octal and Hexadecimal Numbers to Binary Numbers
D4Converting from Binary, Octal or Hexadecimal to Decimal
D.5Converting from Decimal to Binary, Octal or Hexa