Tải bản đầy đủ (.pdf) (946 trang)

Software Solutionsfor for engineers and scientist ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (4.95 MB, 946 trang )

Software
Solutions
for
Engineers
and
Scientists
• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •
• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •
43021_FM.indd 1 9/10/07 10:10:34 AM
43021_FM.indd 2 9/10/07 10:10:34 AM
CRC Press is an imprint of the
Taylor & Francis Group, an informa business
Boca Raton London New York
Software
Solutions
for
Engineers
and
Scientists
Julio Sanchez
Maria P. Canton
• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •
• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •
43021_FM.indd 3 9/10/07 10:10:34 AM
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487‑2742
© 2008 by Taylor & Francis Group, LLC
CRC Press is an imprint of Taylor & Francis Group, an Informa business


No claim to original U.S. Government works
Printed in the United States of America on acid‑free paper
10 9 8 7 6 5 4 3 2 1
International Standard Book Number‑13: 978‑1‑4200‑4302‑0 (Hardcover)
This book contains information obtained from authentic and highly regarded sources. Reprinted material is quoted
with permission, and sources are indicated. A wide variety of references are listed. Reasonable efforts have been made to
publish reliable data and information, but the author and the publisher cannot assume responsibility for the validity of
all materials or for the consequences of their use.
No part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or
other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any informa‑
tion storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://
www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC) 222 Rosewood Drive, Danvers, MA 01923,
978‑750‑8400. CCC is a not‑for‑profit organization that provides licenses and registration for a variety of users. For orga‑
nizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation without intent to infringe.
Library of Congress Cataloging‑in‑Publication Data
Sanchez, Julio, 1938‑
Software solutions for engineers and scientists / authors, Julio Sanchez and Maria P. Canton.
p. cm.
Includes bibliographical references and index.
ISBN 978‑1‑4200‑4302‑0 (alk. paper)
1. Engineering‑‑Data processing. 2. Science‑‑Data processing. I. Canton, Maria P. II. Title.
TA345.S31535 2008
620’.0285‑‑dc22 2007034749
Visit the Taylor & Francis Web site at

and the CRC Press Web site at


43021_FM.indd 4 9/10/07 10:10:34 AM
Table of Contents
Preface xxiii
PART I — TECHNIQUES AND CODE
Chapter 1 — Computer Number Systems
Chapter Summar y 3
1.0 Counting 3
1.0.1 The Tally System 3
1.0.2 Roman Numerals 4
1.1 The Origins of Our Number System 5
1.1.1 Number Systems for Digital-Electronics 6
1.1.2 Positional Characteristics 7
1.1.3 Radix or Base 7
1.2 Types of Numbers 8
1.2.1 Whole Numbers 8
1.2.2 Signed Numbers 8
1.2.3 Rational and Irrational Numbers 8
1.2.4 Real and Complex Numbers 9
1.3 Radix Representations 10
1.3.1 Decimal Versus Binary Numbers 10
1.3.2 Octal and Hexadecimal Numbers 11
1.4 General Theor y of Counting 12
1.5 Assembly Language Conversion Routines 14
1.5.1 Binar y-to-ASCII-Decimal Conversion 15
1.5.2 Binar y-to-Hexadecimal Conversion 18
1.5.3 Decimal-to-Binar y Conversion 19
1.6 C++ Conversion Routines 23
1.6.1 C++ Binary-to-ASCII Conversions 23
1.6.2 C++ ASCII-to-Binary Conversions 25
Chapter 2 — Numeric Data in Memory

Chapter Summar y 31
2.0 Electronic-Digital Machines 31
2.1 Storage of Numer ical Data 32
2.1.1. Word Size 32
2.2 Integer Encodings 33
2.2.1 Sign-Magnitude Representation 34
2.2.2 Radix Complement Representation 35
2.3 Encoding of Fractional Numbers 39
2.3.1 Fixed Point Representations 40
v
2.3.2 Floating-Point Representations 41
2.4 Standardized Floating-Point Encodings 42
2.4.1 ANSI/IEEE 754 Single For mat 42
2.4.2 Floating-Point Exponent in ANSI/IEEE 754 Single Format 43
2.4.3 Floating-Point Significand in ANSI/IEEE 754 Single For mat 44
2.4.4 Decoding Floating-Point Numbers 45
2.5 Binar y-Coded Decimals (BCD) 49
2.5.1 Floating-Point BCD 49
2.6 BCD Conversions 51
2.6.1 BCD Conversion Functions 51
Chapter 3 — Machine Arithmetic
Chapter Summar y 55
3.0 Intel Microprocessors 55
3.0.1 CPU Flags 56
3.1 Logical Instructions 57
3.1.1 Logical AND 58
3.1.2 Logical OR 59
3.1.3 Logical XOR 59
3.1.4 Logical NOT 60
3.2 Arithmetic Instr uctions 60

