Paul Deitel和Harvey Deitel是全球畅销的编程语言教材和专业图书作家,How to Program系列是其最负盛名的一套计算机编程教材,已经销售近40年,并被翻译成中文在内的十几种语言。他们成立的Deitel & Associates公司是一家国际知名的企业培训和写作公司,专门进行计算机编程语言、对象技术、移动应用开发及Internet和Web软件技术方面的培训和写作,出版了一流的编程专业的大学教材、 专业图书以及LiveLessons视频课程。
Paul Deitel和Harvey Deitel是全球畅销的编程语言教材和专业图书作家,How to Program系列是其最负盛名的一套计算机编程教材,已经销售近40年,并被翻译成中文在内的十几种语言。他们成立的Deitel & Associates公司是一家国际知名的企业培训和写作公司,专门进行计算机编程语言、对象技术、移动应用开发及Internet和Web软件技术方面的培训和写作,出版了一流的编程专业的大学教材、 专业图书以及LiveLessons视频课程。
目錄:
Contents
Chapter 1Introduction to Computers and C1
1.1Introduction2
1.2Computers and the Internet in Industry and Research2
1.3Hardware and Software4
1.4Data Hierarchy6
1.5Machine Languages, Assembly Languages and High-Level Languages7
1.6C8
1.7Programming Languages9
1.8Introduction to Object Technology10
1.9Typical C Development Environment13
1.10Test-Driving a C Application15
1.11Operating Systems20
1.12The Internet and World Wide Web22
1.13Some Key Software Development Terminology23
1.14C11 and the Open Source Boost Libraries25
1.15Keeping Up to Date with Information Technologies25
1.16Web Resources26
Chapter 2Introduction to C Programming; InputOutput and Operators31
2.1Introduction31
2.2First Program in C: Printing a Line of Text32
2.3Modifying Our First C Program35
2.4Another C Program: Adding Integers36
2.5Memory Concepts39
2.6Arithmetic40
2.7Decision Making: Equality and Relational Operators43
2.8Wrap-Up47
Chapter 3Introduction to Classes, Objects and Strings55
3.1Introduction55
3.2Defining a Class with a Member Function56
3.3Defining a Member Function with a Parameter58
3.4Data Members, set Member Functions and get Member Functions61
3.5Initializing Objects with Constructors66
3.6Placing a Class in a Separate File for Reusability69
3.7Separating Interface from Implementation72
3.8Validating Data with set Functions76
3.9Wrap-Up80
Chapter 4Control Statements: Part 1; Assignment,and - - Operators87
4.1Introduction87
4.2Algorithms88
4.3Pseudocode88
4.4Control Structures89
4.5if Selection Statement92
4.6ifelse Double-Selection Statement93
4.7while Repetition Statement97
4.8Formulating Algorithms: Counter-Controlled Repetition98
4.9Formulating Algorithms: Sentinel-Controlled Repetition103
4.10Formulating Algorithms: Nested Control Statements111
4.11Assignment Operators116
4.12Increment and Decrement Operators116
4.13Wrap-Up118
Chapter 5Control Statements: Part 2; Logical Operators131
5.1Introduction131
5.2Essentials of Counter-Controlled Repetition132
5.3for Repetition Statement133
5.4Examples Using the for Statement136
5.5dowhile Repetition Statement140
5.6switch Multiple-Selection Statement141
5.7break and continue Statements148
5.8Logical Operators150
5.9Confusing the Equality == and Assignment = Operators153
5.10Structured Programming Summary154
5.11Wrap-Up158
Chapter 6Functions and an Introduction to Recursion167
6.1Introduction168
6.2Program Components in C168
6.3Math Library Functions169
6.4Function Definitions with Multiple Parameters170
6.5Function Prototypes and Argument Coercion174
6.6C Standard Library Headers176
6.7Case Study: Random Number Generation177
6.8Case Study: Game of Chance; Introducing enum182
6.9C11 Random Numbers185
6.10Storage Classes and Storage Duration186
6.11Scope Rules189
6.12Function Call Stack and Activation Records191
6.13Functions with Empty Parameter Lists194
6.14Inline Functions195
6.15References and Reference Parameters196
6.16Default Arguments198
6.17Unary Scope Resolution Operator200
6.18Function Overloading200
6.19Function Templates203
6.20Recursion205
6.21Example Using Recursion: Fibonacci Series208
6.22Recursion vs. Iteration210
6.23Wrap-Up213
Chapter 7Class Templates array and vector; Catching Exceptions232
7.1Introduction233
7.2arrays233
7.3Declaring arrays234
7.4Examples Using arrays235
7.5Range-Based for Statement244
7.6Case Study: Class GradeBook Using an array to Store Grades246
7.7Sorting and Searching arrays251
7.8Multidimensional arrays252
7.9Case Study: Class GradeBook Using a Two-Dimensional array255
7.10Introduction to C Standard Library Class Template vector260
7.11Wrap-Up264
Chapter 8Pointers279
8.1Introduction280
8.2Pointer Variable Declarations and Initialization280
8.3Pointer Operators281
8.4Pass-by-Reference with Pointers283
8.5Built-In Arrays287
8.6Using const with Pointers289
8.7sizeof Operator292
8.8Pointer Expressions and Pointer Arithmetic294
8.9Relationship Between Pointers and Built-In Arrays296
8.10Pointer-Based Strings299
8.11Wrap-Up301
Chapter 9Classes: A Deeper Look; Throwing Exceptions316
9.1Introduction317
9.2Time Class Case Study317
9.3Class Scope and Accessing Class Members323
9.4Access Functions and Utility Functions324
9.5Time Class Case Study: Constructors with Default Arguments324
9.6Destructors328
9.7When Constructors and Destructors Are Called329
9.8Time Class Case Study: A Subtle Trap Returning a Reference or a Pointer to a private
Data Member331
9.9Default Memberwise Assignment334
9.10const Objects and const Member Functions335
9.11Composition: Objects as Members of Classes337
9.12friend Functions and friend Classes341
9.13Using the this Pointer343
9.14static Class Members347
9.15Wrap-Up351
Chapter 10Operator Overloading; Class string361
10.1Introduction362
10.2Using the Overloaded Operators of Standard Library Class string362
10.3Fundamentals of Operator Overloading365
10.4Overloading Binary Operators366
10.5Overloading the Binary Stream Insertion and Stream Extraction Operators367
10.6Overloading Unary Operators370
10.7Overloading the Unary Prefix and Postfixand -- Operators370
10.8Case Study: A Date Class371
10.9Dynamic Memory Management375
10.10Case Study: Array Class377
10.11Operators as Member vs. Non-Member Functions387
10.12Converting Between Types388
10.13explicit Constructors and Conversion Operators389
10.14Overloading the Function Call Operator 391
10.15Wrap-Up392
Chapter 11Object-Oriented Programming: Inheritance402
11.1Introduction402
11.2Base Classes and Derived Classes403
11.3Relationship between Base and Derived Classes405
11.4Constructors and Destructors in Derived Classes422
11.5public, protected and private Inheritance424
11.6Software Engineering with Inheritance425
11.7Wrap-Up425
Chapter 12Object-Oriented Programming: Polymorphism431
12.1Introduction432
12.2Introduction to Polymorphism: Polymorphic Video Game432
12.3Relationships Among Objects in an Inheritance Hierarchy433
12.4Type Fields and switch Statements443
12.5Abstract Classes and Pure virtual Functions444
12.6Case Study: Payroll System Using Polymorphism445
12.7Optional Polymorphism, Virtual Functions and Dynamic Binding Under the Hood456
12.8Case Study: Payroll System Using Polymorphism and Runtime Type Information with
Downcasting, dynamic_cast, typeid and type_info459
12.9Wrap-Up462
Chapter 13Stream InputOutput: A Deeper Look468
13.1Introduction469
13.2Streams469
13.3Stream Output472
13.4Stream Input473
13.5Unformatted IO Using read, write and gcount476
13.6Introduction to Stream Manipulators477
13.7Stream Format States and Stream Manipulators481
13.8Stream Error States488
13.9Tying an Output Stream to an Input Stream490
13.10Wrap-Up490
Chapter 14File Processing499
14.1Introduction499
14.2Files and Streams500
14.3Creating a Sequential File500
14.4Reading Data from a Sequential File504
14.5Updating Sequential Files508
14.6Random-Access Files508
14.7Creating
內容試閱:
Preface
The chief merit of language is clearness
Galen
Welcome to the C computer programming language and C How to Program, Ninth Edition. This book presents leading-edge computing technologies. Its appropriate for introductory course sequences based on the curriculum recommendations of two key professional organizationsthe ACM and the IEEE. If you havent already done so, please read the back cover and inside back coverthese capture the essence of the book concisely. In this Preface we provide more detail for students, instructors and professionals.
At the heart of the book is the Deitel signature live-code approachwe present concepts in the context of complete working programs followed by sample executions, rather than in code snippets. Read the online Before You Begin sectionwww.deitel.combookscpphtp9cpphtp9_BYB.pdf to learn how to set up your Linux-based, Windows-based or Apple OS X-based computer to run the hundreds of code examples. All the source code is available at www.deitel.combookscpphtp9 and www.pearsoninternational-editions.com deitel. Use the source code we provide to run each program as you study it.
We believe that this book and its support materials will give you an informative, challenging and entertaining introduction to C. As you read the book, if you have questions, were easy to reach at deitel@deitel.comwell respond promptly. For book updates, visit www.deitel.combookscpphtp9, join our social media communities on Facebookwww.deitel.comDeitelFan, Twitter@deitel, Googlegplus.todeitel and LinkedInbit.lyDeitelLinkedIn, and subscribe to the Deitel Buzz? Online newsletter www.deitel.comnewslettersubscribe.html.
C11 Standard
The new C11 standard, published in 2011, motivated us to write C How to Program, 9e. Throughout the book, each new C11 feature is marked with the 11 icon you see here in the margin. These are some of the key C11 features of this new edition:
? Conforms to the new C11 standard. Extensive coverage of the new C11 features Fig. 1.
? Code thoroughly tested on three popular industrial-strength C11 compilers. We tested the code examples on GNU C 4.7, Microsoft? Visual C? 2012 and Apple? LLVM in Xcode? 4.5.
? Smart pointers. Smart pointers help you avoid dynamic memory management errors by providing additional functionality beyond that of built-in pointers. We discuss unique_ptr in Chapter 17, and shared_ptr and weak_ptr in Chapter 24.
? Earlier coverage of Standard Library containers, iterators and algorithms, enhanced with C11 capabilities. We moved the treatment of Standard Library containers, iterators and algorithms from Chapter 22 in the previous edition to Chapters 15 and 16 and enhanced it with additional C11 features. The vast majority of your data structure needs can be fulfilled by reusing these Standard Library capabilities. Well show you how to build your own custom data structures in Chapter 19.
C11 features in C How to Program, 9e
Fig. 1 | A sampling of C11 features in C How to Program, 9e.
? Online Chapter 24, C11: Additional Topics. In this chapter, we present additional C11 topics. The new C11 standard has been available since 2011, but not all C compilers have fully implemented the features. If all three of our key compilers already implemented a particular C11 feature at the time we wrote this book, we generally integrated a discussion of that feature into the text with a live-code example. If any of these compilers had not implemented that feature, we included a bold italic heading followed by a brief discussion of the feature. Many of those discussions are expanded in online Chapter 24 as the features are implemented. This chapter includes discussions of regular expressions, shared_ptr and weak_ptr smart pointers, move semantics and more.
? Random Number generation, simulation and game playing. To help make programs more secure, weve added a treatment of C11s new non-deterministic random-number generation capabilities.
Object-Oriented Programming
? Early-objects ap