Pascal_Understanding_Programming_and_Problem_Solving_2ed_1989_Nance.pdf

(37805 KB) Pobierz
Pascal
Und(3rstandiii
Progiramming amd
Probl
em
polvini
SECOND EDmON
Douglas W. Nance
CENTRAL MICHIGAN UNIVERSITY
WEST PUBUSHING COMPANY
ST.PAUL
NEW YORK
LOS ANGELES
SANFRANQSCO
To Helen
Copyeditor and Indexer: Janet Hunter
Interior design: Paula Schlosser and Lucy Leslak
Illustrations: Christine Dettner and Rolin Graphics
Composition: Carlisle Communications
COPYRIGHT ©1984
COPYRIGHT ©1989
By WEST PUBLISHING COMPANY
By WEST PUBLISHING COMPANY
50 W. Kellogg Boulevard
P.O. Box 64526
St. Paul, MN 55164-1003
All rights reserved
Printed in the United States of America
96 95 94 93 92 91 90 89
8 7654 3 2 1 0
Library of Congress Cataloging-in-Publication Data
Nance, Douglas W.
Pascal: understanding programming and problem solving / Douglas
W. Nance.—2nd ed.
p. cm.
Includes index.
ISBN 0-314-43051-2
1. Pascal (Computer program language) I. Title.
QA76.73.P2N35 1989
005.13'3—dcl9
88-29307
CIP
X
Contents
CHAPTER
1
s
Computer Science, Computer
Architecture, and Computer Languages
1.1
1.2
Computer Science: A Preview 1
Computer Architecture 4
A Note of Interest: Microprocessors
Computer Languages
Summary
13
9
8
1.3
A Note of Interest: Why Learn Pascal?
12
CHAPTER
2
■Writing Your First Programs
2.1
14
Program Development—Top-Down Design 15
A Note of Interest: Software Engineering 21
Writing Programs
22
32
A Note of Interest: Blaise Pascal
2.2
2.3
Data Types and Output
Style Tip • 37
Style Tip 42
Summary
45
33
Programming Problems
46
CHAPTER
3 "Arithmetic, Variables, Input, Constants,
and Standard Functions
3.1
Arithmetic in Pascal
47
47
3.2 Using Variables
3.3 Input 59
52
vi
Contents
3.4 Using Constants
68
A Note of Interest: Defined Constants and Space
Shuttle Computing 69
3.5
Standard Functions
71
A Note of Interest: Herman Hollerith
74
Style Tip 78
Summary 78
Programming Problems
80
CHAPTER
4
s
Designing and Writing Complete
Programs
4.1 Writing Code 82
A Note of Interest: Documentation Employment
4.2 Procedures for Output 96
Style Tip 103
4.3 Beginners' Errors
111
82
91
4.4 Mciking a Program Run 120
Style Tip 121
A Note of Interest: Debugging 123
4.5 Writing a Complete Pascal Program 128
A Note of Interest: Debugging or Sleuthing? 130
Summary 136
A Note of Interest: Debugging or Sleuthing: Answers
Programming Problems 138
137
CHAPTER
5
s
Conditional Statements
5.1 Boolean Expressions 145
A Note of Interest: George Boole
5.2 IF ... THEN Statements 156
5.3 IF ... THEN ... ELSE Statements
145
153
164
5.4 Nested IF Statements
169
Style Tip
5.5
173
180
CASE Statements
Style Tip
182
185
A Note of Interest: "Cross-Over" Scholars
5.6 Assertions (Optional) 188
Focus on Programming 189
Running and Debugging Tips 194
Summary 195
Programming Problems 196
CHAPTER
6
s
Looping Statements
6.1 Fixed Repetition Loops 203
Style Tip 211
A Note of Interest: Ada Augusta Byron
203
212
Contents
Vll
6.2 Pretest Loops
214
6.3
6.4
6.5
6.6
A Note of Interest: Debugging Space Flight Programs 222
Posttest Loops 228
A Note of Interest: Charles Babbage 231
Comparison of Loops 235
Nested Loops 239
Style Tip 241
Loops with Conditionals 247
A Note of Interest: A Digital Matter of Life and Death 249
Focus on Programming 253
Running and Debugging Tips 258
Summary
258
Programming Problems
261
chapter
7"Functions and Procedures
7.1 Program Design 264
A Note of Interest: Structured Programming
7.2
Functions
265
^
265
7.3 Procedures
273
A Note of Interest: Ada
283
7.4 Scope of Identifiers 287
7.5 Using Subprograms 297
A Note of Interest: Niklaus Wirth: Pascal to Modula-2
300
7.6 Forward Reference and Nesting 307
Style Tip 308
Focus on Programming 314
Running and Debugging Tips 319
Summary
319
Programming Problems
322
CHAPTER
8"Text Files and User-Defined Data Types
8.1
Text Files
324
324
8.2 TYPE Definitions in Pascal
335
A Note of Interest: The Software System Life Cycle
8.3 Subrange as a Data Type 341
Style Tip 344
8.4 Operations on Ordinal Data Types 346
A Note of Interest: There's a Virus in My Software!
Focus on Programming
Summary
355
339
348
351
Running and Debugging Tips
Programming Problems
357
355
Zgłoś jeśli naruszono regulamin