JIT10203 Chapter2.0 - Problem Solving
JIT10203 Chapter2.0 - Problem Solving
Problem
Solving
Basic concept in computer
system
• Hardware and Software
Basic concept in
programming
• About Programming
• Application in Programming
How to THINK like a
PROGRAMMER?
Programming
is about
problem
solving;
thinking
logically and
breaking down
a problem into
steps to find a
solution
How to breaking down a
problem into steps to find
a solution?
INPU PROCES OUTP
T S UT
Weight, w Calculate BMI
= 50kg BMI = ??
Height, h = BMI =
160cm
Example
1
Calculate Ali’s BMI given his Weight, w =
50kg and Height, h = 160cm
Let’s Test Your
Understanding
Determine a student’s
final grade and
indicate whether it is
passing or failing. The
final grade is
calculated based on
the average of four
marks. IfQuestion:
the average
mark is below than
Define Input, Process and
50,Output
the from
gradethisis FAIL
problem
and vice versa.
HOW TO DESCRIBE THE
PROCESS BEFORE
TRANSLATE INTO
PROGRAMMING
LANGUAGE?
WHAT WILL
YOU LEARN
IN
THIS
CHAPTER?
1 PSEUDOCODE
2 ALGORITHM
3 FLOWCHART
WHAT IS THE
DIFFERENCE?
Informal
high-level Step by step Pictorial
description sequence of representatio
of an solving a n of an
algorithm. given algorithm
Pseudocode problem
is very
similar to
everyday
PSEUDOCODE
&
ALGORITHM
Example
Calculate Ali’s BMI given his Weight, w =
INPU
50kg and Height,PROCES
h = 160cm OUTP
T S UT
Weight, w Calculate BMI
= 50kg BMI = ??
Height, h = BMI =
160cm
Solution
Pseudoco Algorith
de m
1. Input Ali’s Weight (w) 1. STEP 1: Input w
and Height (h) and h
2. Calculate BMI, Weight 2. STEP 2: BMI = w /
(kg) divided by squared h²
Let’s Test Your
Understanding
Write an algorithm to
determine a student’s
final grade and
indicate whether it is
passing or failing. The
final grade is
calculated based on
the average of four
marks. IfQuestion:
the average
mark
Writeis below than
PSEUDOCODE and
50, the grade for
ALGORITHM is this
FAIL
problem
and vice versa.
SOLUTION
PSEUDOCODE
1. Input a set of 4 ALGORITHM
1. STEP 1: M1, M2, M3,
M4
marks
2. Calculate their 2. STEP 2: GRADE =
average by (M1+M2+M3+M4) / 4
summing and 3. STEP 3: If (GRADE <
dividing by 4 50) then
3. If average is below print
50 “FAIL”
4. Print “FAIL” Else
5. Else print
6. Print “PASS” “PASS”
FLOWCHART
&
ALGORITHM
FLOWCHART
• (Dictionary) A pictorial representation of a
sequence of operations in a computer program
END
Exampl
e 1 algorithm and
Write a pseudocode,
draw a flowchart to convert the length
in feet (ft) to centimeter (cm)
PSEUDOCODE ALGORITHM FLOWCHART
1. Input the
length in feet 1. STEP 1: Input L STA
(ft) RT
(ft)
2. STEP 2: Lcm = L
2. Calculate the x 30 INPUT L
(ft)
length in 3. STEP 3: Print Lcm
centimeter Lcm = L x 30
(cm) (multiply
with 30) PRINT
3. Display length Lcm
in centimeter
END
(cm)
Example
2
Write a pseudocode, algorithm and
draw a flowchart that will read a two
sides of a rectangle and calculate its
PSEUDOCODE
area ALGORITHM FLOWCHART
1. Input the 1. STEP 1: Input L
Length (L) and W
STA
RT
and Width (W) 2. STEP 2: A = L x INPUT
2. Calculate the W L and
W
area, (A) of 3. STEP 3: Print A
rectangle A=LxW
(multiply with L
and W) PRINT
A
3. Display area
of rectangle END
Example HINT:
3
Write a pseudocode, algorithm
and draw a flowchart that will ax 2 bx c 0
calculate the roots of a FLOWCHART
PSEUDOCODE ALGORITHM
quadratic equation STA
1. Input RT