Sei sulla pagina 1di 6

INTRODUCTION TO

ENGINEERING PROGRAMMING:
IN C, MATLAB AND JAVA

Mark Austin
Department of Civil Engineering
University of Maryland
College Park, Maryland

David Chancogne
Institute for Systems Research
University of Maryland
College Park, Maryland

John Wiley & Sons, Inc.


New York

Chichester

Weinheim

Brisbane

Singapore

Toronto

CONTENTS

ABOUT THE AUTHORS


PREFACE
ACKNOWLEDGMENTS

PART 1 :

CONCEPTS IN MODERN ENGINEERING COMPUTATIONS


CHAPTER 1 :
1.1
1.2
1.3
1.4
1.5
1.6

Applications of Computers in Engineering


Recent Advances in Computing
Computer Hardware Concepts
Operating System Concepts
Computer Networking Concepts
Review Exercises

CHAPTER 2:
2.1
2.2
2.3
2.4

INTRODUCTION TO
ENGINEERING COMPUTATIONS

PRINCIPLES OF ENGINEERING
SOFTWARE DEVELOPMENT

Hardware-Software Life Cycle


Principles of Engineering Software Design
Computer Programming Language Concepts
Programming Language Selection

in
v
x

1
3
3
4
6
8
9
19

20
20
22
30
34

CONTENTS

XII

PART 2:

PROGRAMMING TUTORIAL
CHAPTER 3:
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8

70
70
71
76
78
81
86
88
91

OPERATORS AND EXPRESSIONS

Arithmetic Operators and Expressions


Assignment Operations
Increment/Decrement Operators
Arithmetic Expressions and Precedence
Mixed Expressions and Data Type Conversions
Bitwise Operations and Applications
Subtractive Cancellation
Programming Exercises

CONTROL OF FLOW

Introduction
Relational and Logical Operands
Selection Constructs
Iteration Constructs
Comparison of Looping Constructs
Programming Exercises

CHAPTER 7:
7.1

41
42
42
46
52
62
66
67

BASIC DATA TYPES AND VARIABLES

CHAPTER 6:
6.1
6.2
6.3
6.4
6.5
6.6

41

Basic Data Types in


Characters
Integers
Single and Double Precision Floating Point Numbers
Enumeration Data Types
Variable Attributes: Type, Address, Name, and Value
Variable Naming Conventions
Programming Exercises

CHAPTER 5:
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8

GETTING STARTED

Key Features of
A Little History
Writing and Compiling a Simple Program
Program 3 . 1 : Print Approximate Value of n
Program 3.2: Compute and Print Area of Circle
Compiling and Running Small Programs
Programming Guidelines
Programming Exercises

CHAPTER 4:
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8

39

FUNCTIONS I

Introduction

95

95
96
97
100
107
110
113
116

121
121
121
124
133
142
143

146
146

CONTENTS

XIII

7.2
7.3
7.4
7.5
7.6
7.7
7.8
7.9

Functions Required in a C Program


Writing User-Defined Functions
Case Study Program: Quadratic Equation Solver
Call-by-Value Mechanism for Function Calls
Scope and Storage of Variables and Functions
Packaging of Program Modules
Math Library Functions
Programming Exercises

CHAPTER 8:
1
2
3
8.4
5
6
7
8
9
8.10
8.11
12

CHAPTER 9:
9.1
9.2
9.3
9.4
9.5

FUNCTIONS II

Introduction
Pointers as Function Arguments
Arrays as Function Arguments
String Functions
Programming Exercises

CHAPTER 10:
10.1
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9

ARRAYS AND POINTERS

Need for Arrays and Pointers


Introduction to Arrays
Initializing the Contents of an Array
Character Arrays
Applications of One-Dimensional Arrays
Multidimensional Arrays
Application of Two-Dimensional Arrays
Pointers
Pointer Type, Address, Name, Value, and Indirect Value
Pointer Arithmetic
Relationship between Pointers and Arrays
Programming Exercises

DYNAMIC ALLOCATION OF MEMORY

Need for Dynamic Memory Allocation


