Flowchart - TDSB School Web Site List

Download Report

Transcript Flowchart - TDSB School Web Site List

PROBLEM SOLVING
Developing a Program
Flow Charts
TEE/TIK 20
Writing a program

Defining the problem


Planning


Coding, including errors correction, testing
Documenting


Write down the steps, draw a flowchart
Programming


Write down what the program will do
Adding comments
Implementing

Improvement, making the program better
Objective
 A program
can be divided into 3 parts:
 Input
data
 Processing data – Calculation, etc.
 Output information/results
Input
Calculation/
Processing
Output
Planning - Flowchart
A Diagram that uses special symbols
showing the steps of a program
What is a flowchart?
 A diagram
made up of symbols of
various shapes connected by arrows.
 Those symbols indicate either actions to
be taken or decisions to be made.
 It may be used to describe any
complicated process when a mixture of
actions & decisions take place
 It helps us planning & programming.
Flowchart Symbols
Decision symbol
T (Selection, Conditional
Statement)
Terminal symbol
(Start & Stop)
Processing symbol
(Calculate, Assign,
Initialize, Declare)
F
2
1
A
Input/Output symbol
(get, put)
A
Page connector
(used when run out of
room at the bottom)
Step connector
(go from one part to
another)
Terminal Symbol
start
stop

Only one “start” & one
“stop”

1 arrow only

Each flowchart starts
with one “start” & ends
with one “stop”
Input / Output Symbol

2 arrows only


Input Data


1 in & 1 out
get fullname:*
Display result

put fullname
Processing Symbol

2 arrows only


Declaration


var sum : real
Initialization


1 in & 1 out
sum := 30.14
Calculation
Decision Symbol

3 arrows


Q. ?
F
T
Question


1 in & 2 out
worded this way that
the answer is Yes or
No
2 out going arrows


T (True, Yes)
F (False, No)
Page connector
2
1

1 arrow only

Shows the next page


Shows the previous page
Run out of space
Step connector

1 arrow only
 Appear in
A



A
1 to 1
Many to 1
Use letters
 Go from one step to
another
Arrows

From Top to Bottom
& from Left to Right

Make turn

Join together
Example
start
bell
ringing
phone?
Y
answer the
phone
N
door?
Y
see who is
at the door
1.is it the door bell?
2.start
3.answer the phone
4.turn off the alarm
5.is it the telephone?
N turn off the 6.listen to bell ringing
7.stop
alarm
8.see who is at the door
stop
start
Example (Turing)%=comment
Define PI
% the symbol **3 =cub
const PI := 3.14
var radius, volume : real
put “please enter...”..
get radius
volume := (4/3)*PI*radius**3
put “”
put “The volume is”, volume %
Declare
radius, volume
ask radius
input radius
Calculate
volume
output
volume
stop
Example
start
1.start declare variables
2.what is the mark
3.ask for mark
4.check mark>=50
5.>=50 show “U Pass”
6.<50 show “U Fail”
7.stop
var mark: real
ask mark
get mark
_____
mark>=50
F
“U Fail”
A
stop
T
“U Pass”
A
Example with Trace Table
Trace Table
start
Declare & Initialise
x & y to1
A
sum of x&y
is
sum<20
N
Show x,y
and sum
stop
Y
x=y
y = sum
A
x
y
sum
1
1
2
1
2
3
2
3
5
3
5
8
5
8
13
8 13
21
Programming
 Convert
the steps to instructions /
programming languages
 Debug – correct the errors
 Syntax

errors
Grammar mistakes which are easily found out
 Logical
errors
Programs run & work but the outcome is not
correct / expected
 Can be found by testing

Documentation
 Add
comments
 Easier
 Use
to understand
spaces wisely
 Blanks,
Tabs, New Lines
 Easy to trace, follow & understand
 Choose
 Easy
variables & constants names
to understand, not too long or short
Implementation
 Ask others to run your program
 Make it more user friendly including
input & output
 Make it more efficient (fewer lines)
 Make it run faster
 Add ending screen etc.
Good Luck!