2.0 Approach in Problem Solving 20222023
2.0 Approach in Problem Solving 20222023
0 Approach
in Problem
Solving
2.0 Approach in Problem Solving
Learning Outcomes
At the end of this topic, you should be able to:
Problem Analysis
General Format
Input : I :
Process : P :
Output : O :
2.0 Approach in Problem
Solving
b) Identify input, process and output based on
the given problem statement. IPO - Sequence (T)
Sequence Control Structure
• A sequence control structure performs actions one after another
in sequence
• All actions will be executed, none will be skipped
• Actions can be input, process, or output.
1 Sequence
Problem Analysis
General Format
Sequence
Input : I :
Process : Calculate P : Calculate output
output O :
Output :
Example 1
• Problem statement:
• Identify input, process and output to calculate the area of a rectangle.
• Problem analysis:
I : mark
P: Determine message based on mark
O: “PASS” or no output
Example 2
• Problem statement:
• Create a problem analysis if an employee works more than 40 hours a week,
compute his overtime pay which is half of his salary.
• Problem analysis:
I: hour, salary
P: Determine overtime based on hour
O: overtime or no output
Example 3
• Problem statement:
• Identify input, process and output to calculate area of circle when radius is
greater than 0 and display the area.
• Problem analysis:
I: radius
P: Determine area based on radius
O: area or no output
Checkpoint 3
Refer tutorial week 2
2 Selection
Problem Analysis
General Format
Dual Selection
Input : I :
Process : Determine P : Determine output
output based on input /
based on input / condition
condition O :
Output :
Example 1
• Problem statement:
• Create a problem analysis that will accept student’s mark. If a student’s mark
is greater than 60, print the message “PASS”. Otherwise, print the message
“FAIL”.
• Problem analysis:
I: mark
P: Determine appropriate message based on mark
O: “PASS” or “FAIL”
Example 2
• Problem statement:
• Create a problem analysis that will accept two numbers from user. Display a
message “First number is bigger” if first number is bigger than second
number. Otherwise display a message “Second number is bigger”.
• Problem analysis:
I: num1,num2
P: Determine appropriate message based on num1,num2
O: “First number is bigger” or “Second number is bigger”
Example 3
• Problem statement:
• Identify input, process and output to calculate area of circle when radius is
greater than 0.0 and display the area. If not, display “Radius can’t be a
negative number”.
• Problem analysis:
I: radius
P: Determine area based on radius
O: area or “Radius can't be a negative number”
Example 4
• Problem statement:
• KTM will give 30% discount of train ticket price if a person is below 20 years
old, otherwise only 5% discount will be given. Identify input, process and
output to calculate and print the ticket price.
• Problem analysis:
• Problem analysis:
I: gender
P: Determine appropriate message based on gender
O: “I am a man” or “I am a women”
Checkpoint 4
Refer tutorial week 2
2 Selection
Problem Analysis
General Format
Multiple Selection
Input : I :
Process : Determine P : Determine output
output based on based on input
input O :
Output :
Example 1
• Problem statement:
• Do problem analysis when mark is greater than or equal to 85 print “A”, mark
is greater than or equal to 65 print “B”, else print “FAIL”.
• Problem analysis:
I: mark
P: Determine appropriate message based on mark
O: “A” or “B” or “FAIL”
Example 2
• Problem statement:
• Do problem analysis to accept a number from user, and to determine and
display whether the number is “positive”, “negative” or “zero”.
• Problem analysis:
I: number
P: Determine appropriate message based on number
O: “positive” or “negative” or “zero”
Example 3
• Problem statement:
• Do problem analysis to display the name of the program that will be assigned
based on code in the following table:
Code Program
1 Multimedia
2 Networking
3 Robotics
• Problem analysis:
I: code
P: Determine appropriate message based on code
O: “Multimedia” or “Networking” or “Robotics”
Example 4
• Problem statement:
• Table shows the rate that is used to calculate the delivery cost based on
distance code and weight. Do the problem analysis.
Code Weight Delivery cost per kg (RM)
A under 5kg 10.00
5kg or more 16.5
B under 5kg 32.00
5kg or more 47.95
• Problem analysis:
I: code, kg
P: Determine cost based on code and kg
O: cost
Checkpoint 5
Refer tutorial week 2
2.0 Approach in Problem
Solving
b) Identify input, process and output based on the
given problem statement. IPO - Repetition (T)
Repetition Control Structure
• The repetition (or looping) structure allows a sequence of instructions
to be executed repeatedly until a certain condition is reached.
3 Repetition
Problem Analysis
General Format
Counter-Controlled
Input : I :
Process : Repeat input to P : Repeat input to output
output for for condition
condition O :
Output :
Example 1
• Problem statement:
• Identify input, process and output to print “Welcome to KMJ” 10 times.
• Problem analysis:
I: no input
P: Repeat display message for 10 times
O: “Welcome to KMJ”
Example 2
• Problem statement:
• Identify input, process and output to display 5 numbers entered by user.
• Problem analysis:
I: number
P: Repeat reading and display number for 5 times
O: number
Example 3
• Problem statement:
• Identify input, process and output to display first 5 positive numbers.
• Problem analysis:
I: no input
P: Repeat display the first 5 positive number
O: first 5 positive number
Example 4
• Problem statement:
• Identify input, process and output to calculate the total of 5 numbers entered
by user and print the total.
• Problem analysis:
I: number
P: Repeat reading and adding number to total for 5 times.
O: total
Example 5
• Problem statement:
• Identify input, process and output to calculate the total of first 5 positive
numbers and print the total.
• Problem analysis:
I: no input
P: Repeat adding first 5 positive number to total.
O: total
Checkpoint 6
Refer tutorial week 2
3 Repetition
Problem Analysis
General Format
Sentinel-Controlled
Input : I :
Process : Repeat input to P : Repeat input to output
output until until condition
condition O :
Output :
Example 1
• Problem statement:
• Identify input, process and output to calculate the total marks entered by user
until the user key in -1.
• Problem analysis:
I: mark
P: Repeat reading and adding mark to total until mark = -1
O: total
Example 2
• Problem statement:
• Identify input, process and output to accept numbers input by user. Print
positive numbers only. Loop will only stop when user enters number 0.
• Problem analysis:
I: number
P: Repeat reading number and determine positive number until number=0.
O: positive number
Example 3
• Problem statement:
• Identify input, process and output to calculate the total and average marks
entered by user until the user key in -1.
• Problem analysis:
I: mark
P: Repeat reading and adding mark to total until mark = -1 and
calculate average
O: total, average
Checkpoint 7
Refer tutorial week 2