Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
127 views

Tutorial Book Scheme Topic 2 Sequence (pg.4-pg32)

The document describes the design of algorithms to solve various computational problems using pseudocode and flowcharts. It provides 10 examples of problems along with their step-by-step solutions represented as pseudocode and flowcharts. The problems include calculating area and volume, currency conversion, calculating total price with taxes, calculating sum and product of two numbers, and more. For each problem, it clearly defines the input, process and output, and represents the algorithm design using structured programming constructs like sequence, selection and repetition.

Uploaded by

Fatin Aqilah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Tutorial Book Scheme Topic 2 Sequence (pg.4-pg32)

The document describes the design of algorithms to solve various computational problems using pseudocode and flowcharts. It provides 10 examples of problems along with their step-by-step solutions represented as pseudocode and flowcharts. The problems include calculating area and volume, currency conversion, calculating total price with taxes, calculating sum and product of two numbers, and more. For each problem, it clearly defines the input, process and output, and represents the algorithm design using structured programming constructs like sequence, selection and repetition.

Uploaded by

Fatin Aqilah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

2.

0 Design a Solution [SEQUENCE]

2.0 Design a Solution (SEQUENCE)


● Describe algorithm (Pseudocode & Flowchart)
● Solve a given problem using algorithm
● Explain each control structure and their respective purposes
● Apply appropriate control structure in computational problem solving

1. Problem solving is a conceptual process that involves discovering, analyzing, and solving
problems.
(a) State the importance of algorithm in problem solving.

- An algorithm is a step-by-step instruction that will transform the input into the output
that can be represent using pseudocode or flow chart that can help the programmer to
build a program.

(b) Explain two (2) representation of algorithm.

Pseudocode is a human-readable language used as a guide when programmer codes


the algorithm

Flowcharts is a graphic representations of the algorithms.

2. Give three (3) types of control structure.

Sequence, selection, repetition

3. Explain the sequence control structure.

The control structure that directs the computer to proses each instruction in the order
listed in the program
2.0 Design a Solution [SEQUENCE]

4. Ahmad wants to create a program that determines the total area of a piece of land where
length and width are given.
Step 1: Problem Analysis
Input Process Output
length, width Calculate total area of a piece of land total area of a piece of
based on length and width. land

Step 2: Design a Solution (Pseudocode & Flowchart)

START

Read length, width


total area of a piece of land = length x width
Print total area of a piece of land
STOP

START

READ length, width

total area of a piece of land = length x width

PRINT total area of a piece of land

STOP
2.0 Design a Solution [SEQUENCE]

5. Calculate and print the volume of a sphere based on the formula given below.
4
Volume of sphere = 3 𝜋𝑟 3
Step 1: Problem Analysis
Input Process Output
r Calculate the volume of sphere based volume of sphere
on r

Step 2: Design a Solution (Pseudocode & Flowchart)

Start
READ r
volume of a sphere = 1.33 x 3.142 x r x r x r
PRINT volume of a sphere
Stop

START

READ r

volume of a sphere = 1.33 x 3.142 x r x r x r

PRINT volume of a sphere

STOP
2.0 Design a Solution [SEQUENCE]

6. Convert a measurement in millimeter (mm) to meter (m) and print the result.

Step 1: Problem Analysis


Input Process Output
millimeter Calculate meter based on millimeter meter

Step 2: Design a Solution (Pseudocode & Flowchart)

START

Read millimeter
meter = millimeter/ 1000
Print meter
STOP

START

READ millimeter

meter = millimeter / 1000

PRINT meter

STOP
2.0 Design a Solution [SEQUENCE]

7. A government tax of 10% and service tax of 5% will be added to the price of a set of meal
bought at MFC. Calculate the total price that Ali has to pay for a set of meal.

Step 1: Problem Analysis


Input Process Output
price Calculate the total price based on price total price

Step 2: Design a Solution (Pseudocode & Flowchart)

Start OR
READ price Start
total price = price x 1.15 READ price
PRINT total price total price = price + (0.15 x price)
Stop PRINT total price
Stop

START

READ price

total price = price + (0.15 x price)

PRINT total price

STOP
2.0 Design a Solution [SEQUENCE]

