Escolar Documentos
Profissional Documentos
Cultura Documentos
Flowcharting
A Supplement to
Starting Out with C++, 4th Edition
Figure 1-11: Process of system development
Building programs
•Edit
•Compile
•Link
•Run
Figure 1-11: Process of system development
Understand the problem:
•Input
•Output
•Process
Develop the solution
(Algorithm):
•Structure chart
•Pseudocode
•Flowchart
Converting design to
computer codes.
e.g:
Flowchart -> C program
Algorithm is the steps
to solve problems
Figure 1-12: Structure chart example
Pseudocode:
Get A
Get B
Calculate Resut
C=A*B
Display the
Result C
Stop
Flowchart Symbols
Terminal: Used to indicates the start and end of a
flowchart. Single flowline. Only one “Start” and “Stop”
terminal for each program. The end terminal for
function/subroutine must use “Return” instead of “Stop”.
Process: Used whenever data is being manipulated. One
flowline enters and one flowline exits.
Input/Output: Used whenever data is entered (input) or
displayed (output). One flowline enters and one flowline
exits.
Decision: Used to represent operations in which there are
two possible selections. One flowline enters and two
flowlines (labelled as “Yes” and “No”) exit.
Function / Subroutine: Used to identify an operation in a
separate flowchart segment (module). One flowline enters
and one flowline exits.
On-page Connector: Used to connect remote flowchart
portion on the same page. One flowline enters and one
flowline exits.
Off-page Connector: Used to connect remote flowchart
portion on different pages. One flowline enters and one
flowline exits.
Comment: Used to add descriptions or clarification.
Read A
Input.
Read B Enter values for
A and B
Calculate Resut
C=A*B Process
Display the
Result C Output
Stop Terminal
Stop Program end
here
Example: Use of comments/description
Start
Yes
No
Stop
Example: Use of connectors on the same page.
Start
1 2
Stop
2
Example: Use of connectors on the different page.
Page 1 Page 2
Start
2
1
Stop
Yes 1
No
2
The details (how the function works)
Example: Function-call example. we put in another flowchart.
This also known as
Note: Module = function = subroutine Function-Definition
Page 1 Start terminal for a Page 2
Function is different.
Start Do not use “Start”
AVRG ( result,n1, n2,n3)
Read
n1, n2 , n3
Body of a function is
AVRG (result, n1, n2,n3) the same with
normal flowchart
result = sum/3
At this part,
we only know what
we want to do. But we Print
don’t know how to do it result
Stop
End terminal
must be “Return”
Control Structures
statement
statement
Selection Structure
If
“do or don’t” (one-choice)
TRUE
condition
condition
FALSE
statement
statement
If-else
(two-choices)
“do this or do that”
TRUE FALSE
condition
condition
°
If set condition is true, execute the first statement, else
execute second statement
Selection Structure (cont..)
Nested if
(if within if)
FALSE
test1 FALSE
test1
TRUE
TRUE
FALSE
TRUE
test2
° °
statement
Considered as
one statement ° °
it is an “one-choice” if
Selection Structure (cont..)
FALSE
condition
TRUE
statement
statement TRUE
condition
FALSE
statement
°
° Considered as one statement
Repeatition Structure
while Loop
(pre-test loop)
°
FALSE
condition
conditio
n
TRUE
statement
body of loop
do-while Loop
(post-test loop)
°
statement
statement
condition
TRUE
FALSE
for Loop
(pre-test loop)
initialization
° FALSE
condition
TRUE
body of loop
increment
y
Example:
Start
Read
Length,
Input:
Width Length <- 5
Width <- 3
Area: 15
Print
Area, Perimeter: 16
Perimeter
Stop
Example:
What is the Output of the following flowchart when the input Num= 10
Start
Enter a Number >> 10
Category A
Input:
Read Num
Num <- 10
Num = 10
10 > 0 ? => YES
Num>0? No
Print
"Category B"
Yes
Print
Output:
"Category A"
“Category A”
Stop
Example:
What is the Output of the following flowchart when the input is Num= 0
Start
Enter a Number >> 0
Category B
Read Num Input: Category A
Num <- 0
Num = 0 Output:
0 > 0 ? => NO “Category B”
Num>0? No
Print
"Category B"
Yes
Print
Output:
"Category A"
“Category A”
Stop
Example:
What is the Output of the following flowchart when the input is Num= 4
Start Variables
Variables
Variables(in
(in
(inmemory):
memory):
memory):
Num
Num
Num [[[ 444 ]]]
Read Num Input: Result
Result
Result [[[ 4
0710]
9 ]]] 0497 +++ 4312
Num <- 4 Count
Count [[[ 3
Count 420
1 ]]] 4312 --- 111
Initialize
Result=0
Count=Num
Print
Result
Stop
Example:
What is the Output of the following flowchart when the input is N = 6 10
Page 1 Page 2 5
average
Start
N=6
AVRG ( result,n1, n2,n3)
Read
N Sum = 10 + 5 + 6
result = sum/3
Print
average
Output:
Average: 7
Return
Stop