At the end of this subtopic, students should be able to:
(b) Solve a given problem using algorithm.
(d) Apply appropriate control structures (Sequence, Selection: single,
dual, multiple, repetition: counter-controlled, sentinel-controlled) in
computational problem solving.
1
2.1 (b) & (d): Design a Solution - [SEQUENCE – Example 1]
Problem Statement: Calculate the area of parallelogram.
Problem Analysis:
Input Process Output
base, height Calculate parallelogram area parallelogram area
Pseudocode Flowchart
Start
Input base, height
Calculate parallelogram area
parallelogram area = base x height
Display parallelogram area
Stop
2
2.1 (b) & (d): Design a Solution - [SEQUENCE – Example 2]
Problem Statement: Calculate total price for a set of meal after 6% government tax & 10% service tax.
Problem Analysis:
Input Process Output
price Calculate new price new price
Pseudocode Flowchart
Start
Input price
Calculate new price
new price = price x 1.16
Display new price
Stop
3
2.1 (b) & (d): Design a Solution - [SEQUENCE – Example 3]
Problem Statement: Calculate and display the overtime pay received by an employee. Overtime rate is RM5 per
hour.
Problem Analysis:
Input Process Output
hour Calculate overtime pay overtime pay
Pseudocode Flowchart
Start
Input hour
Calculate overtime pay
overtime pay = hour x 5
Display overtime pay
Stop
4
2.1 (b) & (d): Design a Solution - [SELECTION – IF]
Problem Statement: If student’s mark is greater than or equal to 60, Print message “Passed”.
Problem Analysis:
Input Process Output
Determine whether mark is greater message “Passed”
mark
than or equal to 60 or none
Pseudocode Flowchart
Start
Input mark
if mark ≥ 60
Print "Passed"
end if
Stop
False
True
5
2.1 (b) & (d): Design a Solution - [SELECTION – IF-ELSE]
Problem Statement: If student’s mark is greater than or equal to 60, Print message “Passed”, else Print message
“Failed”.
Problem Analysis:
Input Process Output
Determine whether mark is greater
message “Passed”
mark than or equal to 60
or “Failed”
Pseudocode Flowchart
Start
Input mark
if mark ≥ 60
Print "Passed"
else
Print "Failed"
end if False
Stop
True
6
2.1 (b) & (d): Design a Solution - [SELECTION – MULTIPLE IF-ELSE]
Problem Statement: Check whether a number entered by user is positive, negative or zero. Display an appropriate
message as output.
Problem Analysis:
Input Process Output
message “Positive” or
Determine respective message based on “Negative”
number
number or “Zero”
Pseudocode Flowchart
Start
Input number
if number > 0
Print "Positive"
else if number < 0
True
Print "Negative"
else
Print "Zero" False
end if
Stop True
False
7
2.1 (b) & (d): Design a Solution - [REPETITION – EXAMPLE 1]
Problem Statement: Calculate the BMI for 4 persons.
Problem Analysis:
Input Process Output
weight, height Calculate BMI for 4 persons BMI
Pseudocode Flowchart
Start
Set counter = 1
while counter ≤ 4
Input weight and height
Calculate BMI: True
BMI = weight ÷ (height x
height)
Display BMI False
counter = counter + 1
end while
Stop
8
2.1 (b) & (d): Design a Solution - [REPETITION – EXAMPLE 2]
Problem Statement: Calculate the BMI for 3 persons. Print “Please reduce your weight” if BMI is greater or equal to
25.0. If not, print “You have an ideal weight”.
Problem Analysis:
Input Process Output
Message “Please reduce
Calculate BMI and determine respective
weight, height your weight” or
message based on BMI for 3 persons.
“You have an ideal weight”
Pseudocode Flowchart
Start
Set counter = 1
while counter ≤ 3
Input weight and height
True
Calculate BMI:
BMI = weight ÷ (height x height)
if BMI ≥ 25.0 False
Display “Please reduce your
weight”
else
False
Display “You have an ideal
weight”
True
end if
counter = counter + 1
end while
Stop
9
2.1 (b) & (d): Design a Solution - [REPETITION – EXAMPLE 3]
Problem Statement: Print the sum of odd number from 9 to 15.
Problem Analysis:
Input Process Output
Calculate sum of odd number from 9 to
- sum
15
Pseudocode Flowchart
Start
Set counter = 9
Set sum = 0
while counter ≤ 15
sum = sum + counter True
counter = counter + 2
end while
False
Display sum
Stop
10
2.1 (b) & (d): Design a Solution - [REPETITION – EXAMPLE 4]
Problem Statement: Calculate and print the sum of several integers. Continue reading values until sentinel -99 is
read.
Problem Analysis:
Input Process Output
num Calculate sum until sentinel -99 is read. sum
Pseudocode Flowchart
Start
Set sum = 0
Input num
while num ≠ - 99
sum = sum + num
Input num
end while True
Display sum
Stop
False
11