8. A program that reads two numbers and print their sum and product.

Step 1: Problem Analysis


Input Process Output
NUMBER1 Calculate sum and product based on sum
NUMBER2 NUMBER1 and NUMBER2 product

Step 2: Design a Solution (Pseudocode & Flowchart)

START

READ NUMBER1, NUMBER2

sum = NUMBER1 + NUMBER2


product = NUMBER1 X NUMBER2

PRINT sum, product

STOP

START

READ NUMBER1,NUMBER2

sum = NUMBER1 + NUMBER2


product = NUMBER1 X NUMBER2

PRINT sum,product

STOP
2.0 Design a Solution [SEQUENCE]

9. Calculate and print the area and circumference of a circle.


(area = pi x radius x radius, circumference = 2 x pi x radius, where pi = 3.14)

Step 1: Problem Analysis


Input Process Output
radius Calculate area and circumference of a area,
circle based on radius circumference

Step 2: Design a Solution (Pseudocode & Flowchart)

Start

READ radius

area = 3.14 x radius x radius


circumference = 2 x 3.14 x radius

PRINT area, circumference


Stop

START

READ radius

area = 3.14 x radius x radius


circumference = 2 x 3.14 x radius

PRINT area, circumference

STOP
2.0 Design a Solution [SEQUENCE]

10. A hotel offers two types of room with different rates.


Room Type Rate per night (RM)
Superior 160
Deluxe 180

During the school holidays, the hotel offers 10% discount on the total room charge. You
are going to make a reservation on one Superior room and one Deluxe room for a few
nights. Calculate and display the total room charge that you must pay.

Step 1: Problem Analysis


Input nights
Process Calculate the total room charge based on nights

Output total room charge

Step 2: Design a Solution (Pseudocode & Flowchart)

START

Read nights
total room charge = 0.9 x (nights x (160+180) )
Print total room charge
STOP

START

READ nights

total room charge = 0.9 x (nights x (160+180) )

PRINT total
room charge
STOP
2.0 Design a Solution [SEQUENCE]

11. Gary Onn is one of the famous fashion designers. In conjunction with 25th anniversary,
25% discount will be given to all dresses. Calculate the price after discount.
Step 1: Problem Analysis
Input price

Process Calculate the price after discount based on price

Output print after discount

Step 2: Design a Solution (Pseudocode & Flowchart)

START

Read price
price after discount = price – (price x 0.25)
Print price after discount
STOP

START
START
Read price
price after discount = price x 0.75
Print price after discount READ price
STOP

price after discount = price – (price x 0.25)

PRINT price after discount

STOP
2.0 Design a Solution [SEQUENCE]

12. A factory worker gets a monthly salary based on basic payment and overtime. The basic
payment is RM1, 820.00 and overtime will be paid RM5 per hour. Calculate the monthly
nett salary for the factory worker after deducting 12% of KWSP.

Step 1: Problem Analysis


Input hour

Process Calculate the nett salary based on hour

Output nett salary

Step 2: Design a Solution (Pseudocode & Flowchart)

START OR
READ hour START
overtime = 5 x hour READ hour
salary = 1820 + overtime nett salary = (1820 + (5 x hour) ) x 0.88
KWSP = 0.12 x salary PRINT nett salary
nett salary = salary - KWSP STOP
PRINT nett salary
STOP

START

READ hour

nett salary = (1820 + (5 x hour)) x 0.88

PRINT nett salary

STOP
2.0 Design a Solution [SEQUENCE]

13. Calculate and display the area of shaded region in the diagram below.

Step 1: Problem Analysis


Input
A, B,C

Process
Calculate the area of shaded region based on A , B, C

Output
area of shaded region

Step 2: Design a Solution (Pseudocode & Flowchart)

START
START

Read A , B , C
area of shaded = (A x B) – (1/2 x B x C) READ A , B , C
Print area of shaded
STOP

area of shaded = (A x B) – (1/2 x B x C)

PRINT area of shaded

STOP
2.0 Design a Solution [SEQUENCE]

