国外计算机科学教材系列:C大学教程(第五版 英文版)
作者: (美)戴特尔,(美)戴特尔 著
出版时间:2010
丛编项: 国外计算机科学教材系列
《C大学教程(第5版)(英文版)》是全球畅销的C语言教程之一。全书系统介绍了4种流行的程序设计方法——面向过程、基于对象、面向对象以及泛型编程,内容全面、生动、易懂,由浅入深地介绍了结构化编程和软件工程的基本概念,从简单的概念到最终完整的语言描述,清晰、准确、透彻、详细地讲解c语言,尤其注重程序设计思想和方法的介绍。在内容方面,《C大学教程(第5版)(英文版)》新增加了介绍C99标准、排序、基于Allegro C函数库的游戏编程以及有关C++面向对象程序设计的章节,并且在附录中增加了Sudoku游戏程序设计的讲解。“活代码”方法是《C大学教程(第5版)(英文版)》的另一特色,它可以促进学生积极地参与到程序设计中来。书中列出的各种程序设计提示,是作者多年教学经验的总结。《C大学教程(第5版)(英文版)》不仅适合于初学者学习,作为高校计算机程序设计教学的教科书,也同样适用于有经验的程序员,作为软件开发人员的专业参考书。
目录
- Chapter 1 Introduction to Computers, the Internet and the Web 1
- 1.1 Introduction 2
- 1.2 What Is a Computer 3
- 1.3 Computer Organization 3
- 1.4 Early Operating Systems 4
- 1.5 Personal, Distributed and Client /Server Computing 4
- 1.6 Machine Languages, Assembly Languages and High-Level Languages 5
- 1.7 Fortran, COBOL, Pascal and Ada 6
- 1.8 History of C 6
- 1.9 C Standard Library 7
- 1.10 C++ 8
- 1.11 Java 8
- 1.12 BASIC, Visual Basic, Visual C++, Visual C# and .NET 9
- 1.13 Key Software Trend: Object Technology 9
- 1.14 Typical C Program Development Environment 10
- 1.15 Hardware Trends 12
- 1.16 History of the Internet 12
- 1.17 History of the World Wide Web 13
- 1.18 Notes About C and This Book 13
- 1.19 Web Resources 14
- Chapter 2 Introduction to C Programming 25
- 2.1 Introduction 25
- 2.2 A Simple C Program: Printing a Line of Text 26
- 2.3 Another Simple C Program: Adding Two Integers 29
- 2.4 Memory Concepts 32
- 2.5 Arithmetic in C 33
- 2.6 Decision Making: Equality and Relational Operators 35
- Chapter 3 Structured Program Development in C 48
- 3.1 Introduction 48
- 3.2 Algorithms 49
- 3.3 Pseudocode 49
- 3.4 Control Structures 50
- 3.5 The if Selection Statement 51
- 3.6 The if...else Selection Statement 52
- 3.7 The while Repetition Statement 55
- 3.8 Formulating Algorithms Case Study 1: Counter-Controlled Repetition 56
- 3.9 Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 2: Sentinel-Controlled Repetition 57
- 3.10 Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 3: Nested Control Structures 62
- 3.11 Assignment Operators 65
- 3.12 Increment and Decrement Operators 65
- Chapter 4 C Program Control 82
- 4.1 Introduction 83
- 4.2 Repetition Essentials 83
- 4.3 Counter-Controlled Repetition 83
- 4.4 for Repetition Statement 85
- 4.5 for Statement: Notes and Observations 86
- 4.6 Examples Using the for Statement 87
- 4.7 switch Multiple-Selection Statement 90
- 4.8 do...while Repetition Statement 94
- 4.9 break and continue Statements 95
- 4.10 Logical Operators 97
- 4.11 Confusing Equality (==) and Assignment (=) Operators 99
- 4.12 Structured Programming Summary 100
- Chapter 5 C Functions 115
- 5.1 Introduction 116
- 5.2 Program Modules in C 116
- 5.3 Math Library Functions 117
- 5.4 Functions 118
- 5.5 Function Definitions 118
- 5.6 Function Prototypes 121
- 5.7 Function Call Stack and Activation Records 123
- 5.8 Headers 123
- 5.9 Calling Functions: Call-by-Value and Call-by-Reference 124
- 5.10 Random Number Generation 124
- 5.11 Example: A Game of Chance 128
- 5.12 Storage Classes 131
- 5.13 Scope Rules 132
- 5.14 Recursion 135
- 5.15 Example Using Recursion: Fibonacci Series 137
- 5.16 Recursion vs. Iteration 140
- Chapter 6 C Arrays 156
- 6.1 Introduction 156
- 6.2 Arrays 157
- 6.3 Defining Arrays 158
- 6.4 Array Examples 158
- 6.5 Passing Arrays to Functions 168
- 6.6 Sorting Arrays 171
- 6.7 Case Study: Computing Mean, Median and Mode Using Arrays 173
- 6.8 Searching Arrays 176
- 6.9 Multiple-Subscripted Arrays 180
- Chapter 7 C Pointers 200
- 7.1 Introduction 200
- 7.2 Pointer Variable Definitions and Initialization 201
- 7.3 Pointer Operators 201
- 7.4 Passing Arguments to Functions by Reference 203
- 7.5 Using the const Qualifier with Pointers 206
- 7.6 Bubble Sort Using Call-by-Reference 210
- 7.7 sizeof Operator 213
- 7.8 Pointer Expressions and Pointer Arithmetic 214
- 7.9 Relationship between Pointers and Arrays 216
- 7.10 Arrays of Pointers 219
- 7.11 Case Study: Card Shuffiing and Dealing Simulation 220
- 7.12 Pointers to Functions 224
- Chapter 8 C Characters and Strings 243
- 8.1 Introduction 244
- 8.2 Fundamentals of Strings and Characters 244
- 8.3 Character-Handling Library 245
- 8.4 String-Conversion Functions 249
- 8.5 Standard Input/Output Library Functions 252
- 8.6 String-Manipulation Functions of the String- Handling Library 255
- 8.7 Comparison Functions of the String-Handling Library 257
- 8.8 Search Functions of the String-Handling Library 258
- 8.9 Memory Functions of the String-Handling Library 262
- 8.10 Other Functions of the String-Handling Library 265
- Chapter 9 C Formatted Input/Output 277
- 9.1 Introduction 277
- 9.2 Streams 278
- 9.3 Formatting Output with printf 278
- 9.4 Printing Integers 278
- 9.5 Printing Floating-Point Numbers 279
- 9.6 Printing Strings and Characters 281
- 9.7 Other Conversion Specifiers 281
- 9.8 Printing with Field Widths and Precision 282
- 9.9 Using Flags in the printf Format Control String 284
- 9.10 Printing Literals and Escape Sequences 286
- 9.11 Reading Formatted Input with scanf 287
- Chapter 10 C Structures, Unions, Bit Manipulations and Enumerations 298
- 10.1 Introduction 298
- 10.2 Structure Definitions 299
- 10.3 Initializing Structures 301
- 10.4 Accessing Members of Structures 301
- 10.5 Using Structures with Functions 302
- 10.6 typedef 302
- 10.7 Example: High-Performance Card Shuffling and Dealing Simulation 303
- 10.8 Unions 305
- 10.9 Bitwise Operators 307
- 10.10 Bit Fields 313
- 10.11 Enumeration Constants 315
- Chapter 11 C File Processing 325
- 11.1 Introduction 325
- 11.2 Data Hierarchy 326
- 11.3 Files and Streams 327
- 11.4 Creating a Sequential-Access File 327
- 11.5 Reading Data from a Sequential-Access File 331
- 11.6 Random-Access Files 335
- 11.7 Creating a Random-Access File 335
- 11.8 Writing Data Randomly to a Random-Access File 337
- 11.9 Reading Data from a Random-Access File 339
- 11.10 Case Study: Transaction-Processing Program 340
- Chapter 12 C Data Structures 353
- 12.1 Introduction 353
- 12.2 Self-Referential Structures 354
- 12.3 Dynamic Memory Allocation 355
- 12.4 Linked Lists 355
- 12.5 Stacks 362
- 12.6 Queues 366
- 12.7 Trees 370
- Chapter 13 C Preprocessor 394
- 13.1 Introduction 394
- 13.2 #include Preprocessor Directive 395
- 13.3 #define Preprocessor Directive: Symbolic Constants 395
- 13.4 #define Preprocessor Directive: Macros 395
- 13.5 Conditional Compilation 397
- 13.6 #error and #pragma Preprocessor Directives 398
- 13.7 # and ## Operators 398
- 13.8 Line Numbers 398
- 13.9 Predefined Symbolic Constants 399
- 13.10 Assertions 399
- Chapter 14 Other C Topics 403
- 14.1 Introduction 403
- 14.2 Redirecting Input/Output on Linux/UNIX and Windows Systems 404
- 14.3 Variable-Length Argument Lists 404
- 14.4 Using Command-Line Arguments 406
- 14.5 Notes on Compiling Multiple-Source-File Programs 407
- 14.6 Program Termination with exit and atexit 408
- 14.7 volatile Type Qualifier 409
- 14.8 Suffixes for Integer and Floating-Point Constants 409
- 14.9 More on Files 410
- 14.10 Signal Handling 411
- 14.11 Dynamic Memory Allocation: Functions calloc and realloc 413
- 14.12 Unconditional Branching with goto 413
- Chapter 15 Game Programming with the Allegro C Library 419
- 15.1 Introduction 420
- 15.2 Installing Allegro 420
- 15.3 A Simple Allegro Program 420
- 15.4 Simple Graphics: Importing Bitmaps and Blitting 421
- 15.5 Animation with Double Buffering 424
- 15.6 Importing and Playing Sounds 429
- 15.7 Keyboard Input 432
- 15.8 Fonts and Displaying Text 436
- 15.9 Implementing the Game of Pong 439
- 15.10 Timers in Allegro 444
- 15.11 The Grabber and Allegro Datafiles 447
- 15.12 Other Allegro Capabilities 453
- 15.13 Allegro Internet and Web Resources 454
- Chapter 16 Sorting: A Deeper Look 460
- 16.1 Introduction 460
- 16.2 Big O Notation 461
- 16.3 Selection Sort 461
- 16.4 Insertion Sort 464
- 16.5 Merge Sort 466
- Chapter 17 Introduction to C99 474
- 17.1 Introduction 475
- 17.2 Support for C99 475
- 17.3 New C99 Headers 476
- 17.4 // Comments 476
- 17.5 Mixing Declarations and Executable Code 476
- 17.6 Declaring a Variable in a for Statement Header 477
- 17.7 Designated Initializers and Compound Literals 478
- 17.8 Type bool 480
- 17.9 Implicit int in Function Declarations 481
- 17.10 Complex Numbers 482
- 17.11 Variable-Length Arrays 483
- 17.12 Other C99 Features 484
- 17.13 Internet and Web Resources 486
- Chapter 18 C++ as a Better C; Introducing Object Technology 490
- 18.1 Introduction 491
- 18.2 C++ 491
- 18.3 A Simple Program: Adding Two Integers 491
- 18.4 C++ Standard Library 493
- 18.5 Header Files 494
- 18.6 Inline Functions 495
- 18.7 References and Reference Parameters 496
- 18.8 Empty Parameter Lists 500
- 18.9 Default Arguments 500
- 18.10 Unary Scope Resolution Operator 501
- 18.11 Function Overloading 502
- 18.12 Function Templates 505
- 18.13 Introduction to Object Technology and the UML 507
- 18.14 Wrap-Up 510
- Chapter 19 Introduction to Classes and Objects 516
- 19.1 Introduction 517
- 19.2 Classes, Objects, Member Functions and Data Members 517
- 19.3 Overview of the Chapter Examples 518
- 19.4 Defining a Class with a Member Function 518
- 19.5 Defining a Member Function with a Parameter 521
- 19.6 Data Members, set Functions and get Functions 523
- 19.7 Initializing Objects with Constructors 528
- 19.8 Placing a Class in a Separate File for Reusability 531
- 19.9 Separating Interface from Implementation 534
- 19.10 Validating Data with set Functions 538
- 19.11 Wrap-Up 542
- Chapter 20 Classes: A Deeper Look, Part 1 548
- 20.1 Introduction 549
- 20.2 Time Class Case Study 549
- 20.3 Class Scope and Accessing Class Members 554
- 20.4 Separating Interface from Implementation 555
- 20.5 Access Functions and Utility Functions 556
- 20.6 Time Class Case Study: Constructors with Default Arguments 558
- 20.7 Destructors 562
- 20.8 When Constructors and Destructors Are Called 562
- 20.9 Time Class Case Study: A Subtle Trap—Returning a Reference to a private Data Member 565
- 20.10 Default Memberwise Assignment 567
- 20.11 Software Reusability 568
- 20.12 Wrap-Up 569
- Chapter 21 Classes: A Deeper Look, Part 2 574
- 21.1 Introduction 575
- 21.2 const (Constant) Objects and const Member Functions 575
- 21.3 Composition: Objects as Members of Classes 582
- 21.4 friend Functions and friend Classes 587
- 21.5 Using the this Pointer 589
- 21.6 Dynamic Memory Management with Operators new and delete 593
- 21.7 static Class Members 594
- 21.8 Data Abstraction and Information Hiding 599
- 21.8.1 Example: Array Abstract Data Type 600
- 21.8.2 Example: String Abstract Data Type 600
- 21.8.3 Example: Queue Abstract Data Type 600
- 21.9 Container Classes and Iterators 601
- 21.10 Proxy Classes 601
- 21.11 Wrap-Up 603
- Chapter 22 Operator Overloading 609
- 22.1 Introduction 610
- 22.2 Fundamentals of Operator Overloading 610
- 22.3 Restrictions on Operator Overloading 611
- 22.4 Operator Functions as Class Members vs. Global Functions 612
- 22.5 Overloading Stream Insertion and Stream Extraction Operators 613
- 22.6 Overloading Unary Operators 616
- 22.7 Overloading Binary Operators 616
- 22.8 Case Study: Array Class 617
- 22.9 Converting between Types 625
- 22.10 Overloading ++ and 行 626
- 22.11 explicit Constructors 627
- 22.12 Wrap-Up 630
- Chapter 23 Object-Oriented Programming: Inheritance 639
- 23.1 Introduction 640
- 23.2 Base Classes and Derived Classes 641
- 23.3 protected Members 642
- 23.4 Relationship between Base Classes and Derived Classes 643
- 23.4.1 Creating and Using a CommissionEmployee Class 643
- 23.4.2 Creating a BasePlusCommissionEmployee Class Without Using Inheritance 647
- 23.4.3 Creating a CommissionEmployeeasePlusCommissionEmployee Inheritance Hierarchy 651
- 23.4.4 CommissionEmployeeasePlusCommissionEmployee Inheritance Hierarchy Using protected Data 654
- 23.4.5 CommissionEmployeeasePlusCommissionEmployee Inheritance Hierarchy Using private Data 659
- 23.5 Constructors and Destructors in Derived Classes 665
- 23.6 public, protected and private Inheritance 670
- 23.7 Software Engineering with Inheritance 671
- 23.8 Wrap-Up 672
- Chapter 24 Object-Oriented Programming: Polymorphism 677
- 24.1 Introduction 678
- 24.2 Polymorphism Examples 679
- 24.3 Relationships Among Objects in an Inheritance Hierarchy 680
- 24.3.1 Invoking Base-Class Functions from Derived-Class Objects 680
- 24.3.2 Aiming Derived-Class Pointers at Base-Class Objects 685
- 24.3.3 Derived-Class Member-Function Calls via Base-Class Pointers 686
- 24.3.4 Virtual Functions 688
- 24.3.5 Summary of the Allowed Assignments Between Base-Class and Derived-Class Objects and Pointers 692
- 24.4 Type Fields and switch Statements 692
- 24.5 Abstract Classes and Pure virtual Functions 693
- 24.6 Case Study: Payroll System Using Polymorphism 695
- 24.6.1 Creating Abstract Base Class Employee 695
- 24.6.2 Creating Concrete Derived Class SalariedEmployee 698
- 24.6.3 Creating Concrete Derived Class HourlyEmployee 699
- 24.6.4 Creating Concrete Derived Class CommissionEmployee 701
- 24.6.5 Creating Indirect Concrete Derived Class BasePlusCommissionEmployee 702
- 24.6.6 Demonstrating Polymorphic Processing 704
- 24.7 (Optional) Polymorphism, Virtual Functions and Dynamic Binding 襏nder the Hood707
- 24.8 Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info 710
- 24.9 Virtual Destructors 712
- 24.10 Wrap-Up 713
- Chapter 25 Templates 718
- 25.1 Introduction 718
- 25.2 Function Templates 719
- 25.3 Overloading Function Templates 721
- 25.4 Class Templates 722
- 25.5 Nontype Parameters and Default Types for Class Templates 726
- 25.6 Notes on Templates and Inheritance 727
- 25.7 Notes on Templates and Friends 728
- 25.8 Notes on Templates and static Members 728
- 25.9 Wrap-Up 729
- Chapter 26 Stream Input/Output 733
- 26.1 Introduction 734
- 26.2 Streams 734
- 26.2.1 Classic Streams vs. Standard Streams 735
- 26.2.2 iostream Library Header Files 735
- 26.2.3 Stream Input/Output Classes and Objects 735
- 26.3 Stream Output 737
- 26.3.1 Output of char * Variables 737
- 26.3.2 Character Output Using Member Function put 738
- 26.4 Stream Input 738
- 26.4.1 get and getline Member Functions 739
- 26.4.2 istream Member Functions peek, putback and ignore 741
- 26.4.3 Type-Safe I/O 741
- 26.5 Unformatted I/O Using read, write and gcount 741
- 26.6 Introduction to Stream Manipulators 742
- 26.6.1 Integral Stream Base: dec, oct, hex and setbase 742
- 26.6.2 Floating-Point Precision (precision, setprecision) 743
- 26.6.3 FieldWidth (width, setw) 744
- 26.6.4 User-Defined Output Stream Manipulators 745
- 26.7 Stream Format States and Stream Manipulators 746
- 26.7.1 Trailing Zeros and Decimal Points (showpoint) 746
- 26.7.2 Justification (left, right and internal) 747
- 26.7.3 Padding (fill, setfill) 748
- 26.7.4 Integral Stream Base (dec, oct, hex, showbase) 749
- 26.7.5 Floating-Point Numbers; Scientific and Fixed Notation (scientific, fixed) 750
- 26.7.6 Uppercase/Lowercase Control (uppercase) 751
- 26.7.7 Specifying Boolean Format (boolalpha) 751
- 26.7.8 Setting and Resetting the Format State via Member Function flags 752
- 26.8 Stream Error States 753
- 26.9 Tying an Output Stream to an Input Stream 754
- 26.10 Wrap-Up 755
- Chapter 27 Exception Handling 764
- 27.1 Introduction 765
- 27.2 Exception-Handling Overview 765
- 27.3 Example: Handling an Attempt to Divide by Zero 766
- 27.4 When to Use Exception Handling 770
- 27.5 Rethrowing an Exception 771
- 27.6 Exception Specifications 772
- 27.7 Processing Unexpected Exceptions 773
- 27.8 Stack Unwinding 773
- 27.9 Constructors, Destructors and Exception Handling 774
- 27.10 Exceptions and Inheritance 775
- 27.11 Processing new Failures 775
- 27.12 Class auto_ptr and Dynamic Memory Allocation 778
- 27.13 Standard Library Exception Hierarchy 780
- 27.14 Other Error-Handling Techniques 781
- 27.15 Wrap-Up 782
- Appendix A Internet and Web Resources 788
- A.1 Free C/C++ Compilers and Development Tools 788
- A.2 C Resource Sites 789
- A.3 C99 789
- A.4 C Projects, Freeware and Shareware 790
- A.5 C Source Code 790
- A.6 C Articles and Whitepapers 791
- A.7 C Tutorials and Webcasts 791
- A.8 GNOME and GLib 792
- A.9 SWIG 793
- A.10 Objective-C 793
- A.11 C Sample Chapters and eBooks 794
- A.12 C Wikis 794
- A.13 C FAQs 794
- A.14 C Newsgroups 795
- A.15 C Blogs 795
- A.16 C Downloads from Download.com 795
- A.17 C Game Programming 795
- A.18 Allegro Game Programming Resources 796
- A.19 Jobs for C Programmers 797
- A.20 Deitel C Training 798
- Appendix B Operator Precedence Charts 799
- Appendix C ASCII Character Set 801
- Appdndix D Number Systems 802
- D.1 Introduction 802
- D.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers 804
- D.3 Converting Octal and Hexadecimal Numbers to Binary Numbers 805
- D.4 Converting from Binary, Octal or Hexadecimal to Decimal 805
- D.5 Converting from Decimal to Binary, Octal or Hexadecimal 806
- D.6 Negative Binary Numbers: Two誷 Complement Notation 807
- Appendix E Game Programming: Solving Sudoku 812
- E.1 Introduction 812
- E.2 Deitel Sudoku Resource Center 812
- E.3 Solution Strategies 813
- E.4 Programming Sudoku Puzzle Solvers 816
- E.5 Generating New Sudoku Puzzles 816
- E.6 Conclusion 818
-
Index 819