3.2.1 Signed and Unsigned Arithmetic 60
3.2.2 Operations on Decimal Numbers 61
3.3 Auxiliary and Bit Manipulation Instr uctions 63
3.3.1 Bit Shift and Rotate Instructions 63
Bit Shift Instructions 63
Bit Rotate Instructions 66
Double Precision Shift Instr uctions 67
Shift and Rotate Addressing Modes 68
3.3.2 Comparison, Bit Scan, and Bit Test Instr uctions 68
Signed and Unsigned Conditional Jumps 70
3.3.3 Increment, Decrement, and Sign Extension Instructions 71
3.3.4 486 and Pentium Proprietar y Instr uctions 72
BSWAP 72
XADD 73
CMPXCHG and CMPXCHG8B 74
3.4 CPU Identification 74
Chapter 4 — High-Precision Arithmetic
Chapter Summar y 79
4.0 Applications of BCD Arithmetic 79
4.0.1 ANSI/IEEE 854 Standard 80
4.1 Algorithms for BCD Ar ithmetic 81
4.2 Floating-Point BCD Addition 82
4.3 Floating-Point BCD Subtraction 82
4.4 Floating-Point BCD Multiplication 83
4.5 Floating-Point BCD Division 85
4.6 C++ BCD Arithmetic Functions 86
4.6 High-Precision BCD Arithmetic 90
vi
Table of Contents
Chapter 5 — Floating-Point Hardware

Chapter Summar y 95
5.0 A Mathematical Coprocessor 95
5.1 Intel Math Units 96
5.1.1 Math Unit Applications 97
5.1.2 Math Unit Limitations 98
5.1.3 Processor/Coprocessor Interface 99
5.1.4 Math Unit Versions 100
8087 101
80287 101
80387 102
5.1.5 The Numeric Unit in 486 and Pentium CPU 102
5.2 Detecting and Identifying the Math Unit 102
5.3 ANSI/IEEE 754 Standard 106
5.3.1 Numeric Data Encoding 107
5.3.2 Rounding 109
5.3.3 Inter val Arithmetic 110
5.3.4 Treatment of Infinity 110
5.3.5 Not a Number (NaN) 112
Signaling and Quiet NaNs 112
5.3.6 Exceptions 11 3
Invalid Operation Exception 113
Division by Zero Exception 114
Overflow Exception 114
Underflow Exception 115
Inexact Result Exception 116
Chapter 6 — Floating Point Data and Conversions
Chapter Summar y 117
6.0 Math Unit Data Formats 117
6.0.1 Binary Integers 118
6.0.2 Decimal Integers 119

6.0.3 Binar y Reals 120
6.1 Special Encodings for Reals 121
6.2 Low-Level Numer ic Data in Memor y 123
6.2.1 Initializing Data with the DW Directive 124
6.2.2 Initializing Data with DD and DQ Directives 124
6.2.3 Initializing Data with the DT Directive 125
6.2.4 Memor y Image of the Special Encodings 125
6.2.5 Operating on Memory Variables 126
6.3 High-Level Numeric Data 127
6.4 Numeric Data Conversions 127
6.4.1 Data Conversion in ANSI/IEEE 754 128
6.4.2 Conversion Requirements in ANSI/IEEE 754 128
6.4.3 FPU_INPUT Procedure 130
Calculating 10
y
131
Post-Conversion Operations 132
6.4.4 FPU_OUTPUT Procedure 132
6.4.5 ASCII-to-Exponential Conversion 133
6.5 High-Level Interface Functions 133
Table of Contents
vii
Chapter 7 — Math Unit Architecture and Instruction Set
Chapter Summar y 137
7.0 Math Unit Inter nal Organization 137
7.0.1 Math Unit Register Stack 137
7.0.2 Math Unit Control Register 140
Error Conditions 141
7.0.3 Math Unit Status Register 143
7.0.4 The Environment Area 150

Tag Word Register 152
Instruction and Data Pointers 154
7.0.5 Math Unit State Area 156
7.1 Math Unit Instruction Patterns 158
7.1.1 Register Operands 158
7.1.2 Memor y Operands 159
7.2 Math Unit Instruction Set 159
7.2.1 Data Transfer Instr uctions 160
7.2.2 Nontranscendental Instr uctions 161
Basic Arithmetic 161
Scaling and Square Root 162
Partial Remainder 163
Update of the P artial Remainder 166
Manipulating the Encoding 168
7.2.3 Comparison Instructions 171
7.2.4 Transcendental Instructions 172
Transcendental Algorithms 174
7.2.5 Constant Instructions 177
7.2.6 Processor Control Instr uctions 178
Chapter 8 — Transcendental Primitives
Chapter Summar y 181
8.0 Developing Math Unit Software 181
8.1 Exponential Functions 182
8.1.1 Calculation of Powers 183
Logarithmic Approximation of Exponentials 184
Binar y Powering 186
Exponent Factoring 190
Applications 198
Mixed Methods 198
8.2 Math Unit Tr igonometr y 199