14. Siti is a salesperson for a company that sells used computers. The price for Brand A is RM
500 per unit while Brand B costs RM 1000 per unit. The company will pay her 10%
commission for the total sales where total sale will be calculated based on the number of
computers sold for both brands.
15. Step 1: Problem Analysis
Input BrandA
BrandB

Process Calculate the commission based on BrandA and BrandB

Output commission

Step 2: Design a Solution (Pseudocode & Flowchart)

START

READ BrandA,
BrandB

commission = (500 x BrandA) +(1000 x BrandB) x 0.1

PRINT commission

Start STOP

Read BrandA, BrandB


commission = (500 x BrandA) +(1000 x BrandB) x 0.1
Print commission
Stop
2.0 Design a Solution [SEQUENCE]

16. Ahmad plans to install floor tiles for his car parking space which is rectangular in shape.
The price per square feet of floor tiles will be determined after Ahmad chooses the
suitable tiles. Calculate and display the area of Ahmad’s parking space and the total cost
of tiles needed to be paid by him.

Step 1: Problem Analysis


Input
width, length, price per square feet

Process Calculate the area and total cost based on width, length and price per square feet

Output area,total coast

Step 2: Design a Solution (Pseudocode & Flowchart)

Start

Read width, length, price per square feet


area =width x length
total cost = price per square feet x area
Print area, total cost
Stop

START

READ width, length, price per square feet

area =width x length


total cost = price per square

PRINT area,total cost

STOP
2.0 Design a Solution [SEQUENCE]

17. A program will calculate students’ monthly fee for a year.

Step 1: Problem Analysis


Input
monthly fee

Process
Calculate totalFee based on monthly fee

Output totalFee

Step 2: Design a Solution (Pseudocode & Flowchart)

Start

Read monthly fee


totalFee = monthly fee x 12
Print totalFee
Stop

START

READ monthly fee

totalFee = monthly fee x 12

PRINT totalFee

STOP
2.0 Design a Solution [SEQUENCE]

18. The manager of RZX Bookstore plans to promote his bookstore by giving a discount of
15% for each book. Calculate and display the price after discount for one book purchased.

Step 1: Problem Analysis


Input price

Process Calculate the price after discount based on price

Output Price after discount

Step 2: Design a Solution (Pseudocode & Flowchart)

Start OR
Read price Start OR
discount = 0.15 x price Read price Start
price after discount = price -discount price after discount = price x 0.85 Read price
Print price after discount Print price after discount price after discount = price -
Stop Stop (price x 0.15)

Print price after discount


Stop

START

READ price

price after discount = price x 0.85

PRINT price after discount

STOP
2.0 Design a Solution [SEQUENCE]

19. Sheena lives in Ipoh. She has to commute from Ipoh to Gopeng 5 days a week and have to
pay RM3.20 every time she goes through the toll. Calculate the toll amount to be paid by
Sheena every month. (Assume 1 month = 4 weeks)

Step 1: Problem Analysis


Input
-

Process Calculate the toll amount to be paid based on days

Output
toll amount to be paid

Step 2: Design a Solution (Pseudocode & Flowchart)

Start

toll amount to be paid = (3.20 x 5) x 4


Print toll amount to be paid
Stop

START

toll amount to be paid = (3.20 x 5) x 4

PRINT toll amount to be paid

STOP
2.0 Design a Solution [SEQUENCE]

20. Calculate the total amount customer needs to pay for a set of lunch meal and a set of kid’s
meal ordered with 10% sales and service tax (SST) charged. Display the total nett price
paid based on quantity bought.
Item Price
Lunch Meal RM7.90
Kid’s meal RM5.70

Step 1: Problem Analysis


Input quantity of Lunch Meal
quantity of Kid’s meal

Process Calculate the total nett price based on quantity lunch meal and quantity of
kid’s meal

Output total nett price

Step 2: Design a Solution (Pseudocode & Flowchart)

Start
Read quantity of Lunch Meal, quantity of Kid’s meal
total nett price = (quantity of Lunch Meal x 7.90) + (quantity of Kid’s meal x 5.7) x 1.10
Print total nett price
Stop

START

Read quantity of Lunch Meal, quantity of Kid’s


meal

total nett price = (quantity of Lunch Meal x 7.90) + (quantity of Kid’s meal x 5.7) x 1.10

