180 likes | 303 Views
EEE 243B Applied Computer Programming. 11 - Flowcharts §Appendix C Sylvain P. Leblanc. Review. What are the three ways to use the name of a function in a program? Are identifiers required for the parameters in a function prototype?
E N D
EEE 243BApplied Computer Programming 11 - Flowcharts §Appendix C Sylvain P. Leblanc
Review • What are the three ways to use the name of a function in a program? • Are identifiers required for the parameters in a function prototype? • Can you use a void function in an assignment expression? • Why/Why not • What information does the type of a variable give us? Prof S.P. Leblanc
Outline • Representing Program Behaviour • Flowchart Evolution and Motivation • Flowchart Symbols • Auxiliary • Primary • Flow Control Flowcharts • if-else • switch • for • while • do…while • Flowcharts and EEE243 Prof S.P. Leblanc
1. Representing Program Behaviour • In the lectures 08 and 09, we have seen flow of control structures: functions, if-else, else-if, switch, while, for and do-while • There are several methods to represent the logic behind the use of these constructs • Pseudo code – English like statements • Flowcharts – Graphical • Chapin diagrams – Graphical Prof S.P. Leblanc
Flowcharts vs. Structure Charts • The Structure Charts that we discussed with functions are also a graphical method, but they are different: • Structure Charts describe the hierarchical organization • Flow Charts describe the behaviour • In Flowcharts, each of the flow control constructs can be graphically represented • Regardless if you use OOAD or structured programming, flowcharts can help you visualize the logic flow of a program Prof S.P. Leblanc
2. Flowchart Evolution • Flowcharts used to be the main design tool for symbolic languages to represent the logic flow of a program • Flowcharts fell out of grace when new analysis and design techniques emerged • Flowcharts were seen as not scalable for large scale designs • Before diagrammatic tools, flowcharts were drawn by hand using stencils Prof S.P. Leblanc
2. Flowchart Evolution • The production of these charts was tedious, and for large monolithic programs, they were difficult to manage • For large programs it used to be common to see “wall flowcharts” • So why do we still use them? • Our programs are no longer huge monolithic lines of assembler code • We decompose our problems into manageable parts (functions) Prof S.P. Leblanc
2. Flowcharts Motivation • Flowcharts are now used to describe the inside of functions; not the entire program • A flowchart shows an algorithm– a way to solve a problem • The flowchart frees the programmer from the syntax and details of the programming language and allows him to concentrate on the details of the problem to be solved • A pictorial representation of our programs allows us to think more clearly • There are several software tools that you can use to draw flowcharts. • PowerPoint was used for all these charts • Visio also has this capability Prof S.P. Leblanc
3a. Flowcharts – Auxiliary Symbols • We will not cover all the symbols here, we covered the main symbols that you will need to produce algorithms • Terminal symbol – shows start and end of algorithms • Flow lines – Shows the order of actions • Connector – Shows connecting points in algorithm: • When we reach the end of a page or column, • When we want to show something that does not fit in the flow Start n Prof S.P. Leblanc
3b. Flowcharts – Primary Symbols • Assignment Statements • I/O Statements • Call to a function in another module • Compound Statement sum = a + b mult = a * b READ (a) x abs() frommath.h Prof S.P. Leblanc
4a Flowcharts – if-else T F a > 10 Something Something else Prof S.P. Leblanc
4a Flowcharts – switch a ? m n o Something n Something m Something 0 Prof S.P. Leblanc
4. Flowcharts - for Initial condition Condition Update F T Something Prof S.P. Leblanc
4. Flowcharts – while Condition F T Something Prof S.P. Leblanc
4. Flowcharts – do…while Something T Condition F Prof S.P. Leblanc
5. Flowcharts in EEE243 • Note that you will be required to create a flowchart to hand in for one of your labs • I recommend flowcharting to capture solution you develop when faced with a problem • Step 4 in the structured design procedure we covered in lecture 04 • Flowcharts are at the same conceptual level a C code • But flowcharts make it easier to see the algorithm .. It represents a different abstraction • Most student’s generate their flow chart afterwards instead of using it as a design tool • That’s a mistake! • Practice with flow charting, and complex problems will become easier to solve. Prof S.P. Leblanc
Quiz Time • Why are flow charts useful? Prof S.P. Leblanc
Next Lecture • Arrays and Command Line Arguments Prof S.P. Leblanc