8.2.1 Angular Conversions 199
8.2.2 Range-Scaling Operations 201
Reduction to the Unit Circle 201
Reduction to the First Octant 202
8.2.3 Trigonometr ic Functions 204
Calculating Tangent, Sine, and Cosine 205
Trigonometr ic Arcfunctions 207
8.4 Logarithms 211
8.4.1 Calculating Natural and Common Logarithms 211
8.4.2 Calculating Antilogarithms 212
8.5 C++ Interface to Transcendentals 213
viii
Table of Contents
Chapter 9 — General Mathematical Functions
Chapter Summar y 215
9.0 Calculator Operations 215
9.0.1 Calculating Hyperbolic Functions 216
9.0.2 Factorial 220
9.0.3 Ordering Numeric Data 221
9.0.4 Calculating the Modulus 224
9.0.5 Integer and Fractional Parts 225
9.0.6 Solving Triangles 227
9.1 Quadratic Equations 229
9.2 Imaginar y and Complex Numbers 232
9.2.1 Operations in Complex Arithmetic 233
9.2.2 Real and Complex Roots of a Quadratic Equation 240
9.2.3 Polar and Cartesian Coordinates 244
Chapter 10 — Financial Calculations
Chapter Summar y 249
10.0 Interest Calculations 249

10.0.1 Simple Interest 249
10.0.2 Compound Interest 251
Future Value at Compound Interest 252
Exponentials in Financial Formulas 253
Present Value at Compound Interest 254
Effective Rate 256
10.1 Amor tization 257
10.1.1 Periodic Payment Calculations 257
10.1.2 Add-On Interest 259
10.1.3 Annual Percentage Rate 261
10.2 Annuities 263
10.2.1 Annuity Future Value 263
10.2.2 Annuity Present Value 265
10.2.3 Annuity Due 266
10.2.4 Sinking Fund 269
10.2.5 Number of Compounding Periods 271
10.3 Numerical Errors in Financial Calculations 272
10.3.1 Conversion Errors 273
10.3.2 Representation Errors 273
10.3.3 Precision and Computation Errors 274
Cancellation Error 275
10.4 Financial Software 275
Chapter 11 — Statistical Calculations
Chapter Summar y 277
11.0 About Statistical Data 277
11.0.1 Data-Type-Flexible Coding 278
11.1 Data Manipulation Primitives 278
11.1.1 Common Summations 278
11.1.2 Sor ting 280
11.2 Counting Techniques 281

Table of Contents
ix
11.2.1 Per mutations 282
11.2.2 Combinations 283
11.2.3 Binomial Probability 285
11.3 Measures of Central Tendency 286
11.3.1 Mean 287
11.3.2 Median 287
11.3.3 Midrange 288
11.3.4 Mode 289
11.3.5 Weighted Measures of Central Tendency 292
11.4 Measures of Dispersion 294
11.4.1 Range 294
11.4.2 Variance 295
11.4.3 Standard Deviation 296
11.5 Normal Distribution 297
11.5.1 Normal Curve 297
Standard Nor mal Cur ve 298
11.5.2 Calculating f(x) 299
11.5.3 Probability in Nor mal Distribution 301
11.6 Linear Correlation and Regression 304
11.6.1 Linear Correlation Coefficient 305
11.6.2 Linear Regression Analysis 307
Chapter 12 — Interpolation, Differentiation, and Integration
Chapter Summar y 311
12.0 Inter polation 311
12.0.1 Linear Interpolation 313
12.0.2 Lagrange Inter polation 316
12.0.3 Least-Squares Interpolation 319
Linear Models 319

Calculating the Error Sum 321
Least-Squares Linear Inter polation Function 321
Non-Linear Models 323
12.1 Numerical Differentiation 327
12.2 Numerical Integration 332
12.2.1 Integration by the Trapezoidal Rule 333
12.2.2 Integration by Simpson's Rule 336
Chapter 13 — Linear Systems
Chapter Summar y 341
13.0 Linear Equations 341
13.0.1 Systems of Linear Equations 342
13.0.2 Matrix Representations of Linear Systems 344
13.1 Numeric Data in Matr ix Form 345
13.1.1 Matrices in C++ 345
13.1.2 Locating a Matr ix Entry 348
13.2 Operations on Matr ix Entries 349
13.2.1 Vectors 350
13.2.2 Vector-by-Scalar Operations in C++ 350
13.2.3 Low-Level Vector-by-Scalar Operations 352
13.2.4 Matrix-by-Scalar Operations 357
x
Table of Contents
13.2.5 Matrix-by-Matrix Operations 359
Matrix Addition 360
Matrix Multiplication 363
13.3 The Solution of a Linear System 368
13.3.1 Gauss-Jordan Elimination 368
13.3.2 Errors in Gaussian Elimination 370
13.4 A Gauss-Jordan Algorithm 371
13.5 Solution of a Linear System 372

