找传奇、传世资源到传世资源站!

c how to program pdf 电子书第8版

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

c how to program 电子书,第8版,c语言相关的英文电子书。
c how to program pdf 电子书第8版 C/C++语言基础-第1张 c how to program pdf 电子书第8版 C/C++语言基础-第2张c how to program pdf 电子书第8版 C/C++语言基础-第3张c how to program pdf 电子书第8版 C/C++语言基础-第4张c how to program pdf 电子书第8版 C/C++语言基础-第5张c how to program pdf 电子书第8版 C/C++语言基础-第6张c how to program pdf 电子书第8版 C/C++语言基础-第7张c how to program pdf 电子书第8版 C/C++语言基础-第8张c how to program pdf 电子书第8版 C/C++语言基础-第9张c how to program pdf 电子书第8版 C/C++语言基础-第10张c how to program pdf 电子书第8版 C/C++语言基础-第11张c how to program pdf 电子书第8版 C/C++语言基础-第12张c how to program pdf 电子书第8版 C/C++语言基础-第13张c how to program pdf 电子书第8版 C/C++语言基础-第14张c how to program pdf 电子书第8版 C/C++语言基础-第15张c how to program pdf 电子书第8版 C/C++语言基础-第16张c how to program pdf 电子书第8版 C/C++语言基础-第17张c how to program pdf 电子书第8版 C/C++语言基础-第18张c how to program pdf 电子书第8版 C/C++语言基础-第19张c how to program pdf 电子书第8版 C/C++语言基础-第20张c how to program pdf 电子书第8版 C/C++语言基础-第21张c how to program pdf 电子书第8版 C/C++语言基础-第22张c how to program pdf 电子书第8版 C/C++语言基础-第23张c how to program pdf 电子书第8版 C/C++语言基础-第24张c how to program pdf 电子书第8版 C/C++语言基础-第25张c how to program pdf 电子书第8版 C/C++语言基础-第26张c how to program pdf 电子书第8版 C/C++语言基础-第27张c how to program pdf 电子书第8版 C/C++语言基础-第28张c how to program pdf 电子书第8版 C/C++语言基础-第29张c how to program pdf 电子书第8版 C/C++语言基础-第30张c how to program pdf 电子书第8版 C/C++语言基础-第31张c how to program pdf 电子书第8版 C/C++语言基础-第32张c how to program pdf 电子书第8版 C/C++语言基础-第33张c how to program pdf 电子书第8版 C/C++语言基础-第34张c how to program pdf 电子书第8版 C/C++语言基础-第35张c how to program pdf 电子书第8版 C/C++语言基础-第36张c how to program pdf 电子书第8版 C/C++语言基础-第37张c how to program pdf 电子书第8版 C/C++语言基础-第38张c how to program pdf 电子书第8版 C/C++语言基础-第39张c how to program pdf 电子书第8版 C/C++语言基础-第40张c how to program pdf 电子书第8版 C/C++语言基础-第41张c how to program pdf 电子书第8版 C/C++语言基础-第42张c how to program pdf 电子书第8版 C/C++语言基础-第43张c how to program pdf 电子书第8版 C/C++语言基础-第44张c how to program pdf 电子书第8版 C/C++语言基础-第45张c how to program pdf 电子书第8版 C/C++语言基础-第46张c how to program pdf 电子书第8版 C/C++语言基础-第47张c how to program pdf 电子书第8版 C/C++语言基础-第48张c how to program pdf 电子书第8版 C/C++语言基础-第49张c how to program pdf 电子书第8版 C/C++语言基础-第50张c how to program pdf 电子书第8版 C/C++语言基础-第51张c how to program pdf 电子书第8版 C/C++语言基础-第52张c how to program pdf 电子书第8版 C/C++语言基础-第53张c how to program pdf 电子书第8版 C/C++语言基础-第54张c how to program pdf 电子书第8版 C/C++语言基础-第55张c how to program pdf 电子书第8版 C/C++语言基础-第56张c how to program pdf 电子书第8版 C/C++语言基础-第57张c how to program pdf 电子书第8版 C/C++语言基础-第58张c how to program pdf 电子书第8版 C/C++语言基础-第59张c how to program pdf 电子书第8版 C/C++语言基础-第60张c how to program pdf 电子书第8版 C/C++语言基础-第61张c how to program pdf 电子书第8版 C/C++语言基础-第62张c how to program pdf 电子书第8版 C/C++语言基础-第63张c how to program pdf 电子书第8版 C/C++语言基础-第64张c how to program pdf 电子书第8版 C/C++语言基础-第65张c how to program pdf 电子书第8版 C/C++语言基础-第66张c how to program pdf 电子书第8版 C/C++语言基础-第67张c how to program pdf 电子书第8版 C/C++语言基础-第68张c how to program pdf 电子书第8版 C/C++语言基础-第69张c how to program pdf 电子书第8版 C/C++语言基础-第70张c how to program pdf 电子书第8版 C/C++语言基础-第71张c how to program pdf 电子书第8版 C/C++语言基础-第72张c how to program pdf 电子书第8版 C/C++语言基础-第73张c how to program pdf 电子书第8版 C/C++语言基础-第74张c how to program pdf 电子书第8版 C/C++语言基础-第75张c how to program pdf 电子书第8版 C/C++语言基础-第76张c how to program pdf 电子书第8版 C/C++语言基础-第77张c how to program pdf 电子书第8版 C/C++语言基础-第78张c how to program pdf 电子书第8版 C/C++语言基础-第79张c how to program pdf 电子书第8版 C/C++语言基础-第80张hello world!Contents
Appendices F, G and H are PDF documents posted online at
the book’s Companion Website (located at
www.pearsonhighered.com/deitel).
Preface
xxiii
1
Introduction to Computers, the Internet and
the Web
1
1.1
Introduction
2
1.2
Hardware and Software
3
1.2.1
Moore’s Law
3
1.2.2
Computer Organization
4
1.3
Data Hierarchy
5
1.4
Machine Languages, Assembly Languages and High-Level
Languages
8
1.5
The C Programming Language
9
1.6
C Standard Library
10
1.7
C and Other C-Based Languages
11
1.8
Object Technology
12
1.8.1
The Automobile as an Object
13
1.8.2
Methods and Classes
13
1.8.3
Instantiation
13
1.8.4
Reuse
13
1.8.5
Messages and Method Calls
14
1.8.6
Attributes and Instance Variables
14
1.8.7
Encapsulation and Information Hiding
14
1.8.8
Inheritance
14
1.9
Typical C Program-Development Environment
15
1.9.1
Phase 1: Creating a Program
16
1.9.2
Phases 2 and 3: Preprocessing and Compiling a C Program
16
1.9.3
Phase 4: Linking
16
1.9.4
Phase 5: Loading
17
1.9.5
Phase 6: Execution
17
1.9.6
Problems That May Occur at Execution Time
17
1.9.7
Standard Input, Standard Output and Standard Error Streams
17
1.10
Test-Driving a C Application in Windows, Linux and Mac OS X
17
1.10.1 Running a C Application from the Windows Command
Prompt
18
1.10.2 Running a C Application Using GNU C with Linux
21
viii
Contents
1.10.3 Running a C Application Using the Teminal on Mac OS X
24
1.11
Operating Systems
27
1.11.1 Windows—A Proprietary Operating System
27
1.11.2 Linux—An Open-Source Operating System
27
1.11.3 Apple’s Mac OS X; Apple’s iOS for iPhone®, iPad® and
iPod Touch® Devices
28
1.11.4 Google’s Android
28
1.12
The Internet and World Wide Web
29
1.12.1 The Internet: A Network of Networks
29
1.12.2 The World Wide Web: Making the Internet User-Friendly
29
1.12.3 Web Services
30
1.12.4 Ajax
32
1.12.5 The Internet of Things
32
1.13
Some Key Software Terminology
32
1.14
Keeping Up-to-Date with Information Technologies
34
2
Introduction to C Programming
39
2.1
Introduction
40
2.2
A Simple C Program: Printing a Line of Text
40
2.3
Another Simple C Program: Adding Two Integers
44
2.4
Memory Concepts
48
2.5
Arithmetic in C
49
2.6
Decision Making: Equality and Relational Operators
53
2.7
Secure C Programming
57
3 Structured Program Development in C
69
3.1
Introduction
70
3.2
Algorithms
70
3.3
Pseudocode
70
3.4
Control Structures
71
3.5
The if Selection Statement
73
3.6
The if…else Selection Statement
74
3.7
The while Iteration Statement
78
3.8
Formulating Algorithms Case Study 1: Counter-Controlled
Iteration
79
3.9
Formulating Algorithms with Top-Down, Stepwise Refinement
Case Study 2: Sentinel-Controlled Iteration
82
3.10
Formulating Algorithms with Top-Down, Stepwise Refinement
Case Study 3: Nested Control Statements
88
3.11
Assignment Operators
92
3.12
Increment and Decrement Operators
93
3.13
Secure C Programming
95
4
C Program Control
113
4.1
Introduction
114
Contents
ix
4.2
Iteration Essentials
114
4.3
Counter-Controlled Iteration
115
4.4
for Iteration Statement
116
4.5
for Statement: Notes and Observations
119
4.6
Examples Using the for Statement
120
4.7
switch Multiple-Selection Statement
123
4.8
do…while Iteration Statement
129
4.9
break and continue Statements
130
4.10
Logical Operators
132
4.11
Confusing Equality (==) and Assignment (=) Operators
135
4.12
Structured Programming Summary
137
4.13
Secure C Programming
142
5
C Functions
157
5.1
Introduction
158
5.2
Modularizing Programs in C
158
5.3
Math Library Functions
159
5.4
Functions
161
5.5
Function Definitions
161
5.5.1
square Function
162
5.5.2
maximum Function
165
5.6
Function Prototypes: A Deeper Look
166
5.7
Function Call Stack and Stack Frames
168
5.8
Headers
172
5.9
Passing Arguments By Value and By Reference
173
5.10
Random Number Generation
174
5.11
Example: A Game of Chance; Introducing enum
178
5.12
Storage Classes
182
5.13
Scope Rules
184
5.14
Recursion
187
5.15
Example Using Recursion: Fibonacci Series
190
5.16
Recursion vs. Iteration
194
5.17
Secure C Programming
195
6
C Arrays
214
6.1
Introduction
215
6.2
Arrays
215
6.3
Defining Arrays
217
6.4
Array Examples
217
6.4.1
Defining an Array and Using a Loop to Set the Array’s
Element Values
217
6.4.2
Initializing an Array in a Definition with an Initializer
List
218
6.4.3
Specifying an Array’s Size with a Symbolic Constant and
Initializing Array Elements with Calculations
220
x
Contents
6.4.4
Summing the Elements of an Array
221
6.4.5
Using Arrays to Summarize Survey Results
222
6.4.6
Graphing Array Element Values with Histograms
224
6.4.7
Rolling a Die 60,000,000 Times and Summarizing the Results
in an Array
225
6.5
Using Character Arrays to Store and Manipulate Strings
225
6.5.1
Initializing a Character Array with a String
226
6.5.2
Initializing a Character Array with an Intializer List of
Characters 226
6.5.3
Accessing the Characters in a String
226
6.5.4
Inputting into a Character Array
226
6.5.5
Outputting a Character Array That Represents a String
227
6.5.6
Demonstrating Character Arrays
227
6.6
Static Local Arrays and Automatic Local Arrays
228
6.7
Passing Arrays to Functions
230
6.8
Sorting Arrays
234
6.9
Case Study: Computing Mean, Median and Mode Using Arrays
236
6.10
Searching Arrays
241
6.10.1 Searching an Array with Linear Search
241
6.10.2 Searching an Array with Binary Search
242
6.11
Multidimensional Arrays
246
6.11.1 Illustrating a Double-Subcripted Array
246
6.11.2 Initializing a Double-Subcripted Array
247
6.11.3 Setting the Elements in One Row
249
6.11.4 Totaling the Elements in a Two-Dimensional Array
249
6.11.5 Two-Dimensonal Array Manipulations
250
6.12
Variable-Length Arrays
253
6.13
Secure C Programming
256
7
C Pointers
274
7.1
Introduction
275
7.2
Pointer Variable Definitions and Initialization
276
7.3
Pointer Operators
277
7.4
Passing Arguments to Functions by Reference
279
7.5
Using the const Qualifier with Pointers
283
7.5.1
Converting a String to Uppercase Using a Non-Constant Pointer
to Non-Constant Data
284
7.5.2
Printing a String One Character at a Time Using a Non-
Constant
Pointer to Constant Data
285
7.5.3
Attempting to Modify a Constant Pointer to Non-Constant Data
287
7.5.4
Attempting to Modify a Constant Pointer to Constant Data
288
7.6
Bubble Sort Using Pass-by-Reference
289
7.7
sizeof Operator
292
7.8
Pointer Expressions and Pointer Arithmetic
295
7.8.1
Allowed Operators for Pointer Arithmetic
295
7.8.2
Aiming a Pointer at an Array
295
Contents
xi
7.8.3
Adding an Integer to a Pointer
296
7.8.4
Subtracting an Integer from a Pointer
296
7.8.5
Incrementing and Decrementing a Pointer
296
7.8.6
Subtracting One Pointer from Another
297
7.8.7
Assigning Pointers to One Another
297
7.8.8
Pointer to void
297
7.8.9
Comparing Pointers
297
7.9
Relationship between Pointers and Arrays
298
7.9.1
Pointer/Offset Notation
298
7.9.2
Pointer/Index Notation
299
7.9.3
Cannot Modify an Array Name with Pointer Arithmetic
299
7.9.4
Demonstrating Pointer Indexing and Offsets
299
7.9.5
String Copying with Arrays and Pointers
300
7.10
Arrays of Pointers
302
7.11
Case Study: Card Shuffling and Dealing Simulation
303
7.12
Pointers to Functions
308
7.12.1 Sorting in Ascending or Descending Order
308
7.12.2 Using Function Pointers to Create a Menu-Driven System
311
7.13
Secure C Programming
313
8
C Characters and Strings
333
8.1
Introduction
334
8.2
Fundamentals of Strings and Characters
334
8.3
Character-Handling Library
336
8.3.1
Functions isdigit, isalpha, isalnum and isxdigit
336
8.3.2
Functions islower, isupper, tolower and toupper
339
8.3.3
Functions isspace, iscntrl, ispunct, isprint and isgraph
340
8.4
String-Conversion Functions
342
8.4.1
Function strtod
342
8.4.2
Function strtol
343
8.4.3
Function strtoul
344
8.5
Standard Input/Output Library Functions
344
8.5.1
Functions fgets and putchar
345
8.5.2
Function getchar
346
8.5.3
Function sprintf
347
8.5.4
Function sscanf
348
8.6
String-Manipulation Functions of the String-Handling Library
349
8.6.1
Functions strcpy and strncpy
350
8.6.2
Functions strcat and strncat
350
8.7
Comparison Functions of the String-Handling Library
351
8.8
Search Functions of the String-Handling Library
353
8.8.1
Function strchr
354
8.8.2
Function strcspn
355
8.8.3
Function strpbrk
355
8.8.4
Function strrchr
356
xii
Contents
8.8.5
Function strspn
357
8.8.6
Function strstr
357
8.8.7
Function strtok
358
8.9
Memory Functions of the String-Handling Library
359
8.9.1
Function memcpy
360
8.9.2
Function memmove
361
8.9.3
Function memcmp
362
8.9.4
Function memchr
362
8.9.5
Function memset
363
8.10
Other Functions of the String-Handling Library
363
8.10.1 Function strerror
364
8.10.2 Function strlen
364
8.11
Secure C Programming
365
9 C Formatted Input/Output
377
9.1
Introduction
378
9.2
Streams
378
9.3
Formatting Output with printf
378
9.4
Printing Integers
379
9.5
Printing Floating-Point Numbers
380
9.5.1
Conversion Specifiers e, E and f
381
9.5.2
Conversion Specifiers g and G
381
9.5.3
Demonstrating Floating-Point Conversion Specifiers
382
9.6
Printing Strings and Characters
382
9.7
Other Conversion Specifiers
383
9.8
Printing with Field Widths and Precision
384
9.8.1
Specifying Field Widths for Printing Integers
384
9.8.2
Specifying Precisions for Integers, Floating-Point Numbers
and Strings
385
9.8.3
Combining Field Widths and Precisions
386
9.9
Using Flags in the printf Format Control String
387
9.9.1
Right and Left Justification
387
9.9.2
Printing Positive and Negative Numbers with and without
the Flag
388
9.9.3
Using the Space Flag
388
9.9.4
Using the # Flag
389
9.9.5
Using the 0 Flag
389
9.10
Printing Literals and Escape Sequences
390
9.11
Reading Formatted Input with scanf
390
9.11.1 scanf Syntax
391
9.11.2 scanf Conversion Specifiers
391
9.11.3 Reading Integers with scanf
392
9.11.4 Reading Floating-Point Numbers with scanf
393
9.11.5 Reading Characters and Strings with scanf
393
9.11.6 Using Scan Sets with scanf
394
Contents
xiii
9.11.7 Using Field Widths with scanf
395
9.11.8 Skipping Characters in an Input Stream
396
9.12
Secure C Programming
397
10 C Structures, Unions, Bit Manipulation and
Enumerations
404
10.1
Introduction
405
10.2
Structure Definitions
405
10.2.1 Self-Referential Structures
406
10.2.2 Defining Variables of Structure Types
407
10.2.3 Structure Tag Names
407
10.2.4 Operations That Can Be Performed on Structures
407
10.3
Initializing Structures
408
10.4
Accessing Structure Members with . and ->
408
10.5
Using Structures with Functions
410
10.6
typedef
411
10.7
Example: High-Performance Card Shuffling and Dealing
Simulation
411
10.8
Unions
414
10.8.1 Union Declarations
414
10.8.2 Operations That Can Be Performed on Unions
415
10.8.3 Initializing Unions in Declarations
415
10.8.4 Demonstrating Unions
415
10.9
Bitwise Operators
416
10.9.1 Displaying an Unsigned Integer in Bits
417
10.9.2 Making Function displayBits More Generic and Portable
419
10.9.3 Using the Bitwise AND, Inclusive OR, Exclusive OR and
Complement Operators
420
10.9.4 Using the Bitwise Left- and Right-Shift Operators
423
10.9.5 Bitwise Assignment Operators
424
10.10 Bit Fields
425
10.10.1 Defining Bit Fields
425
10.10.2 Using Bit Fields to Represent a Card’s Face, Suit
and Color
426
10.10.3 Unnamed Bit Fields
428
10.11 Enumeration Constants
428
10.12 Anonymous Structures and Unions
430
10.13 Secure C Programming
430
11 C File Processing
441
11.1
Introduction
442
11.2
Files and Streams
442
11.3
Creating a Sequential-Access File
443
11.3.1 Pointer to a FILE
445
11.3.2 Using fopen to Open the File
445
11.3.3 Using feof to Check for the End-of-File Indicator
445
xiv
Contents
11.3.4 Using fprintf to Write to the File
446
11.3.5 Using fclose to Close the File
446
11.3.6 File Open Modes
447
11.4
Reading Data from a Sequential-Access File
449
11.4.1 Resetting the File Position Pointer
450
11.4.2 Credit Inquiry Program
450
11.5
Random-Access Files
454
11.6
Creating a Random-Access File
454
11.7
Writing Data Randomly to a Random-Access File
456
11.7.1 Positioning the File Position Pointer with fseek
458
11.7.2 Error Checking
459
11.8
Reading Data from a Random-Access File
459
11.9
Case Study: Transaction-Processing Program
461
11.10 Secure C Programming
466
12 C Data Structures
477
12.1
Introduction
478
12.2
Self-Referential Structures
479
12.3
Dynamic Memory Allocation
479
12.4
Linked Lists
480
12.4.1 Function insert
486
12.4.2 Function delete
487
12.4.3 Function printList
489
12.5
Stacks
489
12.5.1 Function push
493
12.5.2 Function pop
494
12.5.3 Applications of Stacks
494
12.6
Queues
495
12.6.1 Function enqueue
499
12.6.2 Function dequeue
500
12.7
Trees
501
12.7.1 Function insertNode
504
12.7.2 Traversals: Functions inOrder, preOrder and postOrder
505
12.7.3 Duplicate Elimination
506
12.7.4 Binary Tree Search
506
12.7.5 Other Binary Tree Operations
506
12.8
Secure C Programming
506
13 C Preprocessor
518
13.1
Introduction
519
13.2
#include Preprocessor Directive
519
13.3
#define Preprocessor Directive: Symbolic Constants
520
13.4
#define Preprocessor Directive: Macros
521
13.4.1 Macro with One Argument
521
Contents
xv
13.4.2 Macro with Two Arguments
522
13.4.3 Macro Continuation Character
522
13.4.4 #undef Preprocessor Directive
522
13.4.5 Standard Library Functions and Macros
522
13.4.6 Do Not Place Expressions with Side Effects in Macros
523
13.5
Conditional Compilation
523
13.5.1 #if…#endif Preprocessor Directive
523
13.5.2 Commenting Out Blocks of Code with #if…#endif
523
13.5.3 Conditionally Compiling Debugging Code
524
13.6
#error and #pragma Preprocessor Directives
524
13.7
# and ## Operators
524
13.8
Line Numbers
525
13.9
Predefined Symbolic Constants
525
13.10 Assertions
526
13.11 Secure C Programming
526
14 Other C Topics
531
14.1
Introduction
532
14.2
Redirecting I/O
532
14.2.1 Redirecting Input with <
532
14.2.2 Redirecting Input with |
533
14.2.3 Redirecting Output
533
14.3
Variable-Length Argument Lists
533
14.4
Using Command-Line Arguments
535
14.5
Compiling Multiple-Source-File Programs
537
14.5.1 extern Declarations for Global Variables in Other
Files
537
14.5.2 Function Prototypes
537
14.5.3 Restricting Scope with static
538
14.5.4 Makefiles
538
14.6
Program Termination with exit and atexit
538
14.7
Suffixes for Integer and Floating-Point Literals
540
14.8
Signal Handling
540
14.9
Dynamic Memory Allocation: Functions calloc and realloc
543
14.10 Unconditional Branching with goto
543
15 C as a Better C; Introducing Object
Technology
549
15.1
Introduction
550
15.2
C
550
15.3
A Simple Program: Adding Two Integers
551
15.3.1 Addition Program in C
551
15.3.2 <iostream> Header
552
15.3.3 main Function
552
15.3.4 Variable Declarations
552
xvi
Contents
15.3.5 Standard Output Stream and Standard Input Stream
Objects
552
15.3.6 std::endl Stream Manipulator
553
15.3.7 std:: Explained
553
15.3.8 Concatenated Stream Outputs
553
15.3.9 return Statement Not Required in main
553
15.3.10 Operator Overloading
553
15.4
C Standard Library
554
15.5
Header Files
554
15.6
Inline Functions
556
15.7
C Keywords
558
15.8
References and Reference Parameters
559
15.8.1 Reference Parameters
559
15.8.2 Passing Arguments by Value and by Reference
560
15.8.3 References as Aliases within a Function
562
15.8.4 Returning a Reference from a Function
563
15.8.5 Error Messages for Uninitialized References
564
15.9
Empty Parameter Lists
564
15.10 Default Arguments
564
15.11 Unary Scope Resolution Operator
566
15.12 Function Overloading
567
15.13 Function Templates
570
15.13.1 Defining a Function Template
570
15.13.2 Using a Function Template
571
15.14 Introduction to Object Technology and the UML
573
15.14.1 Basic Object Technology Concepts
573
15.14.2 Classes, Data Members and Member Functions
574
15.14.3 Object-Oriented Analysis and Design
575
15.14.4 The Unified Modeling Language
576
15.15 Introduction to C Standard Library Class Template
vector
576
15.15.1 Problems Associated with C-Style Pointer-Based Arrays
576
15.15.2 Using Class Template vector
577
15.15.3 Exception Handling: Processing an Out-of-Range Index
581
15.16 Wrap-Up
583
16 Introduction to Classes, Objects and Strings
589
16.1
Introduction
590
16.2
Defining a Class with a Member Function
590
16.3
Defining a Member Function with a Parameter
593
16.4
Data Members, set Member Functions and get Member Functions
597
16.5
Initializing Objects with Constructors
602
16.6
Placing a Class in a Separate File for Reusability
606
16.7
Separating Interface from Implementation
610
16.8
Validating Data with set Functions
615
16.9
Wrap-Up
620
Contents
xvii
17 Classes: A Deeper Look; Throwing Exceptions 627
17.1
Introduction
628
17.2
Time Class Case Study
629
17.3
Class Scope and Accessing Class Members
635
17.4
Access Functions and Utility Functions
636
17.5
Time Class Case Study: Constructors with Default Arguments
637
17.6
Destructors
643
17.7
When Constructors and Destructors Are Called
643
17.8
Time Class Case Study: A Subtle Trap—Returning a Reference
or a
Pointer to a private Data Member
647
17.9
Default Memberwise Assignment
650
17.10 const Objects and const Member Functions
652
17.11 Composition: Objects as Members of Classes
654
17.12 friend Functions and friend Classes
660
17.13 Using the this Pointer
662
17.14 static Class Members
668
17.15 Wrap-Up
673
18 Operator Overloading; Class string
683
18.1
Introduction
684
18.2
Using the Overloaded Operators of Standard Library Class
string
685
18.3
Fundamentals of Operator Overloading
688
18.4
Overloading Binary Operators
689
18.5
Overloading the Binary Stream Insertion and Stream Extraction
Operators 690
18.6
Overloading Unary Operators
694
18.7
Overloading the Unary Prefix and Postfix and -- Operators
695
18.8
Case Study: A Date Class
696
18.9
Dynamic Memory Management
701
18.10 Case Study: Array Class
703
18.10.1 Using the Array Class
704
18.10.2 Array Class Definition
708
18.11 Operators as Member vs. Non-Member Functions
716
18.12 Converting Between Types
716
18.13 explicit Constructors and Conversion Operators
718
18.14 Overloading the Function Call Operator ()
720
18.15 Wrap-Up
721
19 Object-Oriented Programming: Inheritance 732
19.1
Introduction
733
19.2
Base Classes and Derived Classes
733
19.3
Relationship between Base and Derived Classes
736
19.3.1 Creating and Using a CommissionEmployee Class
736
19.3.2 Creating a BasePlusCommissionEmployee Class Without
Using Inheritance
741
xviii
Contents
19.3.3 Creating a CommissionEmployee–
BasePlusCommissionEmployee
Inheritance Hierarchy
747
19.3.4 CommissionEmployee–BasePlusCommissionEmployee
Inheritance
Hierarchy Using protected Data
751
19.3.5 CommissionEmployee–BasePlusCommissionEmployee
Inheritance
Hierarchy Using private Data
754
19.4
Constructors and Destructors in Derived Classes
759
19.5
public, protected and private Inheritance
761
19.6
Software Engineering with Inheritance
762
19.7
Wrap-Up
762
20 Object-Oriented Programming: Polymorphism 767
20.1
Introduction
768
20.2
Introduction to Polymorphism: Polymorphic Video Game
769
20.3
Relationships Among Objects in an Inheritance Hierarchy
769
20.3.1 Invoking Base-Class Functions from Derived-Class
Objects
770
20.3.2 Aiming Derived-Class Pointers at Base-Class Objects
773
20.3.3 Derived-Class Member-Function Calls via Base-Class
Pointers
774
20.3.4 Virtual Functions and Virtual Destructors
776
20.4
Type Fields and switch Statements
783
20.5
Abstract Classes and Pure virtual Functions
783
20.6
Case Study: Payroll System Using Polymorphism
785
20.6.1 Creating Abstract Base Class Employee
786
20.6.2 Creating Concrete Derived Class SalariedEmployee
790
20.6.3 Creating Concrete Derived Class CommissionEmployee
792
20.6.4 Creating Indirect Concrete Derived Class
BasePlusCommissionEmployee
794
20.6.5 Demonstrating Polymorphic Processing
796
20.7
(Optional) Polymorphism, Virtual Functions and Dynamic
Binding
“Under the Hood”
800
20.8
Case Study: Payroll System Using Polymorphism and Runtime
Type
Information with Downcasting, dynamic_cast, typeid and
type_info
803
20.9
Wrap-Up
807
21 Stream Input/Output: A Deeper Look
812
21.1
Introduction
813
21.2
Streams
814
21.2.1 Classic Streams vs. Standard Streams
814
21.2.2 iostream Library Headers
815
21.2.3 Stream Input/Output Classes and Objects
815
21.3
Stream Output
817
21.3.1 Output of char * Variables
818
21.3.2 Character Output Using Member Function put
818
21.4
Stream Input
819
21.4.1 get and getline Member Functions
819
Contents
xix
21.4.2 istream Member Functions peek, putback and ignore
822
21.4.3 Type-Safe I/O
822
21.5
Unformatted I/O Using read, write and gcount
822
21.6
Introduction to Stream Manipulators
823
21.6.1 Integral Stream Base: dec, oct, hex and setbase
824
21.6.2 Floating-Point Precision (precision, setprecision)
824
21.6.3 Field Width (width, setw)
826
21.6.4 User-Defined Output Stream Manipulators
827
21.7
Stream Format States and Stream Manipulators
828
21.7.1 Trailing Zeros and Decimal Points (showpoint)
829
21.7.2 Justification (left, right and internal)
830
21.7.3 Padding (fill, setfill)
832
21.7.4 Integral Stream Base (dec, oct, hex, showbase)
833
21.7.5 Floating-Point Numbers; Scientific and Fixed Notation
(scientific, fixed)
834
21.7.6 Uppercase/Lowercase Control (uppercase)
835
21.7.7 Specifying Boolean Format (boolalpha)
835
21.7.8 Setting and Resetting the Format State via Member F
unction flags
836
21.8
Stream Error States
837
21.9
Tying an Output Stream to an Input Stream
840
21.10 Wrap-Up
840
22 Exception Handling: A Deeper Look
849
22.1
Introduction
850
22.2
Example: Handling an Attempt to Divide by Zero
850
22.3
Rethrowing an Exception
856
22.4
Stack Unwinding
857
22.5
When to Use Exception Handling
859
22.6
Constructors, Destructors and Exception Handling
860
22.7
Exceptions and Inheritance
861
22.8
Processing new Failures
861
22.9
Class unique_ptr and Dynamic Memory Allocation
864
22.10 Standard Library Exception Hierarchy
867
22.11 Wrap-Up
868
23 Introduction to Custom Templates
874
23.1
Introduction
875
23.2
Class Templates
875
23.3
Function Template to Manipulate a Class-Template
Specialization Object 880
23.4
Nontype Parameters
882
23.5
Default Arguments for Template Type Parameters
882
23.6
Overloading Function Templates
883
23.7
Wrap-Up
883
xx
Contents
A C and C Operator Precedence Charts
886
B
ASCII Character Set
890
C Number Systems
891
C.1
Introduction
892
C.2
Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
895
C.3
Converting Octal and Hexadecimal Numbers to Binary Numbers
896
C.4
Converting from Binary, Octal or Hexadecimal to Decimal
896
C.5
Converting from Decimal to Binary, Octal or Hexadecimal
897
C.6
Negative Binary Numbers: Two’s Complement Notation
899
D Sorting: A Deeper Look
904
D.1
Introduction
905
D.2
Big O Notation
905
D.3
Selection Sort
906
D.4
Insertion Sort
910
D.5
Merge Sort
913
E
Multithreading and Other C11 and C99 Topics 924
E.1
Introduction
925
E.2
New C99 Headers
926
E.3
Designated Initializers and Compound Literals
927
E.4
Type bool
929
E.5
Implicit int in Function Declarations
931
E.6
Complex Numbers
932
E.7
Additions to the Preprocessor
933
E.8
Other C99 Features
934
E.8.1
Compiler Minimum Resource Limits
934
E.8.2
The restrict Keyword
935
E.8.3
Reliable Integer Division
935
E.8.4
Flexible Array Members
935
E.8.5
Relaxed Constraints on Aggregate Initialization
936
E.8.6
Type Generic Math
936
E.8.7
Inline Functions
936
E.8.8
Return Without Expression
937
E.8.9
__func__ Predefined Identifier
937
E.8.10 va_copy Macro
937
E.9
New Features in the C11 Standard
937
E.9.1
New C11 Headers
938
E.9.2
Multithreading Support
938
Contents
xxi
E.9.3
quick_exit function
946
E.9.4
Unicode® Support
946
E.9.5
_Noreturn Function Specifier
946
E.9.6
Type-Generic Expressions
946
E.9.7
Annex L: Analyzability and Undefined Behavior
947
E.9.8
Memory Alignment Control
947
E.9.9
Static Assertions
947
E.9.10 Floating-Point Types
948
E.10
Web Resources
948
Appendices on the Web
951
Index

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复