Memory Allocation with m a l l o c ( ) , c a l l o c ( ) , and r e a l l o c ()
Deallocating Memory with f r e e ()
Dynamic Allocation of Character Strings
Generic Functions for Dynamic Memory Allocation
A File of Miscellaneous Functions
Dynamic Allocation of One-Dimensional Arrays
Dynamic Allocation of Two-Dimensional Arrays
Programming Exercises

148
148
151
162
165
173
175
181

184
184
185
188
190
193
208
21 1
217
217
223
225
232

241
241
241
246
252
262

266
266
267
270
27 1
273
274
278
283
294

CONTENTS

xiv

CHAPTER I I :
11.1
11.2

CHAPTER 12:
12.1
12.2
12.3
12.4
12.5
12.6
12.7
12.8

PART 3:

THE PREPROCESSOR

Compiling Multiple File Programs


Capabilities of the Preprocessor

INPUT AND OUTPUT

Basic Concepts
Using p r i n t f O for Buffered Output
Using s c a n f () for Buffered Input
File Input/Output
Program 12.1: Statistics of Weekly Rainfall
Reading Datasets from an Input File
Program 12.2: Memory Reallocation for Datasets
Programming Exercises

MATLAB PROGRAMMING TUTORIAL


CHAPTER 13:
13.1
13.2
13.3
13.4
13.5
13.6
13.7
13.8

CHAPTER 14:
14.1
14.2
14.3
14.4
14.5
14.6
14.7
14.8

MATLAB GRAPHICS

Simple Two-Dimensional Plotting


Three-Dimensional Plots
Mesh and Surface Plotting
Contour Plots
Subplots
Hard Copies of MATLAB Graphics
Preparing MATLAB Graphics for the World Wide Web
Programming Exercises

CHAPTER 15:
15.1
15.2
15.3
15.4
15.5

INTRODUCTION TO MATLAB

Getting Started
Variables and Variable Arithmetic
Matrices and Matrix Arithmetic
Control Structures
General-Purpose Matrix Functions
Program Development with M-Files
Engineering Applications
Programming Exercises

SOLUTION OF LINEAR MATRIX EQUATIONS

Systems of Linear Matrix Equations


Case Study Problem: Three Linear Matrix Equations
Singular Systems of Matrix Equations
Engineering Applications
Programming Exercises

300
300
302

309
309
310
316
319
322
326
328
334

337
339
339
342
351
367
372
375
382
402

408
408
417
418
421
423
424
425
425

430
430
434
436
437
457

CONTENTS

PART 4:

xv

JAVA PROGRAMMING TUTORIAL


CHAPTER 16:
16.1
16.2
16.3

CHAPTER 17:
17.1
17.2
17.3
17.4

THE JAVA LANGUAGE

Getting Started
Program 18.1: "Peace on Earth" Stand-Alone Program
Program 18.2: "Peace on Earth" Java Applet Program
Primitive Data Types
Java Variables
Expressions
Control Statements
Classes and Objects
Class Libraries and Methods
Arrays
Program 18.3: Compute Roots of Quadratic Equation
Program 18.4: Point and Line Segment Operations
Programming Exercises

CHAPTER 19:
19.1
19.2
19.3
19.4
19.5
19.6
19.7
19.8
19.9

OBJECT-ORIENTED PROGRAM DESIGN

Fundamental Concepts
Object-Oriented Software Development
Is Java Object-Oriented?
Review Exercises

CHAPTER 18:
18.1
18.2
18.3
18.4
18.5
18.6
18.7
18.8
18.9
18.10
18.11
18.12
18.13

INTRODUCTION TO JAVA

JavaA Little History


The "Famous" Java Buzzwords
Java and the Internet

JAVA GRAPHICS

Introduction
The Java Abstract Windowing Toolkit
AWT Components and Containers
AWT Graphics
AWT Layout Managers
AWT I/O Components
Handling AWT Events
Engineering Applications
Programming Exercises

465
467
467
468
476

481
481
483
488
489

490
490
492
497
501
502
505
506
510
521
527
529
538
548

554
554
555
558
562
569
571
580
590
614

APPENDIX I :

INTRODUCTION TO UNIX

621

APPENDIX 2:

THE STANDARD LIBRARY

629

REFERENCES

649

INDEX

651

Potrebbero piacerti anche