Chapter 14 — Solving and Parsing Equations
Chapter Summar y 375
14.0 Function Mapping 375
14.1 Developing a Parser 377
14.2 Evaluating User Equations 379
14.2.1 Equation Grammar 379
14.2.2 Equation Syntax 380
14.2.3 Symbol Table and Numeric Data 381
14.3 An Equation-Solving Algorithm 382
14.3.1 The _EVALUATE Procedure 382
14.3.2 _CALCULATE_Y Procedure 386
Chapter 15 — Neural Networks
Chapter Summar y 389
15.0 Reverse-Engineering the Brain 389
15.0.1 The Biological Neuron 389
15.0.2 The Artificial Neuron 391
15.0.3 Ar tificial Neural Networ ks 394
15.1 The Network as a Classifier 396
15.1.1 Multiple-Node Networks 396
15.1.2 Software Model for Neural Nets 398
15.2 The Perceptron 398
15.2.1 Perceptron as a Classifier 399
15.2.2 Perceptron Lear ning 400
15.2.3 Training the Perceptron 402
15.2.4 A Perceptron Function 403
15.3 The Adaline 405
15.3.1 Widrow-Hoff Lear ning 405
15.3.2 A Neuron for Adaline 406
15.4 Improving the Classification Function 409
15.4.1 Calculating the Error Sum 409

15.4.2 Improving Perceptron Results 410
15.5 Backpropagation Networks 412
15.5.1 Nonlinear Neurons 413
15.5.2 Backpropagation Algorithm 414
15.5.3 Software Model for Backpropagation 415
15.5.4 Executing the Network 417
15.5.5 A Backpropagation Trainer 418
Table of Contents
xi
PART II — APPLICATION DEVELOPMENT
Chapter 16 — The C++ Language on the PC
Chapter Summar y 423
16.0 Introducing C++ 423
16.0.1 Evolution of C++ 423
16.0.2 Advantages of the C++ Language 424
16.0.3 Disadvantages of the C++ Language 424
16.1 PC Implementations of C and C++ 425
16.2 Flowcharts and Software Design 425
16.3 The C++ Console Application 427
Chapter 17 — Event-Driven Programming
Chapter Summar y 431
17.0 Graphical Operating Systems 431
17.1 Enter Windows 432
17.1.1 Text-based and Graphical Programs 432
17.1.2 Graphics Ser vices 434
17.2 Programming Models 434
17.2.1 Event-Driven Programs 434
The Event Manager 436
The Event Handler 436
17.2.2 Event Types 436

System Events 436
Control Events 437
Program Events 437
17.2.3 Event Modeling 437
17.3 File Structure of a Windows Program 438
17.3.1 Source Files 438
17.3.2 Library Files 439
17.3.3 Resource Files 440
17.3.4 Make Files 440
17.3.5 Object Files 441
17.3.6 Executable Files 442
17.3.7 Dynamic Linking 444
Chapter 18 — The Window Program Components
Chapter Summar y 447
18.0 “Hello, World” 447
18.1 Naming Conventions 449
18.2 Constants and Handles 451
18.2.1 Windows Handles 452
18.3 Visual Elements 453
18.3.1 The Main Window 453
18.3.2 Controls 454
18.3.3 Other Visual Components 455
18.4 Programming Style 456
18.4.1 Commented Headers 456
xii
Table of Contents
18.4.2 Asser tions Notation 457
ASSERT 458
INV 458
PRE and POST 458

FCTVAL 458
18.4.3 Programming Templates 458
Chapter 19 — A First Windows Program
Chapter Summar y 463
19.0 Preliminar y Steps 463
19.1 The Program Project 464
19.1.1 Creating a Project 464
19.2 Elements of a Windows Program 468
19.2.1 WinMain() 468
Parameters 469
19.2.2 Data Var iables 470
19.2.3 WNDCLASSEX Structure 471
19.2.4 Registering the Windows Class 475
19.2.5 Creating the Window 476
19.2.6 Displaying the Window 480
19.2.7 The Message Loop 480
19.3 The Window Procedure 481
19.3.1 Windows Procedure Parameters 482
19.3.2 Windows Procedure Var iables 483
19.3.3 Message Processing 483
WM_CREATE Message Processing 484
WM_PAINT Message Processing 484
WM_DESTROY Message Processing 485
19.3.4 The Default Windows Procedure 485
19.4 The WinHello Program 486
19.4.1 Modifying the Program Caption 486
19.4.2 Displaying Text in the Client Area 487
19.4.3 Creating a Program Resource 489
19.4.4 Creating the Icon Bitmap 490
19.5 WinHello Program Listing 493

