0% found this document useful (0 votes)
37 views

2.0 Approach in Problem Solving 20222023

Uploaded by

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

2.0 Approach in Problem Solving 20222023

Uploaded by

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

2.

0 Approach
in Problem
Solving
2.0 Approach in Problem Solving
Learning Outcomes
At the end of this topic, you should be able to:

a) Describe steps in problem solving: problem analysis, design a


solution, implementation, testing and documentation). (L)
b) Identify input, process and output based on the given problem
statement. (T)
Problem Solving
● Problem solving is the process of
transforming the description of a
problem into a solution.
● by using our knowledge of the problem
domain and
● by relying on our ability to select and use
appropriate problem solving strategies,
techniques and tools.
Steps in Problem Solving

Step 1 Step 2 Step 3


Problem Design a Implementation
Analysis Solution
Step 4 Step 5
Testing Documentation
Step
1 Problem Analysis
An analysis of a problem statement to identify input, process and output.

Input Process Output


the input to the the relevant process the required output
problem to produce output
and
Step
2 Design a Solution

● Design a solution involves creating an algorithm.

● An algorithm is a sequence of well-defined steps


to solve a problem.

● two types of algorithms.


- pseudocode
- flowchart
Step
3 Implementation

process of implementing an algorithm by


writing a computer program using a
programming language (for example,
using Java language).
Step
4 Testing
process of executing a
program to demonstrate its
correctness (i.e. run the Program verification
program).

process of ensuring that a


Program testing program meets
user-requirement (i.e.
test/verify it with different
inputs).
Step
5 Documentation
● Documentation contains description of the program that
helps other programmers in editing or maintaining
the program later.
● Documentation can be done in 2 ways:
1. Writing 2. Creating a
comments separate text file
between your to explain the
lines of codes program
Checkpoint 2.0
1. State five step involves in problem solving.
2. List the first and the last step in problem solving.
3. Describe the third step in problem solving.
2.0 Approach in Problem Solving
Learning Outcomes
At the end of this topic, you should be able to:

a) Describe steps in problem solving: problem analysis, design a


solution, implementation, testing and documentation). (L)
b) Identify input, process and output based on the given problem
statement. (T)
Step
1 Problem Analysis

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: area rectangle = width x height

Input : width, height


Process : Calculate area rectangle
Output : area rectangle
Example 2
• Problem statement:
• Identify input, process and output to find the sum of three numbers entered
by user.

sum = num1 + num2 + num3


• Problem analysis:

Input : num1, num2, num3


Process : Calculate sum
Output : sum
Example 3
• Problem statement:
• Identify input, process and output to determine the price of mangoes, given
the weight purchased (in kg) and the price of mangoes per kg.

• Problem analysis: price mangoes


= weight x price per kg
Input : weight, price per kg
Process : Calculate price mangoes
Output : price mangoes
Checkpoint 2
Refer tutorial week 1
2.0 Approach in Problem
Solving
b) Identify input, process and output based on the
given problem statement. IPO - Selection (T)
Selection Control Structure
• Statements that are executed are dependent on certain conditions
that are evaluated either true or false.
• Many situation that may involve selection, for example while
driving a car. When we at the T junction, we have to choose which
direction have to follow either right or left.

Make your own


decision
2 Selection
Problem Analysis
General Format
Single Selection
Input : I :
Process : Determine P : Determine output
output based
based on input / on input / condition
condition O :
Output :
Example 1
• Problem statement:
• Create a problem analysis that will accept student’s mark. If the mark is
greater than 60, print the message “PASS”.

• 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:

I: age, original ticket price


P: Determine ticket price based on age
O: ticket price
Example 5
• Problem statement:
• Identify input, process and output that will print “I am a man” if a person
gender is male, otherwise print “I am a women”.

• 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

You might also like