Chapter 3 Slides

# Chapter 3 Slides - Engineering Problem Solving with C...

This preview shows pages 1–10. Sign up to view the full content.

Chapter 3 1 Engineering Problem Solving with C Chapter 3 Control Structures and Data Files

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Chapter 3 2 Algorithms Before writing a program we need to have a thorough understanding of the problem and must carefully plan an approach for solving it While writing a program, we must know what “building blocks” are available and must use good programming principles Computing problems are solved by executing a series of actions in a specific order An algorithm is a procedure in terms of actions to be executed and the order in which these actions are executed The program control specifies the order in which statements are executed
Chapter 3 3 Algorithm Development Top-down design gives an overall description of a problem which is then refined into detailed steps that are easily translated into program code The decomposition outline provides a first definition of of a problem Stepwise refinement breaks the problem into finer-and-finer steps, and involves the use of pseudocode and/or flowcharts Pseudocode is an artificial, informal language that helps us develop algorithms. It is similar to everyday English, and helps us “think out” a program before writing it. Consisting only of executable statements, pseudocode is easy to convert into a corresponding C program

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Chapter 3 4 Structured Programming Early programs of the 1960s followed an undisciplined flow of program control, with indiscriminate transfers within a program (“spaghetti code”). This lead to notorious program failures in the industry. Programs that did initially work often failed with different data sets, and were virtually impossible to fix and maintain afterwards. The major culprit was the goto statement , which allowed the programmer to specify a transfer of control to one of many possible destinations in a program. Structured programming involved, among other things, complete elimination of goto ’s. Bohm and Jacopini (1966) showed that all programs could be written with only 3 control structures: sequence, selection and repetition. With structured programming, programs become clearer, easier to debug and modify and are more likely to be error-free in the first place.
Chapter 3 5 Structured Programming cont’d Sequence Selection Repetition yes no yes no Sequence means program steps are performed one after another. This is built into C and other languages (although execution order can be modified if desired) Selection means the program evaluates an expression to be either true or false . Different sets of statements are executed for true and false. Repetition means that a set of statements is executed over and over until some condition is satisfied as being true or false.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Chapter 3 6 Pseudocode Notation and Flowchart Symbols
Chapter 3 7 Flowchart for Unducted Fan Problem Solution

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Chapter 3 8 Flowchart for Selection Structure If |denominator| <0.0001 print “Denominator close to zero” else set fraction to numerator/denominator print fraction pseudocode:
Chapter 3 9 Flowchart for Repetition Structure

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 132

Chapter 3 Slides - Engineering Problem Solving with C...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online