1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
1.0 Problem Solving (REPETITION)
1.2 Problem Analysis
Identity input, process, and output from a given problem
1.3 Design a Solution
Define Algorithm (Pseudocode & Flowchart)
Solve a given problem using Pseudocode
Solve a given problem using Flowcharts
1. The use of appropriate control structure is very important when writing a computer
program.
Identify the suitable control structure to solve the following problems:
Problem Control Structure
a. Check whether a staff is entitled to get Selection Control Structure
an overtime pay or not.
b. Get the average marks obtained by students in Repetition Control Structure
the whole matriculation batch. with counter control
c. Calculate the fuel price that needs to be paid by Sequence Control Structure
a customer at a petrol station.
d. Enter the items purchased by a customer one by Repetition Control Structure
one until the null value is entered. with sentinel control
e. Give 10%discount from the total price for a Repetition Counter control
homeless customer. with Accumulator
2. Before writing a program to solve a particular problem, it is essential to have a thorough
understanding of the problem and carefully plan the approach to solve the problem.
(a) Define algorithm.
An algorithm is a step-by-step instruction that will transform the input into
the output.
(b) Describe two (2) of the techniques that you have answered in question 2(a).
Pseudocode An artificial, informal language used to develop algorithms
Flowchart which also similar to everyday English.
A graphic representation of the algorithms
# Organ Donation : It takes lives to save lives…
77
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
3. Explain repetition or looping.
Repetition or looping allow to repeat one or more instructions until some conditions is
met.
4. Define counter controlled.
Counter-controlled repetition is often called definite repetition because the number of
repetitions is known before the loop begins executing.
5. List the 4 tasks associated with counter controlled:
i. Counter-Loop Name ii. Initial Value
iii. Condition iv. Update Value
6. Define sentinel controlled.
Sentinel controlled repetition is sometimes called indefinite repetition because it is not
known in advance how many times the loop will be executed.
7. List the 3 tasks associated with sentinel controlled:
i. Initial value of sentinel control variable ii. Condition to test sentinel control
variable
iii. Update the value of sentinel control
variable
8. Draw a symbol used to represent a repetition structure’s condition in a flowchart.
# Organ Donation : It takes lives to save lives…
78
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
9. Identify the following control structure.
10. Transfer the pseudocode to flowchart and counter control table.
Pseudocode Flowchart
Start
Start
initialize i to 1 False i=1
repeat while (i ≤ 3) Stop
Print i i<3
i=i+1 True
end repeat
Stop
Print i
i=1+1
Counter Control Table i<=3 Print i i = i+1
i= 1 True
1 True 1 2=1+1
2 True
3 False 2 3=2+1
4
3 4=3+1
------------- end while ---------------
# Organ Donation : It takes lives to save lives…
79
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
11. The following pseudocode segment contains an error.
Start Rewrite the correct pseudocode segment.
set number = 1
repeat while (number is less than 5) Start
Print “Hello” number = 1
end repeat while (number <5)
Print “Hello”
Stop number = number + 1
end while
(i) Identify and name the error.
Stop
No update counter
12. Convert the flowchart below to
pseudocode.
Pseudocode
Start
k=1
while ( k < = 10 )
input n
print n
k=k+1
end while
Stop
# Organ Donation : It takes lives to save lives…
80
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
13. Display numbers 1 to 100.
i. Identify the type of repetition used. Counter Controlled
ii. Name & initialize the counter i=1
iii. Condition
iv. Update counter i <= 700
v. What is the value of counter when the loop i=i+1
exits?
Start 101
Pseudocode
Stop Flowchart
set i =1
repeat while ( i <100) Start
Print i False i=1
i = i +1
end repeat i < 100
True
Stop
Print i
i=i+1
Counter Control Table i <=700 Print i i=i+1
i = 100 True
1 True 1 2=1+1
2 True
3 True 2 3=2+1
…. True
…. True 3 4=3+1
….. True
… True …. ….
99 True
100 FALSE ….. …..
101
….. …..
….. …..
99 100 = 99 + 1
100 101 = 100 + 1
Loop Terminates
# Organ Donation : It takes lives to save lives…
81
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
14. Write a loop that displays “Do Good…” 50 times. Assume that you will use a counter
variable named count. Finally print “..it comes to you”.
i. Identify the type of repetition used. Counter Controlled
ii. Name & initialize the counter count = 1
iii. Condition
count <= 50
iv. Update counter count = count + 1
v. What is the value of count when the loop
51
exits?
Flowchart
Pseudocode
Start
Start
set count =1
repeat while ( count < = 50)
Print “Do Good…” count = 1
count = count +1
end repeat False
Print “..it comes to you”. count < 50
Stop Print “..it
comes to
True
you”
Good..” Print “Do Good..”
Stop
count = count + 1
Counter Control Table
i = 1 i < 50 Print “Do Good..” i = i + 1 Print “..it comes to you”
1 True Do Good 2=1+1
2 True Do Good 3=2+1
3 True Do Good 4=1+1
… ….. …… …….
…. ….. …….. …….
…. ….. …….. …….
… ….. ……. ……..
49 True Do Good 50 = 49 + 1
50 True Do Good 51 = 50 + 1
51 False Loop Terminates … it comes to you
# Organ Donation : It takes lives to save lives…
82
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
15. Calculate the sum of 150 numbers that are being input interactively using a loop.
i. Identify the type of repetition used. Counter Controlled with accumulator
ii. Name & initialize the counter count = 1
iii. Condition
iv. Update counter count <= 150
v. What is the value of counter when the loop count = count + 1
exits? 151
Pseudocode Flowchart
Start Start
set i =1 i=1
sum = 0 sum = 0
while ( i < 150)
False
Read number
sum = sum + number Print sum i < 150
i = i +1 Stop True
end while
Print sum Read number
Stop
sum = sum + number
count = count + 1
Counter Control Table i = i+ 1 Print sum
i = 1 sum = 0 i < 150 number sum = sum + number
1 0 TRUE 5 5=0+5 2=1+1
2 5 TRUE 7 12 = 5 + 7 3=2+1
3 12 TRUE 10 22 = 12 + 10 4=3+1
.. 22 TRUE XX
… … TRUE XX … …
… …. TRUE XX …. ….
… …. TRUE XX …. …
149 …. TRUE XX …. …
150 …. TRUE XX …. 150=149+1
151 XXX FALSE XXX== XX + XX 151=150+1
Loop Terminates
XXX
# Organ Donation : It takes lives to save lives…
83
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
16. Find the average marks from five (5) tests that have been taken by a student.
i. Identify the type of repetition used. Counter Controlled with accumulator
ii. Name & initialize the counter test = 1
iii. Condition test <= 5
iv. Update counter
v. What is the value of counter when the loop test = test + 1
6
exits?
Pseudocode Flowchart
Start Start
test =1 test = 1
total = 0 total = 0
while ( test <6)
average = total/5 False
Read marks Print average
total = total + marks test < 5
test = test +1 True
end while
average = total / 5 Read marks
Print average
Stop
Stop
total = total + marks
test = test + 1
Counter Control Table
test = total = test < marks total=total+marks Test=test+1 Average
1 0 5 Marks
1 0 80 80 = 0 + 80 2=1+1
2 80 TRUE 90 170 = 80 + 90 3=2+1 80 = 400/5
TRUE 75 245 = 170 + 75 4=3+1
55 300 = 245 + 55 5=4+1
3 170 TRUE 100 400 = 300 + 100 6=5+1
4 245 TRUE Loop Terminates
5 300 TRUE
6 400 FALSE
# Organ Donation : It takes lives to save lives…
84
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure:
17. Puan Rose is planning to prepare a healthy breakfast for her family. She needs to buy
few items and needs to calculate the total price based on the price and quantity of each
item that she wants to buy. For items with the item code of 5000 and above, 6% of Good
and Service Tax (GST) will be imposed. The calculation process is finished when she
enters 0 for the value of item code.
Input Process Output
item code, Determine to calculate the total price based total price
on the item code, price and quantity as long
price, as (while) item code not equal to 0.
quantity
Pseudocode Flowchart
Start Print False Start
total price = 0 total total price = 0
Read item code price
While (item code ≠ 0 ) Read item code
Read price , quantity Stop
if ( item code < 5000 ) False Item code ≠ 0?
total = price x quantity True
else
total = 1.06 x (price x quantity) Read price, quantity
end if
total price = total price + total Item code <5000?
Read item code
End While
Print total price
Stop
True
total = price x quantity
total = 1.06 x
(price x quantity
total price = total price
+ total
Read item code
# Organ Donation : It takes lives to save lives…
85
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure:
18. 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 also the fuel tank level, in litre (L) at the
beginning and at the end of journey.
Input Process Output
Start KM, End KM, Calculate the average fuel consumption average fuel consumption
Start Litre, End Litre based on Start KM, End KM, Start Litre and
End Litre for 10 journeys.
Pseudocode
Start
journey =1
TotalKM = 0 TotalKM = TotalKM + (End KM – Start KM)
TotalLitre = 0 TotalLitre= TotalLitre + (Start Litre – End Litre)
While ( journey<10)
Read Start KM, End KM, Start Litre, End Litre
KM = End KM – Start KM
TotalKM = TotalKM + KM
Litre = Start Litre – End Litre
TotalLitre= TotalLitre + Litre
journey = journey +1
End while
Average fuel consumption = TotalLitre/TotalKM
Print Average fuel consumption
Stop
Flowchart
# Organ Donation : It takes lives to save lives…
86
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Start
i=1
TotalKM =0
TotalLitre = 0
True
i < 10 Read Start Litre, End Litre,
False Start KM, End KM
Average = TotalKM/ TotalLitre KM = End KM – Start KM
Litre = Start Litre – End Litre
Print Average
Stop TotalKM = TotalKM + KM
TotalLitre= Total Litre+ Litre
i=i+1
# Organ Donation : It takes lives to save lives…
87
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure:
19. Mr. Rahman plans to make a reservation for a hotel room in Langkawi Island. The basic
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.
Input Process Output
number of night Calculate total payment based on number total payment
of night entered by a user.
Pseudocode
Start Start
Read number of night Read night
Total = number of night x RM250
Service charge = 0.15 x Total
Total Payment = Total + service charge
Print Total Payment
Stop
Total = night x RM250
Charge = 0.15 x Total
Total Payment = Total + Charge
Print Total Payment
Stop
]
# Organ Donation : It takes lives to save lives…
88
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure:
Start Flowchart
night = 1
total = 0 Start
Read n night = 1
while ( night <= n) total = 0
total = total + RM250
night = night + 1
end while
service charge = 0.15 x total
total payment = service charge + total
Print total payment
Stop
Read n
service charge = 0.15 x total night <= n
total payment = service charge + total
True
Print Total Payment total = total + RM250
Stop night = night + 1
# Organ Donation : It takes lives to save lives…
89
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
20. Display even numbers from 100 to 700 and add the total of the numbers. Display the total
sum.
Input Process Output
Total
No input Determine to calculate total of even
numbers from 100 to 700.
Pseudocode
Start
number = 100
total = 0
while (number <= 700)
if (number % 2 = 0)
total = total + number
end if
number = number + 1
end while
Print total
Stop
Flowchart
Start
number = 100
total = 0
Print total number < 700?
Stop
False
True
number % 2=0? number = number + 1
True False
Total = total + number
21. Convert the following pseudocode to the appropriate flowchart.
# Organ Donation : It takes lives to save lives…
90
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
CCoonnttrrooll SSttrruuccttuurree::
Flowchart
Start
counter = 0
Read number of staff
Stop counter < number of staff?
False True
False Read year of service, salary
year of service < 10?
Bonus = 2.0 x salary True
Bonus = 1.5 x salary
Print bonus
counter = counter + 1
# Organ Donation : It takes lives to save lives…
91
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
22. Given the list of daily temperatures for a certain number of days, design an algorithm to
determine the maximum temperature. The first input is the number of days.
Input Process Output
number of days, Determine maximum temperature for maximum temperature
temperature certain number of days based on
temperature entered by a user.
Pseudocode
Start
days = 1
max = -99
Read number of days
while (days <= number of days)
Read temperature
if ( temperature > max)
max = temperature
end if
days = days + 1
end while
Print max
Stop
# Organ Donation : It takes lives to save lives…
92
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Flowchart
Start
i=1
max = -99
Read n
Print max i < n?
True
False
Read temp
Stop i=i+1
False
temp > max?
True
max = temp
# Organ Donation : It takes lives to save lives…
93
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure: Nested Selection
23. Seaview Chalet provides three types of room for accommodation. TABLE 1 shows the
rate for each type of room. If the guests check-in during the weekdays, 10% discount will
be given. A guest can make a reservation for more than one night. Calculate and display a
bill that a guest has to pay if he/she books a room for a number of days.
Input Process Output
hotel bills
Number of nights, Determine and calculate hotel bills based
week, type on number of nights, week and type given 94
by a user.
Pseudocode
Start
Read n, week, room
if (week = “Weekdays”)
if (type = ‘S’)
hotel bill = 0.9 x (n x RM300)
else if (type= ‘D’)
hotel bill = 0.9 x (n x RM220)
else
hotel bill = 0.9 x (n x RM180)
end if
else
if (type = ‘S’)
hotel bill = n x RM300
else if (type= ‘D’)
hotel bill = n x RM220
else
hotel bill = n x RM180
end if
Print hotel bill
end if
Stop
# Organ Donation : It takes lives to save lives…
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Start
Read n, week, room type
if (week = “Weekdays” & type = ‘S’)
hotel bill = 0.9 x (n x RM300)
else if (week = “Weekdays” & type= ‘D’)
hotel bill = 0.9 x (n x RM220)
else if (week = “Weekdays” & type= ‘B’)
hotel bill = 0.9 x (n x RM180)
else if (week = “Weekend” & type= ‘S’)
hotel bill = n x RM300
else if (week = “Weekend” & type= ‘D’)
hotel bill = n x RM220
else
hotel bill = n x RM180
end if
Print hotel bill
Stop
Flowchart
Start
Read n, week, type
True True
Type = ‘S’?
week = “WD”? Bill = 0.9 x (n x RM300)
True False False
Bill = n x RM300 Type = ‘S’?
True False Type = ‘D’? True
False Bill = 0.9 x (n x RM220)
Bill = n x RM220 Type = ‘D’?
Bill = n x RM180 Bill = 0.9 x (n x RM180)
Print Bill
Stop
# Organ Donation : It takes lives to save lives…
95
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure:
24. Consider a flowchart given in FIGURE 1.
FIGURE 1
Assume initial value of Nom is 5, trace the flowchart by filling the table below.
Count=0 Total=0 Read Nom≤15 Total =Total + Count = Nom= Nom Print
Count,
Nom Nom Count +2 +5 Total,
Nom
0 0 5 True 5=0+5 2 = 0 + 2 10 = 5 + 5
2 5 10 True 15 = 5 + 10 4 = 2 + 2 15 = 10 + 5
4 15 15 True 30 = 15+ 15 6 = 4 + 2 20 = 15 + 5
6 30 20 False ---------- loop terminate --------------- 6, 30, 20
# Organ Donation : It takes lives to save lives…
96
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure: Selection
25. Write the IPO analysis and pseudocode for e following flow chart
Input
No input
Process Calculate number add to 3 based
on number while number less or
equal than 10.
Output Number
Pseudocode
Number = 1
While (Number <=10)
Number = Number + 3
Print Number
End While
# Organ Donation : It takes lives to save lives…
97
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure: Selection
26. Lily wants to calculate an average of a series of positive numbers. The process will
stop if the number entered has a negative value.
Input Process Output
average
Determine to calculate an average of a
number series of positive number while number is
positive value.
Pseudocode
Start
bil = 0
total = 0
Read number
while (number > 0)
total = total + number
bil = bil + 1
Read number
end while
average = total / bil
Print average
Stop
Flowchart
Start
bil = 0
total = 0
Read number
False
average = total / bil number > 0?
Print average
True Read number
Total = total + number
bil = bil + 1
Stop
# Organ Donation : It takes lives to save lives…
98
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure: Selection
27. Harmony Ltd would like to calculate the total bonus that will be given to their
1,500 staff. The bonus given will be based on the year of service as shown in the
table below. Year of Service Bonus
Above 10 years RM3,000
5-10 years RM2,000
Below 5 years RM1,000
Input Process Output
Year of service Determine to calculate total bonus based Total bonus
on year of service for 1500 staff.
Pseudocode
Start
staff = 1
total bonus= 0
while (staff <= 1500)
Read year of service
if (year of service > 10)
bonus = 3000
else if (year of service >= 5)
bonus = 2000
else
bonus = 1000
end if
total bonus = total bonus + bonus
staff = staff + 1
end while
Print total bonus
Stop
# Organ Donation : It takes lives to save lives…
99
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure: Selection
Flowchart
Start
staff = 0
total bonus = 0
Print total bonus False staff <= 1500?
Stop True
Read year of services
True year of service >10
bonus = 3000 <= 1500?
True False
bonus = 2000 year of service >= 5
<= 1500?
False
bonus = 1000
Total bonus = total bonus + bonus
bil = bil + 1
# Organ Donation : It takes lives to save lives…
100
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure: Selection
28. Employees at Syarikat ABC Sdn. Bhd.
Get bonus at the end of the year as shown in the pseudocode in FIGURE 1. There are N
numbers of employees at the company. Bonus is 50% of the salary.
Input FIGURE 1 Output
Process Employee’s name, bonus
N, Calculate bonus based on salary entered by
Employee’s name, a user for N times.
salary
Flowchart
Read N
False i < N?
True
Read employee’s name, salary
bonus = 50% x salary i=i+1
Print bonus 101
# Organ Donation : It takes lives to save lives…
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
29. Modify the question 28 so that the bonus calculation is based on the salary’s grade given
in TABLE 1.
Salary Grade Bonus Rate
A 20%
B 40%
C 60%
Table 1
Input Process Output
Employee’s name, bonus
N, Calculate bonus based on salary and salary
Employee’s name, grade entered by a user for N times.
salary, salary grade
Pseudocode
Start OUTPUT:
i=1 ALI RM200
Read N SITI RM400
Repeat while ( i < N ) ABU RM600
Read employee’s name, salary, salary grade
if (salary grade = ‘A’)
Bonus = 0.2 x salary
else if ( salary grade = ‘B’)
Bonus = 0.4 x salary
else
Bonus = 0.6 x salary
end if
Print employee’s name, Bonus
i=i+1
End repeat
Stop
# Organ Donation : It takes lives to save lives…
102
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure: Selection
Flowchart
Start
i=1
Read N
False i > =N ? i=i+1
Stop
True Print employee’s
name, Bonus
Read employee’s name,
salary, grade
False True
Grade = ‘A’? Bonus= 0.2 x salary
False True
Grade = ‘B’? Bonus= 0.4 x salary
False
Bonus= 0.6 x salary
# Organ Donation : It takes lives to save lives…
103
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
30. An Nur Care Centre charges for monthly caring services based on a child’s age. Charges
for a child less than 24 months in RM 220 per month, for a child from 2 to 4 years old is
RM 180 per month and for child above 4 years old is RM 150 per month respectively.
Assume they are n children currently at An Nur Care Center. Given n children names and
ages, determine the monthly charge for each child.
Input Process Output
n children, Determine the monthly charge based on Monthly Charge
name, age name and age for n children.
Pseudocode
Start
children = 1
Read n children
While ( children < n children)
Read name, age
if ( age< 24 months ) OR if ( age< 2 years)
Monthly Charge = RM220
else if ( age< 48 months) OR ( age < 4 years )
Monthly Charge = RM180
else
Monthly Charge = RM150
end if
Print Monthly Charge
children = children + 1
End while
Stop
# Organ Donation : It takes lives to save lives…
104
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure: Selection
Flowcharts
Start
children = 1
Read n
children = children + 1
Stop children > n?
True Print charge
Read name, age
age < 2 years? Charge = RM220
age < 4 years? Charge = RM180
Charge = RM150
# Organ Donation : It takes lives to save lives…
105
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
31. Draw a flowchart based on the given problem analysis.
Input : number
Process : Determine whether the number is divisible by 7
Output : Either the message “Divisible by 7” or “Not divisible by 7” based on
number
Pseudocode Flowchart
Start Start
Read number Read number
if (number%7 = 0 )
Print “Divisible by 7”
else
Print “Not divisible by 7”
end if
Stop
False Print “Not
Divisible by 7”
Number%7=0?
True
Print “Divisible
by 7”
Stop
# Organ Donation : It takes lives to save lives…
106
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure:
32. A listening test is one of the
components in the MUET competency test that can be taken maximum 3 times by each
student. Students will have to redo the test if the marks obtained is less than 70. The final
mark obtained by students are calculated based on the average marks from all the
listening tests taken.
Input Process Output
Pseudocode
Flowchart
# Organ Donation : It takes lives to save lives…
107
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Control Structure:
33. Puan Marina is a programming lecturer at Kolej Teknologi Kedah. Due to the high failure
rate in her class, she intends to find the total number of students who have passed in the
examination. The passing mark is 40 marks and above. There are 98 students in her class.
Input Process Output
marks Determine to calculate the total number of Total number of students who
students who have passed in the have passed
examination based on marks for 98
students.
Pseudocode
Start
student = 1
Total Pass = 0
while (student <= 98)
Read marks
if (marks >= 40)
Total Pass = Total Pass + 1
end if
student = student + 1
end While
Print Total Pass
Stop
# Organ Donation : It takes lives to save lives…
108
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Flowchart
False Start
Print Total Pass student = 1,
Stop Total Pass = 0
Student < 98
True
Read marks
False Marks > 40
True
Total Pass = Total Pass + 1
Student = student + 1
# Organ Donation : It takes lives to save lives…
109
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
CCoonntrtorol lSStrtuructcuturer:e:
34. A former secretary had left her
job and decided to sell textbooks. Assume the book is sold at different price on each day.
Calculate how much money that will be earned after a week.
Input Process Output
price, Calculate total price book sold based on total price
number of book price and number of books for 7 days.
Pseudocode
Start
day = 1
total price = 0 total = price x qtty
while (day <= 7) total price = total price + price
Read price, number of book
total price = total price + (price x number of book)
day = day + 1
end while
Print total price
Stop
Flowcharts
Start
day = 1, total price = 0
Print total price False day < 7
Stop
True
Read price, number of book
total price = total price + (price x number of book)
day = day + 1
# Organ Donation : It takes lives to save lives…
110
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
35. The sales manager at MN Company wants to display the price based on a product ID she
enters. Assume there are ‘n’ items. The valid product IDs and their corresponding prices
are shown here. For each item, if the product ID is not valid, the program should display
the “Invalid product ID” message.
Product ID Price
4 12.00
8 50.55
Input Process Output
n, Determine the price based on product ID Price or
product ID
entered by a user for n times. message “Invalid product ID”
Pseudocode
Start If (product Id = 4)
counter = 1 Print “ Price is RM12.00”
Read n
while (counter <= n)
Read product ID
if (product ID = 4)
Price = RM12.00
Print Price
else if (product ID = 8)
Price = RM50.55
Print Price
else
Print “Invalid product ID”
end if
counter = counter + 1
end while
Stop
# Organ Donation : It takes lives to save lives…
111
1.0 Problem Solving [REPETITION]
1.2 Problem Analysis
1.3 Design a Solution
Flowcharts
Start
counter = 1
Read n
Stop False counter < n
True
Read product ID
Product ID = 4 True
Price = RM12.00
False True
Product ID = 8 Price = RM50.55
False Print price
Print “Invalid product ID”
counter = counter +1
# Organ Donation : It takes lives to save lives…
112