Codewarrior - Principles of Programming.pdf

(1883 KB) Pobierz
***Prin FM CW7
CodeWarrior
Principles of
Programming
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.
123776148.001.png
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
U.S.A.
Metrowerks Inc.
1500 du College, suite 300
St. Laurent, QC
H4L 5G6 Canada
Metrowerks Corporation
Suite 310
The MCC Building
3925 West Braker Lane
Austin, TX 78759-5321
voice: (514) 747-5999
fax: (514) 747-2822
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
1.1 Preview. ...................................................................14
A Global View.........................................................15
The Road Ahead.......................................................16
Signs Along the Road...............................................17
1.3 Computers. ...............................................................18
A Low Level View...................................................18
Systems and Their Environments...............................19
History of Programming and the Earth.....................21
1.5 Glossary. ..................................................................25
1.6 Problems. .................................................................27
2.1 Preview. ...................................................................30
2.2 Problem Solving and the Computer.. ........................31
Step 1 Problem Definition.......................................32
Step 2 Solution Design............................................33
Step 3 Solution Refinement......................................34
Step 4 Testing Strategy Development.......................35
Step 5 Program Coding and Testing........................36
Step 6 Documentation Completion..........................37
Step 7 Program Maintenance...................................37
Using the Problem Solving Method..........................38
Problems and Plans Dividing and Conquering........38
2.3 Break-Out Diagrams. .................................................39
More on Break-Out Diagrams...................................41
Modifying Algorithms..............................................47
Alternative Algorithms.............................................52
Equivalence of Algorithms........................................53
Testing......................................................................54
2.5 Programming Languages. .........................................56
Communicating Algorithms......................................56
Basic.........................................................................56
Fortran.....................................................................57
Pascal.......................................................................57
Modula-2..................................................................58
C..............................................................................58
iv
Table of Contents
Ada..........................................................................59
Other programming languages.................................59
2.6 Life Cycles Stages of Programming. ........................60
2.8 Glossary.. .................................................................65
2.9 Problems. .................................................................67
3.1 Preview. ...................................................................74
3.2 What Are Algorithms?.. ............................................75
Algorithm Definition................................................75
General Properties of Algorithms..............................75
Desirable Attributes for Algorithms...........................77
Verbal Representations.............................................80
Algebraic Representations (formulas and
expressions).....................................................82
Tabular Representations (tables, arrays, and
matrices)..........................................................86
3.4 Data-Flow Diagrams. ................................................89
Black Boxes vs. Glass Boxes.......................................89
General Data-Flow Diagrams....................................91
Integer Data-Flow Diagrams.....................................94
Logical Data-Flow Diagrams.....................................98
Data Flow Black Boxes..............................................101
More on Data Flow Components and Diagrams........105
3.5 Flow of Control Diagrams. .......................................107
Flowcharts................................................................107
Larger Flowcharts Using Subprograms...................110
Flowblocks...............................................................113
Pseudocode..............................................................115
3.7 Glossary.. .................................................................119
3.8 Problems.. ................................................................121
4.1 Preview. ...................................................................128
The Four Fundamental Forms...................................128
Connecting Several Forms Sequences and Nests.......131
Deep Nesting............................................................133
4.3 Different Algorithms, Same Problem. ........................135
Equivalent Algorithms..............................................135
Table of Contents
v
Alternative Algorithms.............................................137
4.4 Top-down Algorithm Design ....................................140
Job Description Example...........................................144
Change Maker Example............................................145
A Game Example, Fifty.............................................148
Structured Data.........................................................153
Chili Recipe Example................................................155
Card Trick Example..................................................158
Binary Conversion Example......................................159
Guessing Game Example...........................................160
4.6 Review Top Ten Things to Remember. ....................164
4.7 Glossary. ..................................................................166
4.8 Problems.. ................................................................167
5.1 Preview. ...................................................................176
5.2 Programs. .................................................................176
Data for Programs.....................................................176
Actions In Programs.................................................179
5.3 Sequence Forms. .......................................................182
More Programs Using the Sequence Form................183
5.4 Selection Forms. .......................................................185
Simple Selection Forms.............................................185
Proofs of Equivalence for Simple Selection Forms.....187
Larger Selection Forms.............................................189
Proofs of Equivalence for Larger Selection Forms......192
Nested Selections......................................................194
Logical Conditions....................................................198
Using Logical Conditions to Simplify Selections........201
5.5 Repetition Forms.. ....................................................203
The Repeat-Until Form..............................................203
The Disadvantages of Using the Repeat-Until Form...206
The While Loop Form...............................................209
Getting Insights Using Traces and Invariants...........212
5.6 Invocation Forms. ....................................................219
Seconds Example......................................................221
De-militarize Time Example......................................222
5.7 Improving Programs. ...............................................224
Nested Loops and Selections.....................................224
Using Invariants.......................................................229
5.9 Glossary.. .................................................................235
Zgłoś jeśli naruszono regulamin