0% found this document useful (0 votes)
4 views

3 Flowcharts

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

3 Flowcharts

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

FLOWCHARTS

1
FLOWCHARTS
▪ Graphically depicts the logical steps to carry
out a task and shows how the steps relate to
each other.
▪ Used to document how an algorithm was
designed
▪ Easy to understand and visualize

2
FLOWCHART SYMBOLS

3
FLOWCHART SYMBOLS CONTINUED

4
START/END (TERMINAL )
▪ Indicates the start and end of an algorithm
▪ Represented by a rectangle with rounded
sides
▪ There are typically two:
▪ one to start the flowchart
▪ one to end the flowchart

5
INPUT/OUTPUT
▪ Indicates data being:
▪ inputted into the computer
▪ outputted to the user
▪ Represented by a parallelogram
▪ Flowcharts can have many of this shape

6
PROCESS
▪ Indicates
▪ Data being processed
▪ Calculations being processed
▪ Represented by a rectangle
▪ The most common shape in a flowchart

7
DECISION
▪ Indicates a conditional branch
▪ describe a condition or a question
▪ has more than one outgoing branch, depending on
the outcomes to the condition/question
▪ Represented by a diamond

8
PROBLEM SOLVING EXAMPLE
▪ How many stamps do you use when mailing a letter?
▪ One rule of thumb is to use one stamp for every five sheets of
paper or fraction thereof.

9
PSEUDOCODE EXAMPLE
Determine the proper number of stamps for a
letter
Read Sheets (input)
Set the number of stamps to Sheets / 5
(processing)
Round the number of stamps up to the next
whole number (processing)
Display the number of stamps (output)

10
FLOWCHART EXAMPLE

11
DECISION FLOW CHART STRUCTURE

12
SAMPLE NESTED IF STRUCTURE

13
LOOPING FLOW CHART STRUCTURE

14
DIRECTION OF NUMBERED NYC STREETS
ALGORITHM
▪ Problem: Given a street number of a one-way street in New
York City, decide the direction of the street, either eastbound or
westbound
▪ Discussion: in New York City even numbered streets are
Eastbound, odd numbered streets are Westbound

15
PSEUDOCODE
Program: Determine the direction of a
numbered NYC street
Get street
If street is even Then
Display Eastbound
Else
Display Westbound
End If

16
FLOWCHART

17
EXAMPLE-1
▪ Draw a flowchart to find the average of two
numbers.

18
EXAMPLE-1 SOLUTION
▪ Draw a flowchart to find the
average of two numbers.

1. Start
2. Read two numbers in x and y
3. Set w = x + y
4. Set z = w / 2
5. Print z
6. End

19
EXAMPLE-2
▪ Draw a flowchart to take the sides of a
rectangle and calculate its perimeter and
area.

20
EXAMPLE-2 SOLUTION
▪ Draw a flowchart to take the
sides of a rectangle and
calculate its perimeter and area.

1. Start
2. Read width and length in w and h
3. Set a = w ⨯ h
4. Set s = 2 ⨯ (w + h)
5. Print “perimeter is s and area is a”
6. End

21
EXAMPLE-3
▪ Draw a flowchart to take a number and prints
if it is odd or even.

22
EXAMPLE-3 SOLUTION
▪ Draw a flowchart to take a
number and prints if it is odd
or even.
1. Start
2. Read number in c
3. If c modulo 2 = 0 then
4. print even
5. Else
6. print odd
7. End If
8. End

23
EXAMPLE-4
▪ Draw a flowchart to take three numbers and
print the maximum of them

24
EXAMPLE-4 SOLUTION
▪ Draw a flowchart to take three
numbers and print the maximum
of them

1. Start
2. Read x, y, z
3. If x ≥ y then
4. Set Max = x
5. Else
6. Set Max = y
7. End If
8. If z ≥ Max then
9. Set Max = z
10.End If
11.print “The maximum number is Max”
12.End

25
EXAMPLE-5
▪ Draw a flowchart to print integers 1 to N

26
EXAMPLE-5 SOLUTION WITH IF
▪ Draw a flowchart to
print integers 1 to N

1. Start
2. Read N
3. Set Count = 1
4. Print Count
5. If Count < N then
6. Set Count = Count + 1
7. Goto Line 4
8. End If
9. End

27
EXAMPLE-5 SOLUTION WITH WHILE
▪ Draw a flowchart to
print integers 1 to N

1. Start
2. Read N
3. Set Count = 1
4. While Count ≤ N
5. Print Count
6. Set Count = Count + 1
7. End While
8. End

28
EXAMPLE-6
▪ Draw a flowchart to take integer N print N!

29
EXAMPLE-6 SOLUTION
▪ Draw a flowchart to take
integer N print N!

1. Start
2. Read N
3. Set Fact = 1, Count = 1
4. Set Fact = Fact * Count
5. Set Count = Count + 1
6. If Count ≤ N then
7. Goto Line 4
8. End If
9. print “The Factorial of N is
Fact”
10.End

30
EXAMPLE-6 SOLUTION2
▪ Draw a flowchart to take
integer N print N!

1. Start
2. Read N
3. Set Fact = 1, Count = 1
4. While Count ≤ N
5. Set Fact = Fact * Count
6. Set Count = Count + 1
7. End While
8. print “The Factorial of N is Fact”
9. End

31
CLASS AVERAGE ALGORITHM
▪ Problem: Calculate and report the grade-
point average for a class
▪ Discussion: The average grade equals the
sum of all grades divided by the number of
students
Output: Average grade
Input: Student grades
Processing: Find the sum of the grades; count
the number of students; calculate average

32
PSEUDOCODE
1. Start
2. Set Sum = 0, Count = 0, Avg = 0
3. While more data
4. Read Grade
5. Set Sum = Sum + Grade
6. Set Count = Count + 1
7. End While
8. Set Avg = Sum / Count
9. print “The average grade of the class is Avg”
10.End

33
FLOWCHART

34
TRACING
Trace the algorithm for:
43, 74, 65, 58, 81, 39

Grade (input) | Sum | Count | Avg (output)


0 0 0
43 43 1
74 117 2
65 182 3
58 240 4
81 321 5
39 360 6
60
35
TIPS AND TRICKS OF FLOWCHARTS
▪ Flowcharts are time-consuming to write and
difficult to update
▪ For this reason, professional programmers
are more likely to favor pseudocode and
hierarchy charts
▪ Because flowcharts so clearly illustrate the
logical flow of programming techniques, they
are a valuable tool in the education of
programmers
36
URL’S FOR FREE FLOWCHARTING
SOFTWARE
▪ draw.io/ (recommended)
▪ app.diagrams.net/ (recommended)
▪ www.smartdraw.com
▪ www.breezetree.com/flowcharting-software/
▪ www.edrawsoft.com/flowchart.php

37

You might also like