第0章 緒論 第1章 程序設(shè)計(jì)概述 第2章 程序開(kāi)發(fā) 第3章 選擇結(jié)構(gòu):做決策 第4章 重復(fù)結(jié)構(gòu):循環(huán) 第5章 數(shù)組:列表與表格 第6章 順序數(shù)據(jù)文件 Brief Contents . Contents xiii 0 Introduction 1 1 An Introduction to Programming 27 2 Developing a Program 69 3 Selection Structures: Making Decisions 123 4 Repetition Structures: Looping 177 5 Arrays: Lists and Tables 239 6 Sequential Data Files 301 Study Skills 341 Glossary 351 Index 365 xI Contents 0 Introduction 1 0.1 Computers EveryWhere 1 0.Z A Brief History of Computers 2 What is a Computers 2 Early Computers 2 Personal Computers 5 TOdays Computers 6 The Internet 7 O.3 Computer Basics 9 The Central Processing Unit 10 Internal Memory 11 Mass Storage Devices 12 Input Devices 14 Output Devices 14 0.4 Software and Programming Languages 16 Types of Software 16 Types of Programming Languages 18 Chapter Review and EXercises 21 1 An introduction to Programming 27 In the Everyday World: You Are Already a Programmer! 28 1 .1 What is Programming? 28 A General Problem-Solving Strategy 29 Creating Computer Programs: The Program Development Cycle 31 1 .2 Basic Programming Concepts 3Z A Simple Program 32 The Price Conversion Program 33 Data input 35 The input and Write Statements 36 xIII . Xlv Contents Use Input Prompts 37 Other Forms of input 37 Program Variables and Constants 37 Variables Names 39 Variable Names Should Be Meaningful! 39 Whats Really Going On with Variables in the Computer? 40 y Going On with Variables in the Computer? 40 1 .3 Data Processing and Output 41 Processing Data 41 The Set Statement 42 Assigning and Reassigning Values to Variables 42 rum f; airy+ry d 7 Operations on Data 43 Hierarchy of ODerations 44 y of Operations 44 Data Output 46 The Write Statement Revisited 47 Annotate Your Output 48 1 .4 TyDes of Data 50 ypes of Data 50 Numeric Data 51 Integers 51 b Dividing Integers 52 o Integers 52 Real Numbers 52 The Declare Statement 53 The Last Word on Price Conversion 54 Scientific and Exponential Notation 55 Character String Data 57 The Character Data Type 58 ape 58 Operating on Strings 58 Chanter Review and EXercises 6J pier Review and EXercises 6J 2 Developing a Program 69 In the Everyday World: Planning to Program7 You Need a Plan 7O 2.1 The Program Development Cycle 71 The Process of Developing a Program 71 Analyze the Problem 71 yze the Problem 71 Design the Program 72 an the Program 72 Code the Program 73 Test the Program 74 Additional Steps in the Cycle 76 2.2 Program Design 80 Modular Programming 80 Using Modules and Submodules 81 Benefits of Modular Programming 81 Provide a Welcome Message at the Beginning of Your Program 86 Contents xv 2.3 Coding, Documenting, and Testing a Program 90 Coding and Documenting a Program 90 How Can a Computer Know What to ignore? 91 External Documentation 93 Types of Errors 94 2.4 Commercial Programs: Testing and Documenting 95 The Testing Phase Revisited 96 External Documentation 97 The Users Guide 97 The Program Maintenance Manual 98 Design Documentation 98 Trade Study Documentation 99 2.5 Structured Programming 100 Flowcharts 100 Control Structures 101 The Sequential Structure 101 Loop or Repetition Structures 103 Decision or Selection Structures 103 Z.6 An introduction to OOP and CUls 106 GUls and Event-Driven Programming 106 Object-Oriented Programming 110 Object-Oriented Programming Design 112 Everyone Needs Structured Programming 114 Chapter Review and EXercises ]15 3 Selection StructUres: Making Decisions 123 In the Everyday World: Decisions, decisions, decisions... IZ4 3.1 An Introduction to Selection Structures 125 Types of Selection Structures 125 Single- and Dual-Alternative Structures 127 Single-Alternative Structure: The if -Then Structure 127 Dual-Alternative Structure: The if -Then - Else Structure 129 3.2 Relational and Logical Operators 133 Relational Operators 133 A Little More Explanation about Relational Operators 134 Logical Operators 137 Truth Tables for the OR, AND, and NOT Operators 138 Compounding the Compound Condition issue 140 Hierarchy of Operations 143 3.3 Selecting from Several Alternatives 146 Using if Structures 147 The Action of a Case Statement 150 . Xvi Contents 3.4 Applications of Selection Structures 154 Defensive Programming 154 Menu-Driven Programs 158 35 FOcus on Problem Solving: A New Car Price Calculator 161 Problem Statement 161 Problem AnalVsis 162 y3ls 162 Program Design 162 blain Design 162 Program Code 166 brain Code 166 Program Test 166 brain rest 166 Chanter Review and EXercises ]67 pier Review and EXercises ]67 4 Repetition Structures: Looping 177 In the Everyday WOrld: Loops 178 4.1 An Introduction to Repetition Structures: Computers Never Cet Bored! 179 A Simple Example of a Loop 179 Beware of the Infinite Loop! 181 Relational and Logical Operators 183 Pre-Test and Post-Test Loops 184 4.2 CounteFControlled Loops 189 Constructing a Counter-Controlled Loop 190 Summing How a Computer Adds 190 Counting UP, Down, and Every Way 193 Built-In Counter-Controlled Loops 193 The Careful Beau Counter 197 4.3 Applications of Repetition Structures 202 Using Sentinel-Controlled Loops to input Data 202 Data Validation 204 4.4 Nested Loops 215 Nested For Loops 215 Nesting Other Kinds of Loops 218 Nesting Loops and Selection Structures 220 45 FOcus on Problem Solving: A Cost, Revenue, and Profit Problem 223 Problem Statement 223 Problem Analysis 224 j>Is 224 Program Design 226 Program Code 229 brain Code 229 Program Test 230 brain test 230 Chapter Review and Exercises 232 pier Review and Exercises 232 Contents xvii 5 Arrays: Lists and Tables 239 In the Everyday World: Arrays 24O yday World: Arrays 24O 51 One-Dimensional Arrays 241 ys 241 Array Basics 241 y Basics 241 Declaring ArraVs 242 b Arrays 242 Parallel Arrays 248 ys 248 Some Advantages of Using ArraVs 252 bes of Using Arrays 252 5.Z Searching and Sorting Array 256 g and Sorting ArrayS 256 The Serial Search Technique 256 i he Serial Search Technique 256 The Bubble Sort Technique 261 Other Sorts of Sorting 271 53 Other Uses of Arrays 272 ys 272 Strings As ArraVs of Characters 277 e> As Arrays of Characters 272 Declaring an ArraV As a Data TVDe 272 b an Array As a Data Type 272 String Length versus Array Size j74 o Length versus Array Size 274 54 Two-Dimensional Array 277 ,s 277 An Introduction to Two-Dimensional Arrays 277 ys 277 Declaring Two-Dimensional ArraVs 278 b two-Dimensional Arrays 278 Using Two-Dimensional ArraVs 279 a two-Dimensional Arrays 279 5.5 Focus on Problem Solving. 5. An invoice Preparation Program 284 Problem Statement 284 Problem Analysis 285 ysls 285 Program Design 285 Program Code 290 Program Test 291 Chanter Review and Exercises 292 pier Review and Exercises 292 6 Sequential Data Files 301 In the EvervdaV WOrld: Data Files 302 yday WOrld: Data Files 302 6.1 An Introduction to Data Files 3O3 File Basics 303 Creating and Reading Seauential Files 306 b and Reading Sequential Files 306 6.Z Modifying a Seauential File 312 ying a Sequential File 312 Deleting Records 314 b Records 314 ModifVing Records 316 ying Records 316 Inserting Records 317 b Records 317 Using ArraVs in File Maintenance 320 o Arrays in File Maintenance 320 6.3 Mereing Seauential Files 322 ging Sequential Files 322 ... xvill Contents 6.4 Focus on Problem Solving: Control Break Processing 326 Problem Statement 326 Problem Analysis 327 j Program Design 328 Program Code 331 Program Test 332 blain rest 332 Chanter Review and EXercises 333 pier Review and EXercises 333 <.. c 1. I I study skills 341 y Skills 341 Clossary 351 y 351 Index 365