Upload
zoe-blake
View
213
Download
0
Embed Size (px)
Citation preview
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?
Winter 2011 2Prof S.P. Leblanc
Outline
1. Representing Program Behaviour2. Flowchart Evolution and Motivation3. Flowchart Symbols
a. Auxiliaryb. Primary
4. Flow Control Flowchartsa. if-elseb. switchc. ford. whilee. do…while
5. Flowcharts and EEE243
3Winter 2011 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
Winter 2011 4Prof S.P. Leblanc
5Prof 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
Winter 2011
6Prof 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
Winter 2011
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)
7Winter 2011 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
Winter 2011 8Prof 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 flowWinter 2011 9Prof S.P. Leblanc
Start
n
3b. Flowcharts – Primary Symbols
• Assignment Statements
• I/O Statements
• Call to a function in another module
• Compound Statement
Winter 2011 10Prof S.P. Leblanc
sum = a + bmult = a * b
READ (a)
x abs()from math.h
4a Flowcharts – if-else
Winter 2011 11Prof S.P. Leblanc
a > 10
SomethingSomething
else
T F
4a Flowcharts – switch
Winter 2011 12Prof S.P. Leblanc
a ?
Somethingm
Something0
Somethingn
m n o
4. Flowcharts - for
Winter 2011 13Prof S.P. Leblanc
Initial conditionCondition
Update
Something
T
F
4. Flowcharts – while
Winter 2011 14Prof S.P. Leblanc
Condition
Something
T
F
4. Flowcharts – do…while
Winter 2011 15Prof S.P. Leblanc
T
F
Something
Condition
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.Winter 2011 16Prof S.P. Leblanc
Quiz Time
• Why are flow charts useful?
Winter 2011 17Prof S.P. Leblanc
Next Lecture• Arrays and Command Line Arguments
18Winter 2011 Prof S.P. Leblanc