C++程序设计(英文版)(第3版) / 经典原版书库
定价:¥79.00
作者: Y.Daniel Liang
出版时间:2013-06-07
出版社:机械工业出版社
- 机械工业出版社
- 9787111425052
- 1-8
- 44219976-6
- 16开
- 2013-06-07
- 1062
- 计算机类
- 本科
作者简介
内容简介
本书保持了Liang博士系列丛书中一贯的标志性的教与学的哲学:以实例教,由实践学。通过使用他所提出的已经经过实践检验的“基础先行”的方法,Liang博士在本书中通过大量实例阐明了基本的C++特性,使得学生可以通过实践来更有效地进行学习。在引入面向对象程序设计思想之前,Liang博士使用清晰简明的语言介绍了C++语言的基础知识和基本的程序设计技术,如循环、逐步求精等。这些概念都 是使用简短且吸引人的实例来进行阐明的。他还在实例研究中给出了一些较大规模的实例,并附以整体的分析讨论和详细的逐行注解。本书首先帮助学 生循序渐进地学习所有必需和重要的基本概念,然后再进入到面向对象程序设计方法的学习,最终掌握构建具有异常处理和输入输出功能的有意义的应用程序的方 法。贯穿全书的实例和练习都以问题求解为中心,力图培养学生开发可重用组件并用之创建实际项目的意识。
目录
Chapter 1 Introduction to Computers,
Programs, and C++ 1
1.1 Introduction 2
1.2 What Is a Computer? 2
1.3 Programming Languages 9
1.4 Operating Systems 12
1.5 History of C++ 13
1.6 A Simple C++ Program 14
1.7 C++ Program-Development Cycle 18
1.8 Programming Style and Documentation 20
1.9 Programming Errors 21
Chapter 2 Elementary Programming 29
2.1 Introduction 30
2.2 Writing a Simple Program 30
2.3 Reading Input from the Keyboard 32
2.4 Identifiers 35
2.5 Variables 35
2.6 Assignment Statements and Assignment Expressions 37
2.7 Named Constants 39
2.8 Numeric Data Types and Operations 40
2.9 Evaluating Expressions and Operator Precedence 45
2.10 Case Study: Displaying the Current Time 47
2.11 Augmented Assignment Operators 49
2.12 Increment and Decrement Operators 50
2.13 Numeric Type Conversions 52
2.14 Software Development Process 55
2.15 Case Study: Counting Monetary Units 59
2.16 Common Errors 61
Chapter 3 Selections 71
3.1 Introduction 72
3.2 The bool Data Type 72
3.3 if Statements 73
3.4 Two-Way if-else Statements 76
3.5 Nested if and Multi-Way if-else Statements 77
3.6 Common Errors and Pitfalls 79
3.7 Case Study: Computing Body Mass Index 84
3.8 Case Study: Computing Taxes 86
3.9 Generating Random Numbers 89
3.10 Logical Operators 91
3.11 Case Study: Determining Leap Year 94
3.12 Case Study: Lottery 95
3.13 switch Statements 97
3.14 Conditional Expressions 101
3.15 Operator Precedence and Associativity 102
3.16 Debugging 104
Chapter 4 Mathematical Functions,
Contents xiii
Characters, and Strings 117
4.1 Introduction 118
4.2 Mathematical Functions 118
4.3 Character Data Type and Operations 122
4.4 Case Study: Generating Random Characters 126
4.5 Case Study: Guessing Birthdays 128
4.6 Character Functions 131
4.7 Case Study: Converting a Hexadecimal Digit to a Decimal Value 133
4.8 The string Type 134
4.9 Case Study: Revising the Lottery Program Using Strings 138
4.10 Formatting Console Output 140
4.11 Simple File Input and Output 144
Chapter 5 Loops 155
5.1 Introduction 156
5.2 The while Loop 156
5.3 The do-while Loop 168
5.4 The for Loop 171
5.5 Which Loop to Use? 174
5.6 Nested Loops 176
5.7 Minimizing Numeric Errors 178
5.8 Case Studies 179
5.9 Keywords break and continue 185
5.10 Case Study: Checking Palindromes 188
5.11 Case Study: Displaying Prime Numbers 190
Chapter 6 Functions 207
6.1 Introduction 208
6.2 Defining a Function 209
6.3 Calling a Function 210
6.4 void Functions 212
6.5 Passing Arguments by Value 215
6.6 Modularizing Code 216
6.7 Overloading Functions 218
6.8 Function Prototypes 221
6.9 Default Arguments 223
6.10 Inline Functions 224
6.11 Local, Global, and Static Local Variables 225
6.12 Passing Arguments by Reference 230
6.13 Constant Reference Parameters 239
6.14 Case Study: Converting Hexadecimals to Decimals 239
6.15 Function Abstraction and Stepwise Refinement 242
Chapter 7 Single-Dimensional Arrays and C-Strings 265
7.1 Introduction 266
7.2 Array Basics 267
7.3 Problem: Lotto Numbers 273
7.4 Problem: Deck of Cards 276
7.5 Passing Arrays to Functions 278
7.6 Preventing Changes of Array Arguments in Functions 280
7.7 Returning Arrays from Functions 281
7.8 Problem: Counting the Occurrences of Each Letter 284
7.9 Searching Arrays 286
7.10 Sorting Arrays 290
7.11 C-Strings 292
Chapter 8 Multidimensional Arrays 309
8.1 Introduction 310
8.2 Declaring Two-Dimensional Arrays 310
8.3 Processing Two-Dimensional Arrays 311
8.4 Passing Two-Dimensional Arrays to Functions 314
8.5 Problem: Grading a Multiple-Choice Test 315
8.6 Problem: Finding a Closest Pair 317
8.7 Problem: Sudoku 319
8.8 Multidimensional Arrays 322
Chapter 9 Objects and Classes 341
9.1 Introduction 342
9.2 Defining Classes for Objects 342
9.3 Example: Defining Classes and Creating Objects 344
9.4 Constructors 347
9.5 Constructing and Using Objects 348
9.6 Separating Class Definition from Implementation 351
9.7 Preventing Multiple Inclusions 354
9.8 Inline Functions in Classes 355
9.9 Data Field Encapsulation 356
9.10 The Scope of Variables 359
9.11 Class Abstraction and Encapsulation 361
Chapter 10 Object-Oriented Thinking 371
10.1 Introduction 372
10.2 The string Class 372
10.3 Passing Objects to Functions 381
10.4 Array of Objects 384
10.5 Instance and Static Members 386
10.6 Constant Member Functions 390
10.7 Thinking in Objects 392
10.8 Object Composition 398
10.9 Case Study: The StackOfIntegers Class 400
10.10 Class Design Guidelines 402
Chapter 11 Pointers and Dynamic Memory Management 411
11.1 Introduction 412
11.2 Pointer Basics 412
11.3 Defining Synonymous Types Using the typedef Keyword 417
11.4 Using const with Pointers 418
11.5 Arrays and Pointers 419
11.6 Passing Pointer Arguments in a Function Call 422
11.7 Returning a Pointer from Functions 426
11.8 Useful Array Functions 427
11.9 Dynamic Persistent Memory Allocation 429
11.10 Creating and Accessing Dynamic Objects 433
11.11 The this Pointer 435
11.12 Destructors 436
11.13 Case Study: The Course Class 439
11.14 Copy Constructors 442
11.15 Customizing Copy Constructors 445
Chapter 12 Templates, Vectors, and Stacks 455
12.1 Introduction 456
12.2 Templates Basics 456
12.3 Example: A Generic Sort 460
12.4 Class Templates 462
12.5 Improving the Stack Class 469
12.6 The C++ vector Class 471
12.7 Replacing Arrays Using the vector Class 474
12.8 Case Study: Evaluating Expressions 477
Chapter 13 File Input and Output 491
13.1 Introduction 492
13.2 Text I/O 492
13.3 Formatting Output 498
13.4 Functions: getline, get, and put 499
13.5 fstream and File Open Modes 502
13.6 Testing Stream States 504
13.7 Binary I/O 506
13.8 Random Access File 513
13.9 Updating Files 516
Chapter 14 Operator Overloading 523
14.1 Introduction 524
14.2 The Rational Class 524
14.3 Operator Functions 530
14.4 Overloading the Subscript Operator [] 532
14.5 Overloading Augmented Assignment Operators 534
14.6 Overloading the Unary Operators 535
14.7 Overloading the ++ and –– Operators 535
14.8 friend Functions and friend Classes 537
14.9 Overloading the << and >> Operators 539
14.10 Automatic Type Conversions 541
14.11 Defining Nonmember Functions for Overloading Operators 542
14.12 The Rational Class with Overloaded Function Operators 543
14.13 Overloading the = Operators 551
Chapter 15 Inheritance and Polymorphism 559
15.1 Introduction 560
15.2 Base Classes and Derived Classes 560
15.3 Generic Programming 568
15.4 Constructors and Destructors 569
15.5 Redefining Functions 574
15.6 Polymorphism 575
15.7 Virtual Functions and Dynamic Binding 576
15.8 The protected Keyword 580
15.9 Abstract Classes and Pure Virtual Functions 581
15.10 Casting: static_cast versus dynamic_cast 589
Chapter 16 Exception Handling 597
16.1 Introduction 598
16.2 Exception-Handling Overview 598
16.3 Exception-Handling Advantages 601
16.4 Exception Classes 603
16.5 Custom Exception Classes 607
16.6 Multiple Catches 612
16.7 Exception Propagation 617
16.8 Rethrowing Exceptions 618
16.9 Exception Specification 620
16.10 When to Use Exceptions 621
Chapter 17 Recursion 625
17.1 Introduction 626
17.2 Example: Factorials 626
17.3 Case Study: Fibonacci Numbers 630
17.4 Problem Solving Using Recursion 633
17.5 Recursive Helper Functions 635
17.6 Towers of Hanoi 638
17.7 Eight Queens 642
17.8 Recursion versus Iteration 645
17.9 Tail Recursion 645
The following bonus chapters are on the book’s Companion Website at
www.pearsonhighered.com/liang.
Chapter 18 Developing Efficient Algorithms 18-1
Chapter 19 Sorting 19-1
Chapter 20 Linked Lists, Queues,
and Priority Queues 20-1
Chapter 21 Binary Search Trees 21-1
Chapter 22 STL Containers 22-1
Chapter 23 STL Algorithms 23-1
Chapter 24 Graphs and Applications 24-1
Chapter 25 Weighted Graphs and Applications 25-1
Chapter 26 AVL Trees and Splay Trees 26-1
APPENDIXES
Contents xvii
Appendix A C++ Keywords 653
Appendix B The ASCII Character Set 655
Appendix C Operator Precedence Chart 657
Appendix D Number Systems 659
Appendix E Bitwise Operations 663
INDEX 665
CREDIT 689





