Chapter 3 Slides

Chapter 3 Slides - Engineering Problem Solving with C Chapter 3 Control Structures and Data Files 1 Chapter 3 Algorithms • Before writing a

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

View Full Document Right Arrow Icon
Chapter 3 1 Engineering Problem Solving with C Chapter 3 Control Structures and Data Files
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Chapter 3 6 Pseudocode Notation and Flowchart Symbols
Background image of page 6
Chapter 3 7 Flowchart for Unducted Fan Problem Solution
Background image of page 7

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

View Full DocumentRight Arrow Icon
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:
Background image of page 8
Chapter 3 9 Flowchart for Repetition Structure
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/26/2008 for the course ESE 124 taught by Professor Sussman-fort during the Spring '08 term at SUNY Stony Brook.

Page1 / 132

Chapter 3 Slides - Engineering Problem Solving with C Chapter 3 Control Structures and Data Files 1 Chapter 3 Algorithms • Before writing a

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online