Lecture 3 Flowcharting For Students
Lecture 3 Flowcharting For Students
Flowcharting
Computer Science Principles
1
2
Flowchart defined
• “Use of symbols and phrases to designate the logic of how a
problem is solved”
• A common method for defining the logical steps of flow
within a program by using a series of symbols to identify the
basic Input Process and Output (IP’s) function with in a
program.
• A two- dimensional representation of an algorithm; the
predefined graphic symbol of a flowchart are used to
indicate the various operations and the flow of control.
• A diagram representing the logical sequence in which a
combination of steps or operations is to be performed. It is a
blueprint of the program.
3
Algorithm defined
• Is a finite set of instructions that specify a
sequence of operations to be carried out in order
to solve a specific problem or class of problems.
4
Basic symbols used in flowcharting
Symbols What it represents
6
Symbols What it represents
Flowlines 7
Example 1 Start
Algorithm:
Step 1. Initialize sum and product into 0 Print N
Step 2. Read in the values of A and B.
8
Example 2 Start
Display
End Sum
9
Review Exercises
Identify the following symbols:
1 7.
4-5
6
8.
3
9-10
Activity No. 1
Construct a flowchart that will compute
and display the product and average of 3
numbers.
11
Answer Start
Read
a,b,c
Prod=a*b*c
Ave= (a+b+c)/3
Print
End
Prod, Ave 12
Example No. 2
Construct a flowchart that will
convert an inputted number in
Fahrenheit to its equivalent measure
in celcius.
13
Example No. 2 Start
Celcius=(5/9)*(F-32)
Print
End
Celcius 14
Activity No. 2
15
Operators commonly used in flowcharting
Arithmetic operations
Operators Meaning
+ = Addition
- = Subtraction
* = Multiplication
/ = Division
16
Relational Operators
Operators Meaning
= = equal
> = Greater than
< = Less than
<> = Not Equal
≥ = Greater than or Equal to
≤ = Less than or equal to
17
Logical Operators
Operators Meaning
&& = AND
|| = OR
! = NOT
18
Logical Operators
19
Logical Operators
20
Logical Operators
21
Basic Control Structures
•Sequence
•Decision
•Repetition
•Case
22
Sequence Structure
23
Sequence Control Structure Start
Example 1: Sum=0
Ave=0
Sum=A+B+C
Ave= Sum/3
Print
End
Sum, Ave 24
Sequence Control Structure Start
Example No. 2
Celsius=0
Print
End
Celcius 25
Sequence Control Structure
Activity No. 1
Draw a flowchart that will compute and display
the area of a restangle using the formula:
Activity No. 4
Read 2 records in a computer. The first
record will contain unit price and the second record
will contain quantity. Draw a flowchart that will
compute and display the amount by multiplying unit
price and quantity.
27
Decision Structure
Flowchart
False True
x < y?
y is greater
than x
28
Decision Structure
False True
x < y?
x is greater y is greater
than y than x
29
Decision Control Structure
Example 1. Start
Draw a flowchart that
will input values for A
and B. Compare two Input A,B
values inputted and
print which of the
value is higher
including the remark Print B F
“Higher”. A>B
“Higher”
T
Print A
End
“Higher”
30
Start
Decision Control Structure
Example 2. Name= “ ”
Draw a flowchart Remarks= “ “
that will input a grade of
student and determine Read Name,
whether the grade is Grade
passed or failed. Print
the name, grade and
remarks of student.
T Grade
Remarks = “Passed” ≥ 60
F
Print
End Name,Grade, Remarks = “Failed”
Remarks
31
Decision Control Structure
Activity No. ____
Construct a flowchart that asks for the amount
purchased by the customer. If the customer
purchases more than 2,000 then a 5% discount is
given. Display the net amount to be paid by the
customer.
Create a flowchart that will calculate the net amount to be
paid by the customer.
Conditions:
If the customer purchases 1,000 and above then a 5%
discount is given if below 1000 then 3% discount is given.
Display the net amount to be paid by the customer. 32
Activity No. ___
DEI Manufacturing Company plans to give a year end
bonus to each of its employee. Draw a flowchart
which will compute the bonus of an employee.
Considering the following conditions: If the
employee’s monthly salary is less than 2,000 pesos,
the bonus is 50% of the salary; for employees with
salaries greater than 2,000 pesos, the bonus is 1,500
pesos. Print the name and the corresponding bonus
for each employee.
33
Repetition Structure (Looping)
Flowchart
T
x < y? Add 1 to x
F 34
Controlling a Repetition Structure
35
Controlling a Repetition Structure
T
x < y? Display x Add 1 to x
36
Example No 1:
Start
Construct a flowchart
that will accept a Num=1
number less than 10. If
the number is not less
than 10 the program will Read Num
terminate. Print the
number inputted.
Print num T
Num < 10
End
37
Example No 2:
Start
Construct a
flowchart that will
count from 1 to 10 Num=0
and print each
number counted
using the repetition Read Num
structure.
T
Print Num Num=Num+1 Num < 10
End
38
Activity (Repetition Control Structure)
39
Activity (Repetition Control Structure)
Expected output: 1 2 3. . . . n
40
Activity (Repetition Control Structure)
41
Case Structure
1 2 3 Other
42
Example:
Start
Draw a flowchart that will
ask the user to input an
integer then output the Read num
equivalent day of the week.
1 – Monday
2 – Tuesday
case num
3 – Wednesday
1 2 3
End
43
Example No. 2
44
Activity
Draw a flowchart that will ask the user if he wants to
compute the perimeter,area or volume of a
rectangle. If the Area is wanted, ask the measure of
the length and width and computer the area. If the
perimeter is wanted, ask also for the length and
width and compute the perimeter. If the volume is
wanted, ask for the length, width and height. Display
the computed value.
Formula:
Area= length x width
Perimeter= 2(length x width)
Volume= length x width x height 45
Connectors
END
A
46
Modules
START
•The position of the module
symbol indicates the point the Read Input.
module is executed.
•A separate flowchart can be Call calc_pay
function.
constructed for the module.
Display results.
END
47
Combining Structures
Display “x is NO YES
outside the limits.”
x < max?
Display “x is Display “x is
outside the limits.” within limits.”
48