1 / 12

Computers in Civil Engineering CEE3100 Spring 2002 Lecture #3

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

kay-salas
Download Presentation

Computers in Civil Engineering CEE3100 Spring 2002 Lecture #3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computers in Civil EngineeringCEE3100 Spring 2002Lecture #3 General Programming Concepts

  2. Programming Concepts • General discussion • Class-specific aspects

  3. 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

  4. 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

  5. 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

  6. Debugging & Testing • Types of errors (bugs): • Syntax (spelling) detected by compiler • Semantic (logic) Difficult to detect!

  7. 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?

  8. 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/n Endif ! The denominator may be a big nasty Expression: TEST IT FIRST!

  9. 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????

  10. 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

  11. 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

  12. To Be Continued …(Please read Chapter 2 of Chapra & Canale)

More Related