Chapter 20 — Text Display
Chapter Summar y 497
20.0 Text in Windows 497
20.1 The Client Area 498
20.2 Device and Display Contexts 498
20.2.1 The Display Context 499
20.2.2 Display Context Types 500
20.2.3 Window Display Context 502
20.3 Mapping Modes 502
20.3.1 Screen and Client Area 503
20.3.2 Viewport and Window 504
20.4 Programming Text Operations 505
20.4.1 Typefaces and Fonts 507
20.4.2 Text Formatting 508
Table of Contents
xiii
20.4.3 Paragraph Formatting 511
20.4.4 The DrawText() Function 515
20.5 Text Graphics 518
20.5.1 Selecting a Font 518
20.5.2 Drawing with Text 523
Chapter 21 — Keyboard and Mouse Programming
Chapter Summar y 525
21.0 Keyboard Input 525
21.1 Input Focus 526
21.1.1 Keystroke Processing 527
21.1.2 Determining the Key State 529
21.1.3 Character Code Processing 530
21.1.4 Keyboard Demonstration Program 531
21.2 The Caret 534

21.2.1 Caret Processing 535
21.2.2 Caret Demonstration Program 535
21.3 Mouse Programming 538
21.3.1 Mouse Messages 539
21.3.2 Cursor Location 541
21.3.3 Double-Click Processing 542
21.3.4 Capturing the Mouse 543
21.3.5 The Cursor 543
21.4 Mouse and Cursor Demonstration Program 546
Chapter 22 — Graphical User Interface Elements
Chapter Summar y 549
22.0 Window Styles 549
22.1 Child Windows 550
22.1.1 Child Windows Demonstration Program 552
22.2 Basic Controls 554
22.2.1 Communicating with Controls 558
22.2.2 Controls Demonstration Program 563
22.3 Menus 566
22.3.1 Creating a Menu 568
22.3.2 Menu Item Processing 56 9
22.3.3 Shor tcut Keys 570
22.3.4 Pop-Up Menus 571
22.3.5 The Menu Demonstration Program 573
22.4 Dialog Boxes 573
22. 4. 1 Modal and Modeless 574
22. 4. 2 The Message Bo x 574
22.4.3 Creating a Modal Dialog Box 576
22.4.4 Common Dialog Boxes 578
22.4.5 The Dialog Box Demonstration Program 581
22.5 Common Controls 581

22.5.1 Common Controls Message Processing 582
22.5.2 Toolbars and ToolTips 583
22.5.3 Creating a Toolbar 584
22.5.4 Standard Toolbar Buttons 589
xiv
Table of Contents
22.5.5 Combo Box in a Toolbar 591
22.5.6 ToolTip 592
Chapter 23 — Drawing Lines and Curves
Chapter Summar y 597
23.0 Drawing in a Window 597
23.1 The Redraw Responsibility 598
23.1.1 The Invalid Rectangle 599
23.1.2 Screen Updates On-Demand 600
23.1.3 Intercepting WM_PAINT 600
23.2 The Graphics Device Interface 602
23.2.1 Device Context Attributes 603
23.2.2 DC Info Demonstration Program 607
23.2.3 Color in the Device Context 610
23.3 Graphic Objects and GDI Attr ibutes 611
23.3.1 Pens 611
23.3.2 Brushes 613
23.3.3 Foreground Mix Mode 615
23.3.4 Background Modes 617
23.3.5 Current Pen Position 617
23.3.6 Arc Direction 618
23.4 Pixels, Lines, and Cur ves 618
23.4.1 Pixel Operations 619
23.4.2 Drawing with LineTo() 620
23.4.3 Drawing with PolylineTo() 621

23.4.4 Drawing with Polyline() 621
23.4.5 Drawing with PolyPolyline() 622
23.4.6 Drawing with Arc() 623
23.4.7 Drawing with ArcTo() 624
23.4.8 Drawing with AngleArc() 6 24
23.4.9 Drawing with PolyBezier() 626
23.4.10 Drawing with PolyBezierTo() 629
23.4.11 Drawing with PolyDraw() 629
23.4.12 Pixel and Line Demonstration Program 633
Chapter 24 — Drawing Solid Figures
Chapter Summar y 635
24.0 Closed Figures 635
24.1. Closed Figure Elements 636
24.1.1 Brush Origin 636
24.1.2 Object Selection Macros 638
24.1.3 Polygon Fill Mode 638
24.1.4 Creating Custom Br ushes 640
24.2 Drawing Closed Figures 642
24.2.1 Drawing with Rectangle() 643
24.2.2 Drawing with RoundRect() 643
24.2.3 Drawing with Ellipse() 644
24.2.4 Drawing with Chord() 645
24.2.5 Drawing with Pie() 646
24.2.6 Drawing with Polygon() 647
Table of Contents
xv
24.2.7 Drawing with PolyPolygon() 649
24.3 Operations on Rectangles 650
24.3.1 Drawing with FillRect() 650
24.3.2 Drawing with FrameRect() 652

