這是一本介紹用C語言進行計算機編程的經(jīng)典教材。通過大量的實例和練習,全書系統(tǒng)介紹了數(shù)據(jù)類型、算術運算、邏輯運算、變量、條件語句、函數(shù)、數(shù)組、指針、字符串、結構、文件操作、位操作、宏、庫函數(shù)等基本內(nèi)容,使讀者在閱讀之后就能很快掌握C語言編程的精髓。講解C++編程的一章也是本書的特色之一。書中每章都有大量的簡答題和編程練習題,附錄還列出了它們的答案。
Gary J. Bronson博士是狄金森州立大學的信息系統(tǒng)教授,在那里他曾兩度當選為年度教師。Bronson博士曾在洛克希德電子公司擔任高級項目工程師,曾擔任貝爾實驗室的特邀講師和顧問,并擔任了數(shù)家華爾街金融公司的軟件顧問。Bronson博士撰寫了幾部相當成功的有關C、C++和Java的編程教材。
Gary J. Bronson博士是狄金森州立大學的信息系統(tǒng)教授,在那里他曾兩度當選為年度教師。Bronson博士曾在洛克希德電子公司擔任高級項目工程師,曾擔任貝爾實驗室的特邀講師和顧問,并擔任了數(shù)家華爾街金融公司的軟件顧問。Bronson博士撰寫了幾部相當成功的有關C、C++和Java的編程教材。
Contents
Part 1 Fundamentals 1
Chapter 1 Introduction to Computer Programming 1
1.1 History and Hardware 1
1.2 Programming Languages 7
1.3 Algorithms 12
1.4 The Software Development Process 15
1.5 Case Study: Design and Development 22
1.6 Common Programming Errors 25
1.7 Chapter Summary 25
1.8 Chapter Appendix: Numerical Storage Codes 26
Chapter 2 Getting Started in C Programming 28
2.1 Introduction to C Programming 28
2.2 Programming Style 36
2.3 Data Types 40
2.4 Arithmetic Operations 45
2.5 Variables and Declarations 53
2.6 Case Study: Temperature Conversion 61
2.7 Common Programming and Compiler Errors 64
2.8 Chapter Summary 66
2.9 Chapter Supplement: Memory Allocation 67
Chapter 3 Processing and Interactive Input 73
3.1 Assignment 73
3.2 Mathematical Library Functions 81
3.3 Interactive Input 85
3.4 Formatted Output 94
3.5 Symbolic Constants 101
3.6 Case Study: Interactive Input 103
3.7 Common Programming and Compiler Errors 108
3.8 Chapter Summary 109
3.9 Chapter Supplement: Introduction to Abstraction 110
Part 2 Flow of Control 112
Chapter 4 Selection 112
4.1 Relational Expressions 112
4.2 The if and if-else Statements 117
4.3 The if-else Chain 126
4.4 The switch Statement 132
4.5 Case Study: Data Validation 138
4.6 Common Programming and Compiler Errors 141
4.7 Chapter Summary 143
4.8 Chapter Supplement: Errors, Testing, and Debugging 144
Chapter 5 Repetition 149
5.1 Basic Loop Structures 149
5.2 The while Statement 152
5.3 Computing Sums and Averages Using a while Loop 158
5.4 The for Statement 167
5.5 Case Studies: Loop Programming Techniques 174
5.6 Nested Loops 180
5.7 The do-while Statement 183
5.8 Common Programming and Compiler Errors 187
5.9 Chapter Summary 188
Chapter 6 Modularity Using Functions: Part I 190
6.1 Function and Parameter Declarations 190
6.2 Returning a Value 201
6.3 Case Study: Calculating Age Norms 209
6.4 Standard Library Functions 217
6.5 Common Programming and Compiler Errors 228
6.6 Chapter Summary 229
Chapter 7 Modularity Using Functions: Part II 230
7.1 Variable Scope 231
7.2 Variable Storage Class 236
7.3 Pass by Reference 242
7.4 Case Study: Swapping Values 251
7.5 Recursion 257
7.6 Common Programming and Compiler Errors 261
7.7 Chapter Summary 262
Part 3 Completing the Basics 264
Chapter 8 Arrays 264
8.1 One-Dimensional Arrays 265
8.2?Array Initialization 272
8.3 Arrays as Function Arguments 276
8.4 Case Study: Computing Averages and Standard Deviations 279
8.5 Two-Dimensional Arrays 284
8.6 Common Programming and Compiler Errors 292
8.7 Chapter Summary 293
8.8 Chapter Supplement: Searching and Sorting Methods 293
Chapter 9 Character Strings 312
9.1 String Fundamentals 312
9.2 Library Functions 321
9.3 Input Data Validation 327
9.4 Formatting Strings (Optional) 333
9.5 Case Study: Character and Word Counting 335
9.6 Common Programming and Compiler Errors 340
9.7 Chapter Summary 341
Chapter 10 Data Files 342
10.1?Declaring, Opening, and Closing File Streams 342
10.2?Reading from and Writing to Text Files 352
10.3?Random File Access 359
10.4?Passing and Returning Filenames 361
10.5?Case Study: Creating and Using a Table of Constants 363
10.6?Writing and Reading Binary Files (Optional) 371
10.7?Common Programming and Compiler Errors 375
10.8?Chapter Summary 376
10.9?Chapter Supplement: Control Codes 377
Part 4 Additional Topics 380
Chapter 11 Arrays, Addresses, and Pointers 380
11.1?Array Names as Pointers 380
11.2?Manipulating Pointers 385
11.3?Passing and Using Array Addresses 390
11.4?Processing Strings Using Pointers 395
11.5?Creating Strings Using Pointers 399
11.6?Common Programming and Compiler Errors 404
11.7?Chapter Summary 405
Chapter 12 Structures 406
12.1?Single Structures 406
12.2?Arrays of Structures 411
12.3?Passing and Returning Structures 415
12.4?Unions 420
12.5?Common Programming and Compiler Errors 422
12.6?Chapter Summary 423
Chapter 13 Dynamic Data Structures 425
13.1?Introduction to Linked Lists 425
13.2?Dynamic Memory Allocation 432
13.3?Stacks 436
13.4?Queues 442
13.5?Dynamically Linked Lists 447
13.6?Common Programming and Compiler Errors 453
13.7?Chapter Summary 454
Chapter 14 Additional Capabilities 456
14.1?Additional Features 456
14.2?Bit Operations 461
14.3?Macros 467
14.4?Command-Line Arguments 469
14.5?Common Programming and Compiler Errors 473
14.6?Chapter Summary 473
Chapter 15 A Brief Introduction to C++ 475
15.1?Procedural Programming in C++ 475
15.2?Object-Oriented C++ 479
15.3?Common Programming and Compiler Errors 481
15.4?Chapter Summary 482
Appendix A Operator Precedence Table 484
Appendix B ASCII Character Codes 485
Appendix C The Standard C Library 488
Appendix D Input, Output, and Standard Error Redirection 493
Appendix E Floating-Point Number Storage 495
Appendix F Creating a Personal Library 497
Appendix G Solutions to Short Answer Questions 499