PRINT total nett price

STOP
2.0 Design a Solution [SEQUENCE]

21. Read and print two variables Name and Age.

Step 1: Problem Analysis


Input Name, Age
Process -
Output Name, Age

Step 2: Design a Solution (Pseudocode & Flowchart)

Start
Read Name, Age Start
Display Name, Age
Stop
Read Name, Age

Display Name, Age

Stop
2.0 Design a Solution [SEQUENCE]

22. Calculate and display Ahmad’s age.

Step 1: Problem Analysis


Input
current year, born year

Process
Calculate Ahmad’s age based on current year, born year

Output Ahmad’s age

Step 2: Design a Solution (Pseudocode & Flowchart)

Start

Read current year, born year


Ahmad’s age = current year – born year
Print Ahmad’s age
Stop

START

READ current year, born year

Ahmad’s age = current year – born year

PRINT Ahmad’s age

STOP
2.0 Design a Solution [SEQUENCE]

23. You are asked to calculate the area of shaded region of two circles in FIGURE 1.

Step 1: Problem Analysis


Input
r1, r2

Process
Calculate the area of shaded region based on r1, r2

Output area of shaded region

Step 2: Design a Solution (Pseudocode & Flowchart)

Start
Read r1, r2
area of shaded region = (3.142 x r2 x r2) – (3.142 x r1 x r1)
Print area of shaded region
Stop

START

READ r1, r2

area of shaded region = (3.142 x r2 x r2) – (3.142 x r1 x r1)

PRINT area of shaded region

STOP
2.0 Design a Solution [SEQUENCE]

24. ABC Supermarket offers 20% discount for each item that is bought during Year End Sale
(YES). The discount and price after discount will be calculated based on the given normal
price. As the result, price after discount will be displayed.
Step 1: Problem Analysis
Input normal price

Process Calculate price after discount based on normal price

Output price after discount

Step 2: Design a Solution (Pseudocode & Flowchart)

START
Read normal price
Price after discount = normal price×0.8
Print price after discount
STOP

START

READ normal price

Price after discount = normal price×0.8

PRINT price after discount

STOP
2.0 Design a Solution [SEQUENCE]

25. Calculate the price of a cup of coffee sold at MyKopitiam Cafe. The price is based on the
number of scoops of espresso coffee, sugar syrup and milk. The prices of espresso coffee,
sugar syrup and milk are RM5, RM3 and RM0.20 per scoop respectively.

Step 1: Problem Analysis


Input
scoopEspresso, scoopSugar, scoopMilk

Process
Calculate the price of a cup of coffee based on scoopEspresso, scoopSugar,
scoopMilk.

Output
price of a cup of coffee

Step 2: Design a Solution (Pseudocode & Flowchart)


START

Read scoopEspresso, scoopSugar, scoopMilk


price of a cup of coffee = (scoopEspresso x 5) + (scoopSugar x 3) + (scoopMilk x 0.2)
Print price of a cup of coffee

STOP

START

READ scoopEspresso, scoopSugar, scoopMilk

price of a cup of coffee = (scoopEspresso x 5) + (scoopSugar x 3) + (scoopMilk x 0.2)

Print price of a cup of coffee

STOP
2.0 Design a Solution [SEQUENCE]

26. Meatz Place Café prints a receipt for its customers as shown in FIGURE 2. The unit price
for each item is fixed and stored by the system. The date and
time are automatically generated by the system.

(a) State the inputs required by the system.

quantity, item

(b) Besides the item, unit price, quantity, date and time,
state the other outputs produced by the system.

Sub Total, Total, GST 6%, GST ID, price

(c) State two (2) of the process involved to produce the above outputs.
price = unit price x quantity
total = subtotal x 1.06
2.0 Design a Solution [SEQUENCE]

27. With the escalating price of fuel, the need to understand the car fuel consumption has
become increasingly important. In April 2017, you have made 10 journeys. You want to
know the average fuel consumption for month of April 2017. Assume that your car can
read the mileage, in kilometer (km) and the fuel tank level, in liter (L) at the beginning
and at the end of journey.
Step 1: Problem Analysis
Input mileage, fuelBegin, fuelEnd