24.3.3 Drawing with DrawFocusRect() 652
24.3.4 Auxiliary Operations on Rectangles 653
24.3.5 Updating the Rectangle() Function 659
24.4 Regions 660
24.4.1 Creating Regions 661
24.4.2 Combining Regions 664
24.4.3 Filling and Painting Regions 666
24.4.4 Region Manipulations 667
24.4.5 Obtaining Region Data 670
24.5 Clipping Operations 671
24.5.1 Creating or Modifying a Clipping Region 672
24.5.2 Clipping Region Information 67 5
24.6 Paths 676
24.6.1 Creating, Deleting, and Conver ting Paths 678
24.6.2 Path-Render ing Operations 679
24.6.3 Path Manipulations 681
24.6.4 Obtaining Path Information 684
24.7 Filled Figures Demo Program 685
Chapter 25 — Displaying Bit-Mapped Images
Chapter Summar y 687
25.0 Raster and Vector Graphics 687
25.1 The Bitmap 688
25.1.1 Image Processing 689
25.1.2 Bitblt Operations 690
25.2 Bitmap Constructs 691
25.2.1 Windows Bitmap For mats 691
25.2.2 Windows Bitmap Structures 691
25.2.3 The Bitmap as a Resource 691
25.3 Bitmap Programming Fundamentals 693
25.3.1 Creating the Memor y DC 693

25.3.2 Selecting the Bitmap 693
25.3.3 Obtaining Bitmap Dimensions 694
25.3.4 Blitting the Bitmap 695
25.3.5 A Bitmap Display Function 697
25.4 Bitmap Manipulations 698
22.4.1 Hard-Coding a Monochrome Bitmap 699
25.4.2 Bitmaps in Heap Memory 701
25.4.3 Operations on Blank Bitmaps 706
25.4.4 Creating a DIB Section 708
25.4.5 Creating a Pattern Br ush 713
25.5 Bitmap Transformations 714
25.5.1 Patter n Brush Transfer 714
25.5.2 Bitmap Stretching and Compressing 715
25.6 Bitmap Demonstration Program 719
xvi
Table of Contents
PART III — PROJECT ENGINEERING
Chapter 26 — Fundamentals of Systems Engineering
Chapter Summar y 723
26.0 What Is Software Engineer ing 723
26.0.1 The Programmer as an Ar tist 725
26.1 Software Characteristics 725
26.1.1 Software Qualities 726
Correctness 726
Reliability 726
Robustness 727
Efficiency 727
Verifiability 728
Maintainability 728
User Fr iendliness 728

Reusability 729
Por tability 729
Other Proper ties 729
26.1.2 Quality Metrics 730
26.2 Principles of Software Engineering 730
26.2.1 Rigor 731
26.2.2 Separation of Concerns 733
26.2.3 Modularization 734
26.2.4 Abstraction and Infor mation Hiding 735
26.2.5 Malleability and Anticipation of Change 736
26.2.6 Maximum Generalization 736
26.2.7 Incremental Development 73 7
26.3 Software Engineer ing Paradigms 738
26.3.1 The Waterfall Model 738
26.3.2 Prototyping 740
26.3.3 The Spiral Model 742
26.3.4 A Pragmatic Approach 743
26.4 Concurrent Documentation 744
26.4.1 Objections and Excuses 745
26.4.2 Advantages of Good Documentation 745
Chapter 27 — Description and Specification
Chapter Summar y 747
27.0 System Analysis Phase 747
27.0.1 The System Analyst 748
27.0.2 Analysis and Project Context 749
27.1 The Feasibility Study 750
27.1.1 Risk Analysis 751
Risk Identification 753
Risk Estimation 753
Risk Assessment 753

Risk Management 754
27.1.2 Risk Analysis in a Smaller Project 754
27.1.3 Cost-Benefit Analysis 755
27.2 Requirements Analysis and Specification 757
Table of Contents
xvii
27.2.1 The Requirements Analysis Phase 757
Customer/User Participation 758
The Vir tual Customer 758
27.2.3 The Specifications Phase 758
The Software Specifications Document 760
27.3.4 Formal and Semiformal Specifications 761
27.3.5 Asser tions Notation 762
ASSERT 762
INV 762
PRE and POST 763
27.4 Tools for Process and Data Modeling 764
27.4.1 Data Flow Diagrams 765
Event Modeling 767
27.4.2 Entity-Relationship Diagrams 769
Chapter 28 — The Object-Oriented Approach
Chapter Summar y 773
28.0 Histor y and Chronology 773
28.1 Object-Oriented Fundamentals 774
28.1.1 Problem-Set and Solution-Set 775
28.1.2 Rationale of Object Orientation 776
28.2 Classes and Objects 776
28.2.1 Classes and Data Abstraction 777
28.2.2 Classes and Encapsulation 778
28.2.3 Message Passing 778

