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

Lecture 3 Flowcharting For Students

The document provides an introduction to flowcharting and defines key concepts. It explains that a flowchart uses graphic symbols to represent the logical steps of an algorithm or program workflow. Common symbols are presented that represent actions like inputs, outputs, decisions, and flow direction. Examples of flowcharts are given to compute sums and conversions between temperature scales. Basic control structures like sequence and decision are discussed.

Uploaded by

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

Lecture 3 Flowcharting For Students

The document provides an introduction to flowcharting and defines key concepts. It explains that a flowchart uses graphic symbols to represent the logical steps of an algorithm or program workflow. Common symbols are presented that represent actions like inputs, outputs, decisions, and flow direction. Examples of flowcharts are given to compute sums and conversions between temperature scales. Basic control structures like sequence and decision are discussed.

Uploaded by

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

Introduction to

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

Terminal -Used to signify the beginning and


the end of flowchart

Preparation/ - Signifies the preparation of data


Initialization - Used to select initial conditions
- Used to represent instructions or
group of instructions that will alter
or modify a program’s course of
execusion. 5
Symbols What it represents

-Shows input and output. Data are to be


Input/ read into the computer memory from an
Output input device or data to be passed from
memory to an output device.

Processing - Performs any calculations that are to


be done.

Decision - Signifies any decisions that are to be


done.

6
Symbols What it represents

-Shows the entry or exit point of the


flowchart.
-A non- processing symbol used to
One- page Connector
connect one part of a flowchart to
another without drawing flowlines.

Off- page - Designates entry to or exit from one


Connector page when a flowchart requires more
than one page.

- Signifies the process tha is to be


executed next.

Flowlines 7
Example 1 Start

Draw a flowchart that will compute and display


the sum and product of two numbers. Write its Read N
equivalent algorithm.

Algorithm:
Step 1. Initialize sum and product into 0 Print N
Step 2. Read in the values of A and B.

Step 3. Compute Sum by adding A


and B then compute Product by End
multiplying A and B.

8
Example 2 Start

Design a flowchart that will accept


and display the sum of two numbers. sum=0
Write its equivalent algorithms.

Algorithm: Read A,B


Step 1. Read in the value of N.
Step 2. Print the value of N.
sum=A+B

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

Construct a flowchart that will


Prod=0
compute and display the product Ave=0
and average of 3 numbers.

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.

Formula: C=(5/9) x (F-32)

13
Example No. 2 Start

Construct a flowchart that will


convert an inputted number in Celsius=0
Fahrenheit to its equivalent measure
in celcius.
Read F
Formula: C=(5/9) x (F-32)

Celcius=(5/9)*(F-32)

Print
End
Celcius 14
Activity No. 2

Draw a flowchart that will compute and display the


area of a rectangle using the formula: Area = length x
width.

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

Operators Meaning Truth Table

&& = AND true && true= true


true && false= false
false && true= false
false && fasle= fasle

19
Logical Operators

Operators Meaning Truth Table

|| = OR true || true= true


true || false= true
false || true= true
false || false= fasle

20
Logical Operators

Operators Meaning Truth Table

! = NOT !true = False


!false = True

21
Basic Control Structures
•Sequence
•Decision
•Repetition
•Case

22
Sequence Structure

• A series of actions are performed in sequence

23
Sequence Control Structure Start

Example 1: Sum=0
Ave=0

Construct a flowchart that will


compute and print the sum and Read
average of 3 numbers. A,B,C

Sum=A+B+C
Ave= Sum/3

Print
End
Sum, Ave 24
Sequence Control Structure Start

Example No. 2
Celsius=0

Construct a flowchart that will


convert an inputted number in
Fahrenheit to its equivalent measure Read F
in celcius.

Formula: C=(5/9) x (F-32)


Celcius=(5/9)*(F-32)

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:

Area= length x width


Activity No. 2
Construct a flowchart that will compute and
display an inputted number in inches (in.) to its
equivalent number in feet (ft).

Hint 1ft = 12 in.


26
Sequence Control Structure
Activity No. 3
Draw a flowchart that accepts a number in
kilowatts then display its equivalent number in watts.

Hint: 1 kilowatt= 1000 watt.

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

• The flowchart segment below shows a decision structure


with only one action to perform. It is expressed as an if
statement.

Flowchart

False True
x < y?

y is greater
than x

28
Decision Structure

• The flowchart segment below shows how a decision


structure is expressed as an if/else statement.
Flowchart

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)

• This structure provides for the repetitive execution of an


operation or routine while the condition is TRUE. The
condition is evaluated before executing any process
statement. As long as the condition is true, the process is
executed, otherwise, control flows out of the structure.

Flowchart

T
x < y? Add 1 to x

F 34
Controlling a Repetition Structure

• The action performed by a repetition structure must


eventually cause the loop to terminate. Otherwise, an
infinite loop is created.
• In this flowchart segment, x is never changed. Once the loop
starts, it will never end.

• QUESTION: How can this T


flowchart be modified so x < y? Display x
it is no longer an infinite
loop? F

35
Controlling a Repetition Structure

• ANSWER: By adding an action within the repetition that


changes the value of x.

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)

Draw a flowchart that will display a number


from 0 to 100 in descending order. Divisible by
2.

Expected output: 100 98 96 94....0

39
Activity (Repetition Control Structure)

Draw a flowchart that will display a number


from 1 to n in ascending order base on the
user input data.

Expected output: 1 2 3. . . . n

40
Activity (Repetition Control Structure)

Construct a flowchart that will get the


sum of all integers from 1 to 10.

41
Case Structure

Is a branching control mechanism that


allows different executions depending on the
value of the label.
If years_employed = 2, If years_employed = 3,
bonus is set to 200 bonus is set to 400
If years_employed = 1, If years_employed is
CASE
bonus is set to 100 years_employed
any other value, bonus
is set to 800

1 2 3 Other

bonus = 100 bonus = 200 bonus = 400 bonus = 800

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

Print Print Print


“Monday” “Tuesday” “Wednesday”

End

43
Example No. 2

Write a flowchart that will ask the user to


input 2 integer and a character (A S M or
D) If the user inputs ‘A’, add the two
integers, if ‘S’ subtract the two integers, if
‘M’ multiply the two integers and if ‘D’
divide the two integers. Print the
computed value.

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

•The “A” connector


A
indicates that the second START

flowchart segment begins


where the first segment
ends.

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

• This flowchart segment


shows two decision
structures combined. NO YES
x > min?

Display “x is NO YES
outside the limits.”
x < max?

Display “x is Display “x is
outside the limits.” within limits.”

48

You might also like