0% found this document useful (0 votes)
58 views30 pages

2.1 B Design A Solution Sequence B

The document provides examples of designing algorithms to solve given problems. It begins with learning outcomes about solving problems using algorithms. It then provides 4 examples of analyzing problems and designing algorithms using pseudocode and flowcharts. The examples include finding the perimeter and area of a rectangle, finding the area of a triangle, calculating discount price, and finding the length of a hypotenuse. For each example, it analyzes the problem using an input-process-output chart and designs an algorithm using pseudocode and a flowchart.

Uploaded by

Fatin Aqilah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views30 pages

2.1 B Design A Solution Sequence B

The document provides examples of designing algorithms to solve given problems. It begins with learning outcomes about solving problems using algorithms. It then provides 4 examples of analyzing problems and designing algorithms using pseudocode and flowcharts. The examples include finding the perimeter and area of a rectangle, finding the area of a triangle, calculating discount price, and finding the length of a hypotenuse. For each example, it analyzes the problem using an input-process-output chart and designs an algorithm using pseudocode and a flowchart.

Uploaded by

Fatin Aqilah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

2.

0
DESIGN A SOLUTION
b) Solve a given problem using algorithm
LEARNING OUTCOME

At the end of this topic, students should


be able to:
•Solve a given problem using
algorithm.

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)

Input Processing Output


length, Calculate the perimeter and perimeter,
width area based on length and area
width.

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)

Input Processing Output


height, Calculate the area of triangle triangle
width based on height and width. area

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

Print triangle area

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)

Input Processing Output


original Calculate the price after price
price discount based on original price. after
discount

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

discount price = 0.15 x original price


price after discount = original price –
discount price

Print price after discount

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

1. Analyze the problem:


• Input Process Output Chart (IPO)
Input Processing Output
radius Calculate the area of circle area of
based on radius circle
2. Design an algorithm: Question 1
• Pseudocode
Pseudocode

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

area of circle = 3.142 x 𝑟𝑎𝑑𝑖𝑢𝑠2

Print area of circle

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

Read normal price

price after discount =


0.8 x normal price

Print price after discount

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.

1. Analyze the problem:


• Input Process Output Chart (IPO)
Input Processing Output
litre of Calculate price to be paid price
petrol based on litre of RON95 petrol paid
2. Design an algorithm: Question 3
• Pseudocode
Pseudocode

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

Read litre of petrol

price paid =
2.2 x litre of petrol

Print price paid

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

You might also like