28.2.4 Inheritance 779
28.2.5 Polymor phism 780
Abstract Classes 780
28.4 A Notation for Classes and Objects 781
28.5 Example Classification 783
28.6 When to Use Object Orientation 786
28.6.1 Operational Guidelines 786
Chapter 29 — Object-Oriented Analysis
Chapter Summar y 789
29.0 Elements of Object-Oriented Analysis 789
29.0.1 Modeling the Problem-Domain 790
29.0.2 Defining System Responsibilities 790
29.0.3 Managing Complexity 791
Abstraction 791
Encapsulation 791
Inheritance 791
Message Passing 791
29.1 Class and Object Decomposition 792
29.1.1 Searching for Objects 796
29.1.2 Neat and Dirty Classes 796
29.2 Finding Classes and Objects 797
29.2.1 Looking at Class Associations 797
Gen-Spec Structures 798
Multiple Inheritance in Gen-Spec Str uctures 800
xviii
Table of Contents
Whole-Part Structures 800
Compound Structures 802
29.2.2 Looking at Mechanisms and Devices 802
29.2.3 Related Systems 803

29.2.4 Preser ved Data 803
29.2.5 Roles Played 803
29.2.6 Operational Sites 804
29.2.7 Organizational Units 804
29.3 Testing Object Validity 804
29.3.1 Information to Remember 805
29.3.2 Object Behavior 805
29.3.3 Multiple Attributes 805
29.3.4 Multiple Objects 805
29.3.5 Always-Applicable Attr ibutes 806
29.3.6 Always-Applicable Methods 806
29.3.7 Objects Relate to the Problem Domain 806
29.3.8 Derived or Calculated Results 807
29.4 Subsystems 807
29.4.1 Subsystems as Modules 808
Subsystem Cohesion 809
Subsystem Coupling 809
29.5 Attributes 809
29.5.1 Attribute Identification 810
29.5.2 Attributes and Structures 811
29.6 Methods or Ser vices 812
29.6.1 Identifying Methods 812
Object States 812
Required Ser vices 812
29.7 Instance Connections 814
29.7.1 Instance Connection Notation 814
29.8 Message Connections 814
29.8.1 Message Connection Notation 814
29.9 Final Documentation 815
PART IV — APPENDICES

Appendix A — C++ Math Unit Programming
Summar y 819
AA.0 Programming the Math Unit 819
AA.1 MASM Sources in C++ Programs 820
AA.1.1 Sample Code 821
Appendix B — Accuracy of Exponential Functions
Summar y 829
AB.0 Accuracy Calculations 829
Appendix C — C++ Indirection
Summar y 833
Table of Contents
xix
AC.0 Indirection in C++ 833
AC.0.1 Pointer Phobia 833
AC.1 Indirect Addressing 836
AC.2 Pointer Variables 837
AC.2.1 Dangling Pointers 838
AC.2.2 Pointers to Variables 838
Pointer Variable Declaration 838
Pointer Variable Assignment 838
Pointer Variable Dereferencing 839
AC.3 Pointers to Arrays 839
AC.4 Pointers to Structures 840
AC.5 Pointer Arithmetic 842
AC.6 Pointers to Void 843
AC.6.1 Programming with Pointers to Void 845
AC.7 Reference Variables 847
AC.8 Dynamic Memory Allocation in C++ 848
AC.8.1 Dynamic Data 849
AC.8.2 The

New
and
Delete
Operators 850
AC.9 Pointers to Functions 852
AC.9.1 Simple Dispatch Table 854
AC.9.2 Indexed Dispatch Table 856
AC.10 Compounding Indirection 858
Appendix D — Multiple File Programs
Summar y 861
AD.0 Partitioning a Program 861
AD.0.1 Class Libraries 862
AD.0.2 Public and Pr ivate Components 862
AD.0.3 Object-Oriented Class Libraries 863
AD.1 Multifile Support in C++ 864
AD.2 Multilanguage Programming 864
AD.2.1 Naming Conventions 865
AD.2.2 Calling Conventions 866
AD.2.3 Parameter-Passing Conventions 867
AD.2.4 Difficulties and Complications 867
AD.3 Mixing Low- and High-Level Languages 868
AD.3.1 C++ to Assembly Interface 869
AD.4 Sample Interface Programs 869
AD.4.1 Microsoft C-to-Assembly Interface 871
Return Values in Microsoft C++ Compilers 874
AD.4.2 Borland C++ to Assembly Interface 875
AD.4.3 Using Interface Headers 877
Appendix E — The MATH32 Library
Summar y 879
Appendix F — Windows Structures

