2.1 B Design A Solution Sequence B
2.1 B Design A Solution Sequence B
0
DESIGN A SOLUTION
b) Solve a given problem using algorithm
LEARNING OUTCOME
2
EXAMPLE 1:
Problem statement:
Find the perimeter and area of a rectangle.
The perimeter and area of the rectangle are then
given by the following formulas:
perimeter = 2 x (length + width)
area = length x width
3
EXAMPLE 1
1. Analyze the problem:
PAC: • Input Process Output Chart (IPO)
4
EXAMPLE 1 2. Design an algorithm:
• Pseudocode
Pseudocode
Must begin
with
Start
Read length, width
perimeter = 2 x (length + width)
area = length x width
Print perimeter, area
Must end
with Stop
5
EXAMPLE 1
Start
2. Design an algorithm:
• Flow Chart
Read length, width
Pseudocode
Start
Read length, width perimeter = 2 x (length + width)
perimeter = 2 x (length + width) = area = length x width
area = length x width
Print perimeter, area
Stop Print perimeter, area
Stop
6
EXAMPLE 2:
Problem statement:
Find the area of triangle by using this formula:
1
area = x height x width
2
7
EXAMPLE 2
1. Analyze the problem:
PAC: • Input Process Output Chart (IPO)
8
EXAMPLE 2
2. Design an algorithm:
• Pseudocode
Pseudocode
Start
Read height, width
1
triangle area = x height x width
2
Print triangle area
Stop
9
EXAMPLE 2
Start
2. Design an algorithm:
• Flow Chart
Read height, width
1
triangle area = x height x width
2
Stop 10
EXAMPLE 3:
Problem statement:
Every book purchased at SHK bookstore will be
given 15% discount based on the price. Calculate
and display the price after discount for one book
purchased.
11
EXAMPLE 3
1. Analyze the problem:
PAC: • Input Process Output Chart (IPO)
12
EXAMPLE 3 2. Design an algorithm:
• Pseudocode
Pseudocode
Start
Read original price
discount price = 0.15 x original price
price after discount = original price – discount price
Print price after discount
Stop
13
EXAMPLE 3
Start
2. Design an algorithm:
• Flow Chart
Read original price
Stop
14
1. Find the area of a circle by using this formula:
area = 𝜋𝑟2
2. ABC Supermarket offers 20% discount for each
item that is bought during YEAR END Sale (YES).
The price after discount will be calculated
based on the given normal price. As the result,
price after discount will be displayed.
3. Calculate the fuel gas (RON95) that
needs to be paid by a customer at the
petrol station. Given the price for 1 litre
of RON95 is RM2.20.
4. Find the length of hypotenuse of a right
angle triangle using formula:
𝑐= 𝑎2 + 𝑏 2
Question 1
Find the area of a circle by using this formula:
area = 𝜋𝑟2
Start
Read radius
area of circle = 3.142 x 𝑟𝑎𝑑𝑖𝑢𝑠2
Print area of circle
Stop
20
2. Design an algorithm:
Question 1
• Flow Chart
Start
Read radius
Stop 21
Question 2
ABC Supermarket offers 20% discount for each item that is bought
during YEAR END Sale (YES). The price after discount will be calculated
based on the given normal price. As the result, price after discount will
be displayed.
1. Analyze the problem:
• Input Process Output Chart (IPO)
Input Processing Output
normal Calculate price after discount price
price based on normal price after
discount
2. Design an algorithm: Question 2
• Pseudocode
Pseudocode
Start
Read normal price
price after discount = 0.8 x normal price
Print price after discount
Stop
23
2. Design an algorithm:
Question 2
• Flow Chart
Start
Stop 24
Question 3
Calculate the price of fuel gas (RON95) that needs to be
paid by a customer at the petrol station. Given the price for
1 litre of RON95 is RM2.20.
Start
Read litre of petrol
price paid = 2.2 x litre of petrol
Print price paid
Stop
26
2. Design an algorithm: Question 3
• Flow Chart
Start
price paid =
2.2 x litre of petrol
Stop 27
Question 4
Find the length of hypotenuse of a right angle triangle
using formula:
𝑐= 𝑎2 + 𝑏2
1. Analyze the problem:
• Input Process Output Chart (IPO)
Input Processing Output
a, b Calculate hypotenuse (c) based c
on length of a and b.
2. Design an algorithm: Question 4
• Pseudocode
Pseudocode
Start
Read a, b
c = 𝑎2 + 𝑏 2
Print c
Stop
29
2. Design an algorithm: Question 4
• Flow Chart
Start
Read a, b
c = 𝑎2 + 𝑏 2
Print c
Stop 30