Programming practice pascal

486 132 1
Programming practice pascal

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

CodeWarrior Programming Practice: Pascal Metrowerks CodeWarrior TM CD Because of last-minute changes to CodeWarrior, some information in this manual may be out of date. Please read all the Release Notes files that come with CodeWarrior for the latest information. Metrowerks CodeWarrior Copyright ©1993-1995 by Metrowerks Inc. and its Licensors. All rights reserved. Documentation stored on the compact disc may be printed by licensee for personal use. Except for the foregoing, no part of this documentation may be reproduced or transmitted in any form by any means, electronic or mechanical, including photocopying, recording, or any information storage and retrieval system, without permission in writing from Metrowerks Inc. Metrowerks, the Metrowerks logo and Software at Work are registered trademarks of Metrowerks Inc. CodeWarrior, PowerPlant, and PowerPlant Constructor are trademarks of Metrowerks Inc. All other trademarks or registered trademarks are the property of their respective owners. ALL SOFTWARE AND DOCUMENTATION ON THE COMPACT DISC ARE SUBJECT TO THE LICENSE AGREEMENT IN THE CD BOOKLET. Canada and International Metrowerks Inc. 1500 du College, suite 300 St. Laurent, QC H4L 5G6 Canada voice: (514) 747-5999 fax: (514) 747-2822 U.S.A. Metrowerks Corporation Suite 310 The MCC Building 3925 West Braker Lane Austin, TX 78759-5321 voice: 512-305-0400 fax: 512-305-0440 Metrowerks Mail Order voice: (800) 377-5416 or (419) 281-1802 fax: (419) 281-6883 World Wide Web site (Internet): http://www.metrowerks.com Registration information (Internet): register@metrowerks.com Technical support (Internet): support@metrowerks.com Sales, marketing, & licensing (Internet): sales@metrowerks.com AppleLink: METROWERKS America OnLine: goto: METROWERKS Compuserve: goto: METROWERKS eWorld: goto: METROWERKS Table of Contents iii Table of Contents Chapter 1 An Overview 1.1 Preview 14 1.2 Introduction to Programming Practice: Pascal 15 A Global View 15 The Road Ahead 15 Signs Along the Road 16 1.3 Hardware: Computers and Peripherals 17 The CPU 18 Other Components and Packaging 19 1.4 The World of Programming 20 What is Programming? 20 “Real world” and “Abstract World” 20 1.5 Pascal 21 An example Pascal program 22 Running Programs: Compiling, Linking, Executing.23 1.6 Communicating to Computers 24 Typing 24 1.7 Chapter 1 Review 27 Chapter 2 Computing: A Short Survey of Some Applications 2.1 Preview 30 2.2 Software and Applications 30 2.3 Application Software 33 Editor Application 34 Typing Applications 35 Calculator Applications 36 Retrieve Application: A Tiny Database 38 Planner-Calendar Application 39 Bar Plot Application 41 Drill Application 42 SSS: Small and Simple Spreadsheet 43 2.4 Chapter 2 Review 47 Chapter 3 Programming Language: Pascal 3.1 Preview 50 iv Table of Contents 3.2 Languages 50 Syntax and Semantics 50 Syntax Diagrams 53 3.3 Pascal Programs 56 Program Format 56 Program Presentation 59 More Pascal Programming: Data and Actions 60 Data Items 61 Actions: Arithmetic Operations 63 3.4 More Example Programs 66 3.5 Chapter 3 Review 69 3.6 Chapter 3 Problems 70 3.7 Chapter 3 Programming Project 74 Getting Acquainted 74 Chapter 4 Data and Actions 4.1 Preview 76 4.2 Programming: Data and Actions 76 Declarations: Syntax Diagrams from the Bottom 76 Simple Input and Output in Pascal 80 4.3 More Programs: A Top View of Pascal 83 4.4 Programming Style 85 4.5 Layout of Programs 86 4.6 More Programs: Continued 89 Actions: Pre-Defined Standard Functions in Pascal 89 Libraries: Using Units in Pascal 92 4.7 A Foretaste of Procedures 94 4.8 Chapter 4 Review 96 4.9 Chapter 4 Problems 96 4.10 Chapter 4 Programming Projects 97 Generate Conversion Tables 97 Observing Errors 97 Demilitarize Time 98 TipTable 99 STT: Sales Tax Table 100 SSP: Simple Side Plot 101 Chapter 5 The Four Fundamental Forms in Pascal 5.1 Preview 105 Table of Contents v 5.2 The Sequence Form in Pascal 105 5.3 Conditions in Pascal 107 5.4 Repetition Form: The WHILE statement 108 Tracing Loops 110 5.5 WHILES, REALS, and Errors 114 5.6 Selection Forms in Pascal 117 5.7 More Selections: Combinations of Selection Forms 119 Confusion in Choices 120 More Nesting of Choices 120 Alternative Ways to Code Selections 121 5.8 Select Form: Handling Many Branches 124 5.9 Awkward Nests: General Nesting 127 Mixed Nests: Repetition and Selections 128 5.10 Subprograms: Using Subprograms as Black Boxes 130 The ShortSort Library 134 Notation for Defined Procedures 137 Procedures vs. Functions 140 5.11 Binary Logic Library: BitLib 145 5.12 Chapter 5 Review 149 5.13 Chapter 5 Problems 150 5.14 Chapter 5 Programming Problems 152 Sequence Problems 153 Selection Problems 153 Loop Problems 153 Subprogram Problems 153 Debugging Problems 154 Selection Programs 156 Procedures and Repetitions 157 Josephus’ Problem 158 5.15 Chapter 5 Programming Projects 159 Project A: Change Change 159 Project B: Payroll 160 Project C: Quadratic Roots 160 Project D: Digital Circuits 160 Project E: Roll Your Own 161 CRN: Convert Roman Numbers 161 GPR: Growing Pay Roll 161 MWM: Many Ways to Mid 162 DFP: Data Flow Programming 163 Chapter 6 Pascal with Bigger Blocks 6.1 Preview 169 vi Table of Contents 6.2 Conglomerations 169 Mixed and Nested Forms 169 6.3 More Data 171 External 171 CASE Form 173 6.4 More Repetition Forms 175 6.5 The For Loop 177 6.6 Character Type 182 in Pascal 182 Representation of Characters 185 6.7 Boolean Type in Pascal 190 6.8 More Types 193 Big Types in Pascal 193 Even Bigger Types 193 Smaller Types 194 6.9 Programmer Defined Types 195 Enumerated Types 195 Subrange Types In Pascal 198 6.10 Strings in Pascal 198 6.11 Simple Files in Pascal 201 More Files: Input and Output 205 6.12 Modification of Programs 207 6.13 Programming Style 209 Documentation 209 Further Guidelines for Identifiers 212 A Bad Style Horror Story 213 Criticism of the MeanMean Program 215 6.14 Errors in Programming 216 Syntactic Errors 216 Execution Errors 217 Logical Errors 217 Other Errors 217 6.15 Debugging, Testing, Proving 217 6.16 Chapter 6 Review 219 6.17 Chapter 6 Problems 219 6.18 Chapter 6 Programming Problems 221 6.19 Chapter 6 Programming Projects 224 Plotting Programs 224 Modify Calculator 226 Statistics (Rainfall) 227 Project Plotup 227 BSD: Big Statistics Data 228 Table of Contents vii BTD: Big Text Data 229 SMC: Small Monthly Calendar 230 Chapter 7 Better Blocks: Procedures and Libraries 7.1 Preview 233 7.2 Procedures in Pascal 233 Use and Definition 233 7.3 Syntax of Subprogram Forms 235 Procedures in Pascal 235 More Examples of Pascal Procedures 239 Power Procedure 242 7.4 Passing Parameters 242 In, Out, In and Out, and Neither 242 BigChange 242 BigPay 245 A Miscellany of procedures 248 A Second Miscellany of procedures 250 7.5 Procedures with Char, Boolean and Other Types 252 Generalized Item Types 255 7.6 Procedures with User-Defined types 256 7.7 More on Passing Parameters 259 7.8 Nested Procedures 261 7.9 Functions in Pascal 264 Many Functions 266 7.10 SubPrograms: Variations on a theme 269 7.11 Recursion in Pascal 272 7.12 Libraries in Pascal 275 Units 275 UtilityLib: a custom-made utilities Library 278 Other Libraries: DateLib, BitLib, CharLib 281 The Interaction of Many Libraries 288 7.13 Function and Procedure Types 291 7.14 Top-Down Development 296 Pay Again 296 7.15 Chapter 7 Review 299 7.16 Chapter 7 Problems 300 7.17 Chapter 7 Programming Problems 302 Random Projects 302 DateLib 305 Create Libraries 306 viii Table of Contents FinanceLib 307 Change Again: Done Properly with Procedures 308 MeanLib 308 7.18 Chapter 7 Programming Projects 310 DMT: DeMilitarizeTime Lab with Procedures 310 SLL: Small Library Project 311 Chapter 8 Pascal Data Structures 8.1 Preview 314 8.2 Arrays in Pascal 314 ChangeMaker and Variance 317 Parallel Arrays: Part Inventory 319 A Tiny Data Base: Retrieving Strings from Arrays 321 Arrays as Parameters 323 IntArrayLib: Integer Array Library 325 8.3 Two Dimensional Arrays in Pascal 328 Arrays of Arrays—Two Dimensional Arrays 328 8.4 N-Dimensional Arrays 331 More Dimensions 331 8.5 Records in Pascal 333 ComplexLib: A Library for Complex Numbers 337 Records of Records: Nested Records 339 Arrays of Records in Pascal 342 Records of Arrays 345 Matrix Library 347 8.6 Sets in Pascal 352 More Sets (Optional) 355 8.7 Dynamic Variables and Pointers in Pascal 359 8.8 Chapter 8 Review 361 8.9 Chapter 8 Problems 361 8.10 Chapter 8 Programming Projects 363 Gas Project 363 Library Projects 364 BSL: Big Stat Lab 364 Chapter 9 Algorithms to Run With 9.1 Preview 368 9.2 Sorting Algorithms 369 A Context for Sorting 369 Count Sort 373 Bubble Sort 375 Table of Contents ix Select Sort 376 9.3 Improving sorts (Optional) 377 Recursive Sort: Merge Sort 378 Another Merge Sort: the Von Neumann Sort 380 9.4 Searching 387 Binary Search 387 9.5 Implementing Stacks and Queues 391 StackLib: Stack as an Abstract Data Type 391 Dynamic Stacks 395 QueueLib 397 Big Cardinals 400 SetLib: Stack of Strings 404 9.6 Trees 407 9.7 Chapter 9 Review 412 9.8 Chapter 9 Problems 412 9.9 Chapter 9 Programming Projects 415 Queue Abstract Data Type 415 PES: Performance Evaluation of Sorts 416 VS: Visual Sorts 418 Chapter 10 The Seven Step Method 10.1 Method: Part II 425 The Seven Step Method 425 10.2 Design Stage: Acme Payroll System 426 1. Problem Definition 426 Problem Definition Application 426 2. Solution Design 427 Solution Design Application 427 3. Solution Refinement 428 Solution Refinement Application 428 4. Testing Strategy Development 429 Testing Strategy Development Application 429 10.3 Implementation Stage: Acme Payroll System 431 5. Program Coding and Testing 431 Case Study: The Acme Payroll System 432 6. Documentation Completion 444 Documentation Completion Application 444 7. Program Maintenance 445 Program Maintenance Application 445 10.4 An Advanced Case Study: Building a Text Index 445 Design Stage 446 1. Problem Definition 446 2. Solution Design 446 3. Solution Refinement 447 x Table of Contents Binary Search Tree Unit 449 Queues Unit 451 Implementation Stage 452 4. Testing Strategy Development 452 5. Program Coding and Testing 453 6. Documentation 463 7. Program Maintenance 463 10.5 Chapter 10 Review 464 10.6 Chapter 10 Programming Problems 464 1. Editor Application 464 2. Typing 470 3. Calculator Applications 472 10.7 Chapter 10 Programming Projects 473 10.8 Level 1 — Getting Started 473 1–1. General 474 A Guessing Game 474 1–2. Business 474 Computing a Customer's Change 474 1–3. Scientific 475 A Bouncing Ball 475 10.9 Level 2 — Getting Organized with Procedures 477 2–1. General 477 Your Age in Days 477 2–2 Business 477 What’s the Cost of My Mortgage? 477 2–3 Scientific 478 Solving the Quadratic Equation 478 10.10 Level 3 — Getting Fancier with Parameters 479 3–1. General 479 Count the Word Occurrences in a Text 479 Processing Personnel Data 480 3–3. Scientific 481 Plotting a Function 481 10.11 Level 4 — Getting Your Wings with Units 483 4–1 General 483 The Kwic Index 483 4–2 Business 484 Information Retrieval 484 4–3 Scientific 486 Complex Algebra 486 [...]... the material described applies equally to all computers It aims to introduce you to the practice of programming Section 1.2 1.2 Introduction to Programming Practice: Pascal 15 Introduction to Programming Practice: Pascal A Global View The goal of this book is to teach you how to program computers using the Pascal programming language However, learning to write computer programs is very much like learning... obstacles and outlines the new terrain by introducing the Programming Practice: Pascal in three subsections: • A Global View describes the layout of the text book’s material in very general detail This sub-section also offers an idea of the way in which the Programming Practice: Pascal should be used with its companion book: the Principles of Programming • The Road Ahead gives a very brief synopsis... Preview 14 Introduction to Programming Practice: Pascal 15 A Global View 15 The Road Ahead .15 Signs Along the Road 16 Hardware: Computers and Peripherals 17 The CPU 18 Other Components and Packaging 19 The World of Programming 20 What is Programming? 20 “Real world” and “Abstract World” 20 Pascal .21 An example Pascal program .22 Running... principles upon which the craft is based and then practice, practice, practice For example, you can read all the books ever published about riding a bicycle but, until you actually get on one and start pedaling on your own, you will not know how to ride a bicycle The same applies to computer programming! Here, we provide the second book, the Programming Practice: Pascal, which assumes that you have already... chapter of the Programming Practice: Pascal A synopsis of each chapter is presented so that you can visualize the road ahead • Chapter 2, Computing: A short survey of some applications, this chapter introduces software by giving some examples of packaged programs, applications, which perform specific tasks • Chapter 3, Programming Language: Pascal, in this chapter we further introduce the Pascal programming. ..Preface The purpose behind Programming Practice: Pascal is to teach you how to apply the theories, tools, and concepts mentioned in the Principles book to problem-solving using the Pascal programming language We suggest that you either read the Principles book before beginning this book, or read the two books concurrently While using this book to learn Pascal, you may find that there are too... intends to teach you how to program a computer using the Pascal programming language, using the concepts and topics discussed in the Principles of Programming Although the journey through the Principles of Programming is echoed throughout this book, their are some additional obstacles and terrain that must be dealt with when learning the Pascal programming language This chapter provides you with a guide... forgotten 4 Finally, each chapter ends with a set of Problems and Programming Projects to solve These are the most important parts of each chapter Some chapters contain Programming Problems as well In any case, programming is an intensely practical skill that can only be acquired by practice Remember: Practice makes perfect!” The Principles of Programming, because it is a book which explains a great many... our understanding Some extremely simple Pascal program examples are given as illustrations of the syntax presented Although it will take a few more chapters to introduce all of the Pascal syntax, some other examples of complete Pascal programs are also given in this chapter • Chapter 4, Data and Actions, this chapter continues with the introduction to the Pascal programming language that was started... chapter presents the creation and use of Pascal subprograms, i.e the Pascal procedures and functions Subprograms are often part of libraries, and the chapter introduces the Pascal units that are used to implement libraries • Chapter 8, Pascal Data Structures, in this chapter we consider the three structured data types: arrays, records, and sets, and how they are used in Pascal The main concepts introduced . It aims to introduce you to the practice of programming. Section 1.2 Introduction to Programming Practice: Pascal 15 1.2 Introduction to Programming Practice: Pascal A Global View The goal of. chapter provides an introduction to the Programming Practice: Pascal, an overview of current computing devices and systems, and a brief introduction of Pascal and programming. Being an overview, this. when learning the Pascal programming language. This chapter provides you with a guide to these obstacles and outlines the new terrain by introducing the Programming Practice: Pascal in three subsections: •

Ngày đăng: 23/10/2014, 11:47

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan