computers in civil engineering cee3100 spring 2002 lecture #3
DESCRIPTION
Computers in Civil Engineering CEE3100 Spring 2002 Lecture #3. General Programming Concepts. Programming Concepts. General discussion Class-specific aspects. Programming Steps. Clearly identify and understand the problem Clearly identify the desired input and output - PowerPoint PPT PresentationTRANSCRIPT
Computers in Civil EngineeringCEE3100 Spring 2002
Lecture #3
General Programming Concepts
Programming Concepts General discussion Class-specific aspects
Programming Steps Clearly identify and understand the problem Clearly identify the desired input and output Use ‘pseudo-code’ to design your solution
strategy and algorithm Write source code debug, debug, and debug… the source code Test code on cases with known results; revise
source, compile, debug, .., test, … Document code
Algorithm Definition
- A Sequence of Logical Steps Required to Perform a Task
Characteristics- Finite number of steps- Considers all possibilities- Anticipates errors in input data
Program Composition Program
- A sequence of instructions for computer High-level Languages
- FORTRAN. Original “language of engineers”; still popular for heavy-duty number-crunching; not the best for more general work
- Pascal: a well-structured language; starting to be rare- C, C++, Java, Visual Basic: graphics, PC applications
Other - MATLAB, MATHEMATICA, MATHCAD
Debugging & Testing Types of errors (bugs):
- Syntax (spelling) detected by compiler- Semantic (logic) Difficult to detect!
Example – Logic Error
! Calculate arithmetic mean of a vector Dim n As Integer Dim m As Integer
Dim sum As Single,average As Single
Dim A(n) As Single
! (procedures to load A, scalar n) sum = 0.0 For i = 1 To n Sum = Sum + a(i) Next i
average=sum/m! Will the compiler catch this error?
Some advice to avoid much grief:
NEVER divide without first testing that the denominator is non-zero.
If m = 0 then MsgBox “Oops: denominator m=0”else average=sum/nEndif! The denominator may be a big nasty Expression: TEST IT FIRST!
Documentation of Your Work Internal (use of comments): worth its weight in
gold! External
- README files- Messages printed by program- File naming conventions can be self-documenting
You are the main user! Can you understand your work if you pick it
up after five years????
Storage and Maintenance Logical Directory Organization. E.g.:
ehabib/compce/module01/lab
/hw
Make Backups: Keep multiple copies Revisions
- Try to avoid having multiple versions of a code – it only leads to grief
Error-Mitigation Approach to Programming
Algorithm development & analysis Modular design of code Individual testing of code elements Analysis of the solution Explain your code to someone else
To Be Continued …
(Please read Chapter 2 of Chapra & Canale)