图书简介:
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
展开
Preface
As with its predecessors, the primary purpose of this edition of A First Book of ANSI C is to make C accessible as an applications programming language. The success of past editions, and the many comments I have received from both students and faculty stating that the book really did help them learn and teach C, have been extremely gratifying. Thus, the goal of this fourth edition remains the same as the first three editions: to present all topics clearly, unambiguously, and accessibly to beginning students. This text can be used as an introduction to programming in general, as an introduction to the C language in particular, and as a basis for further study of the C++ language.
This fourth edition includes a number of enhancements, including:
New case studies illustrating real-world program applications
A thorough explanation of input data validation techniques
Expanded exercises that now include both short-answer questions and programming exercises
A table of Common Compiler Errors (at the end of most chapters), for both Unix-and Windows-based compilers, in addition to the list of Common Programming Errors also provided at the end of most chapters
Historical Notes relating to computer science topics
Introductory chapter on Computer Hardware and Software Engineering
Updates to all programs and descriptions that reflect the latest C99 ANSI standard
Distinctive Features of This Book
Emphasis: This text presents topics in a manner that helps students in the real-world of programming. I think this emphasis is best described by a reviewer, who wrote. “The depth [of this text] focuses on the kinds of problems that beginning students stumble across. This is in contrast to [many texts] that somehow manage the feat of providing massive volume without including useful hints and short cuts.”
Writing Style: I firmly believe that introductory texts do not teach students—professors teach students. An introductory textbook, if it is to be useful, must be the supporting actor to the professor’s leading role. Once the professor sets the stage, however, the textbook must encourage the student in mastering the material presented in class. To do this, the text must makes sense to the student. My primary concern, and one of the distinctive features of this book, is that it has been written for the student. As one reviewer said of an earlier edition, “This book addresses the student and not the professional.”
Software Engineering: This text introduces students to the fundamentals of software engineering right from the start. In Section 1.3, students learn about algorithms and the various ways that an algorithm can be described.
The emphasis on software engineering continues in Section 1.4, which introduces the Software Development Process, and in all subsequent case studies, which demonstrate practical applications of the Software Development Process.
Introduction to Pointers: One of the unique features of the first edition was the introduction to pointers, in which the printf() function was used to initially display the addresses of variables; only then were variables used to actually store these addresses. This approach always seemed a more logical and intuitive method of explaining pointer variables than the indirection description in vogue at the time the first edition was released. Since the first edition, I have been pleased to see that using the printf() function to display addresses has become the standard way to introduce pointers. Although this approach, therefore, is no longer a unique feature of my book, I am very proud of its presentation and continue to use it in this new edition.
Program Testing: Every C program in this text has been successfully compiled and run using both Microsoft’s Visual C++ .NET and UNIX compilers. All programs have been written following the C99 ANSI standard. Source code files for all program examples used in the text are available online. This permits students to experiment with the programs and more easily modify them as required by a number of end-of-section exercises.
Pedagogical Features
To make C accessible for a first-level course, the text includes the following pedagogical features:
End-of-Section Exercises: Almost every section in the book contains numerous short answer questions, in addition to the programming exercises provided in earlier editions. Additionally, solutions to all short answer questions are provided in Appendix G and the solutions to all programming exercises are available online to instructors.
Pseudocode and Flowchart Description: Pseudocode is stressed throughout the text. Students also learn about flowchart symbols and how to use flowcharts to visually present flow-of-control constructs.
Common Programming and Compiler Errors and Chapter Summary: Each chapter ends with a section on common programming errors. New to this edition is an easy-to-read table of compiler errors and associated error messages generated by both UNIX- and Windows-based compilers. Each chapter also contains a summary of the main topics covered in the chapter.
Programming and Historical Notes: Scattered through the chapters are shaded boxes labeled “Programming Notes” that highlight important concepts, useful technical points, and programming techniques used by professional programmers. Similarly, the “Historical Notes” highlight significant historical events and people related to the history of computer hardware and software development.
Appendices and Solutions: An expanded set of appendices is provided in this fourth edition. These include appendices on operator precedence, ASCII codes, the standard C library, I/O and standard error redirection, floating-point number storage, and creating a personal C library. A final appendix offers solutions to all short answer questions. Solutions for all programming exercises are available at www.cengage.com/us/.
Supplemental Materials The following supplemental materials are available when this book is used in a classroom setting.
Electronic Instructor’s Manual. The Instructor’s Manual that accompanies this textbook includes:
Additional instructional material to assist in class preparation, including suggestions for lecture topics
Solutions to all the end-of-chapter materials, including the Programming Exercises
ExamView?. This textbook is accompanied by ExamView, a powerful testing software package that allows instructors to create and administer printed, computer (LAN-based), and Internet exams. ExamView includes hundreds of questions that correspond to the topics covered in this text, enabling students to generate detailed study guides that include page references for further review. These computer-based and Internet testing components allow students to take exams at their computers, and save the instructor time because each exam is graded automatically.
PowerPoint Presentations. This book comes with Microsoft PowerPoint slides for each chapter. These are included as a teaching aid for classroom presentations, either to make available to students on the network for chapter review, or to be printed for classroom distribution. Instructors can add their own slides for additional topics that they introduce to the class.
Distance Learning. Course Technology is proud to present online courses in WebCT and Blackboard to provide the most complete and dynamic learning experience possible. When you add online content to one of your courses, you’re adding a lot: Topic Reviews, Practice Tests, Review Questions, Assignments, PowerPoint presentations, and, most of all, a gateway to the 21st century’s most important information resource. For more information on how to bring distance learning to your course, contact your local Course Technology sales representative.
Source Code. The source code for this text is available at www.cengage.com/us/.
Solution Files. The solution files for all programming exercises are available at www.cengage.com/us/.
Acknowledgments This fourth edition is a direct result of the success of the past editions. In this regard, my most heartfelt acknowledgment and appreciation go to the instructors and students who found these editions helpful in their quests to teach and learn C.
Special thanks also to my editor, Alyssa Pratt, at Course Technology. Alyssa’s vision, continuous faith, and attention to schedule and detail were instrumental to the successful completion of this edition. Next, Ann Shaffer, the development editor, provided one of the most extensive and professional edits of the original manuscript that I have ever been fortunate to receive.
Additionally, I would like to express my gratitude to the following reviewers:
John Avitabile, The College of Saint Rose
Pamela Carter, University of Colorado at Colorado Springs
Andrew Hurd, Hudson Valley Community College
Thami Rachidi, University of Colorado at Denver
Eric Thompson, University of Colorado at Denver
John H. Town, Blinn College
Each reviewer supplied detailed and constructive reviews of the text. Their suggestions, attention to detail, and comments were extraordinarily helpful to me as the manuscript evolved and matured throughout the editorial process.
Once the review process was completed, the task of turning the final manuscript into a textbook depended on many people other than myself. I especially want to thank Jennifer Roehrig, Production Editor, Serge Palladino, Quality Assurance Tester, Chris Scriver, Quality Assurance Manager, Nicole Ashton, who created the solutions, and once again, Ann Shaffer, the overall coordinator. The dedication of this second team of people was incredible and very important to me. I am very grateful to each of these individuals for the work they did on this text.
Special acknowledgment goes to three of my colleagues who provided material for this text. First, in addition to numerous editing and technical contributions made by Assistant Professor Andrew J. Hurd, of Hudson Valley Community College, I am very grateful for his provision of the compiler errors. I am also extremely grateful to R. Kenneth Walter, now retired from Weber State University, who graciously provided the material used in the Historical Notes. Special thanks must also go to my first mathematics teacher, Marie Scully-Bell, who taught me that any subject, no matter how difficult, can be mastered, both in academics, and in all of life. She is one of those special people that we are blessed to have in our lives. As always, any errors in the text (as in most of my life) rest solely on my shoulders.
I gratefully acknowledge the direct encouragement and support of Fairleigh Dickinson University. This includes the constant encouragement, support, and positive academic climate provided by the campus provost, Dr. Kenneth Greene, and my Chairperson, Dr. Paul Yoon. Without their support, this text could not have been written.
Finally, I deeply appreciate the patience, understanding, and love provided by my friend, wife, and partner, Rochelle.
To: Rochelle, Matthew, Jeremy, David Bronson
Gary Bronson
展开