Process Calculate average fuel consumption based on mileage, fuelBegin, fuelEnd for 10
journeys

Output average fuel consumption

Step 2: Design a Solution (Pseudocode & Flowchart)

Start
Read mileage, fuelBegin, fuelEnd
average fuel consumption = ( (fuelBegin - fuelEnd) / mileage) / 10
Print average fuel consumption
Stop

START

Read mileage, fuelBegin, fuelEnd

average fuel consumption = ( (fuelBegin - fuelEnd) / mileage) / 10

PRINT average fuel consumption

STOP
2.0 Design a Solution [SEQUENCE]

28. Mr. Rahman plans to make a reservation for a hotel room in Langkawi. The room rate is
RM250.00 per night and the sales and service charge is 15% of the room rate. Determine
the total payment if he books the hotel room for n nights. List the input, processes
involved to calculate the total payment and the output.

Step 1: Problem Analysis


Input n

Process
Calculate the total payment based on n

Output
total payment

Step 2: Design a Solution (Pseudocode & Flowchart)


START
Read n
total payment = (n x 250) + (n x 250 x 0.15)
Print total payment
STOP

START
Read n
total payment = (n x 250) x 1.15
Print total payment
STOP

START

READ n

total payment = (n x 250) x 1.15

PRINT total payment

STOP
2.0 Design a Solution [SEQUENCE]

29. A student is required to determine volume of a cuboid based on the measurements of


length, width, and height in centimeter unit. Calculate the volume.
Step 1: Problem Analysis
Input
length, width, height

Proces Calculate the volume of a cuboid based on length, width, height


s
Output
volume of a cuboid

Step 2: Design a Solution (Pseudocode & Flowchart)

START

Read length, width, height


volume of a cuboid = length x width x height
Print volume of a cuboid
STOP

START

READ length, width, height

volume of a cuboid = length x width x height

PRINT volume of a cuboid

STOP
2.0 Design a Solution [SEQUENCE]

30. A customer books flight ticket through an online system. For each transaction, the
customer has to pay total flight charges based on number of passengers and the cabin
class price.

Step 1: Problem Analysis


Input passengers , cabin class price
Process Calculate the total flight charges based on passengers, cabin class price.
Output total flight charges

Step 2: Design a Solution (Pseudocode & Flowchart)

START

Read passengers, cabin class price


total flight charges = passengers x cabin class price
Print total flight charges
STOP

START

READ passengers, cabin class price

total flight charges = passengers x cabin class price

PRINT total flight charges

STOP
2.0 Design a Solution [SEQUENCE]

31. The Computer Science lecturers wish to determine the final marks for every student. The
final marks are taken from average marks of three (3) quizzes and total marks of two
(2) tests. Print the final marks for each student.
Step 1: Problem Analysis
Input quiz1, quiz2, quiz3, test1, test2
Process Calculate the final marks based on quiz1, quiz2, quiz3, test1 and test2 entered
Output final marks

Step 2: Design a Solution (Pseudocode & Flowchart)

START

Read quiz1, quiz2, quiz3, test1, test2


final marks = ((quiz1 + quiz2 + quiz3)/ 3) + (test1+ test2)
Print final marks
STOP

START

READ quiz1, quiz2, quiz3, test1, test2

final marks = ((quiz1 + quiz2 + quiz3)/ 3) + (test1+ test2)

PRINT final marks

STOP
2.0 Design a Solution [SEQUENCE]

32. Nafisah lives in Uganda that charges 3% income tax on her annual salary. She wants to
calculate the amount of tax that she needs to pay.

Step 1: Problem Analysis


Input annual salary
Process Calculate the amount of tax based on annual salary
Output amount of tax

Step 2: Design a Solution (Pseudocode & Flowchart)

rE
START

Read annual salary


amount of tax = annual salary x 0.03
Print amount of tax
STOP

START

Read monthly salary


amount of tax = (monthly salary x 12) x 0.03
Print amount of tax
STOP
START

READ annual salary

amount of tax = annual salary x 0.03

PRINT amount of tax

STOP

“All PROGRESS occurs because people dare to be different…"

You might also like