Summar y 883
xx
Table of Contents
Bibliography 895
Index 903
Table of Contents
xxi

Preface
Our book was conceived as a programming toolkit and a problem-solving resource for
professional engineers and scientists who take on the role of programmers. The
book’s original idea was based on the fact that engineers and scientists often need to
develop software to suit their particular needs, but hardly ever are they “super-
programmers” at the start. On the other hand, the scientist/engineer who becomes an
improvised programmer is often the originator of major software products: who
knows better what the software must accomplish than the person who is an expert in
the field of application and the intended user of the product? Who can better design
and code the bridge-building program than the bridge builder?
At the same time, scientists and engineers are intellectuals, trained in the sci-
ences, with good mathematical backgrounds, and who already know the many com-
plexities involved in scientific and technological calculations. They constitute a
group of readers who do not accept black boxes or unexplained methodologies. Fur-
nishing software and development tools for them requires finding a balance that, on
one hand, does not ignore their scientific, technical, and mathematical competence,
and on the other one, provides practical shortcuts that avoid unnecessary complica-
tions. We have attempted to achieve this balance in our book.
The software requirements of applications intended for engineering and scientific
uses are almost always computational. The typical scientific and engineering pro
-
gram has a strong number-crunching component. But the computational capabilities

of conventional programming languages are limited and often not well documented.
For example, the mathematical functions that are part of the C++ language barely
include the common trigonometric and logarithmic functions. An engineering appli
-
cation that requires calculating a statistical function, or that performs basic differ
-
entiation or integration, cannot be easily developed in this or most other
programming languages. Consequently, the scientist/engineer software developer is
forced to search for or develop algorithms and methods to perform the required cal
-
culations, often ending up with untested, undocumented, and unreliable routines.
Providing these numerical tools has been our primary objective in this book.
But it does not end with the tool, algorithm, or even the canned routine that
solves a computational problem. The engineering or scientific application must exe
-
cute in a modern computer and do so with professional appearance and functional
-
ity. In a very few cases is a minimal, text-based program sufficient for the purpose at
hand. To be effective, the program must execute in a graphical operating system
such as Windows; therefore the engineer/scientist programmer must also have ac
-
cess to these skills.
xxiii
Furthermore, the scientist/engineer programmer must also be capable of ana
-
lyzing and designing the application using state-of-the-art tools and technology.
The “make it up as you go along” approach does not work for digging a mountain
tunnel or for crafting a computer program. This means that project engineering
skills will also be necessary, as they are for any other engineering or scientific en
-

terprise.
Book Structure
The requirements just listed account for the three principal parts of the book. Part I,
titled Techniques and Code, starts at the most elementary level: number systems,
storage of numerical data, and basic machine arithmetic. A discussion of
binary-coded decimal numbers and the development of high-precision arithmetic
routines in floating-point follows. Then come chapters on the Intel math unit archi
-
tecture, data conversions, and the details of math unit programming. With this
framework established, the remainder of the first part is devoted to developing rou
-
tines useful in engineering and scientific code. These routines include general math
-
ematics, financial calculations, statistics, differentiation and integration, linear
systems, equation parsing, and topics in artificial intelligence.
Part II is titled Application Development. Starting with Chapter 16 we cover
the actual implementation of a C++ program on the PC. The first chapter of Part II
is an introduction of the PC implementations of C++, flowcharting as a program
development tool, and the use of Microsoft’s Developer Studio in creating a
text-based program, called a Console Application. The remaining chapters of Part
II are a tutorial on Windows programming. The intention of this part is to provide
essential skills that will allow the reader to create a professional quality program
while avoiding topics and details that have little interest for the engineer/scientist
programmer.
Part III, titled Project Engineering, covers topics quite familiar to the scien
-
tist/engineer programmer since a software product is created following engineer
-
ing principles that are similar to those used in any engineering endeavor. The first
chapter of Part III is an overview of the software engineering field and describes

its most common qualities, principles, and paradigms. This is followed by a dis
-
cussion of the description and specification of software projects. The remainder
of this part is about the object-oriented approach to software development and
the use of object-orientation as an analysis tool. Object-oriented programming
has proven itself in the past 20 years and the scientist/engineer programmer
should have some familiarity with the possible uses of this development model.
The final part of the book contains several appendices that either cover topics
of general interest in the field of scientific programming or provide useful tools
for the developer. Included in the topics covered is an overview of math unit pro
-
gramming, the accuracy of exponential functions, the use of pointers and indirec
-
tion in C++, and the use of multiple files in applications. Also in Part IV is an
appendix listing of all the primitives contained in the MATH32 library furnished in
the book’s software package and an appendix that lists the Windows structures
mentioned in the text.
xxiv
Preface

×