Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

Chapter 4

INTRODUCTION TO
PROBLEM SOLVING AND
WRITING ALGORITHMS
Learning outcome

 Explain basic techniques of problem solving


 Analysis the problem using Problem Analysis Chart
 Design the algorithm
 Draw the flowchart
Problem solving
 Programming is a process of problem solving
 Problem solving techniques
 Analyze the problem
 Outline the problem requirements
 Design steps (algorithm) to solve problem
 Algorithm
 Step-by-step problem solving process
 Solution achieved in finite amount of time
 Flowchart
 graphical representation of the algorithm
What is PDLC?

 When we want to develop a program using any


programming language, we follow a sequence of
steps.
 These steps are called phases in program
development. The Program Development Life
Cycle is a set of steps or phases that are used to
develop a program in any programming
language.
PDLC

 PDLC contains 6 phases which are:


1. Problem Definition
2. Problem Analysis
3. Algorithm Development
4. Coding
5. Testing and Debugging
6. Documentation and Maintenance
Step 1 – Problem Definition
 The process defining the problem statement and
identify the boundaries of it.
 In this phase we need to understand the problem
statement and what is the requirement needed.
Step 2 – Problem Analysis
 A process of identifying the input, processes and output of
a program.
 Identify (IPO) :
i. Input (given data)
ii. Process (solution – relation between input and output; can
using formula)
iii. Output (the result)

Input Process Output


Analyzing the Problem
Understand requirements:
1. The given data- Input
2. The required results- Output
3. The processing that is required in the problem-Formula
4. A list of solution alternatives - Assumptions made

0-8
Problem Analysis Chart

0-9
Problem Analysis Chart for the Payroll
Problem

0-10
From step 1 and step 2;
 Understanding the problem:
 The feasibility
 The limitation
 Identify the following
 Input – prerequisite, data that exist at the beginning of the problem
 Output – the expected data/information/result from the program
 Process – set of steps that need to be done in getting the output
Example 1:
Write a problem analysis for program that can input 2 integer
number from user. Find the addition for the number and
display the result. Draw the respective PAC chart.

Problem analysis
 Input  number1 and number2
 Process  result = number1 + number2
 Output  display result
Problem Analysis Chart
Given Data Required Result

number1, number2 Result

Processing Solution Alternatives

Result = number1 + number2 1. Input as Integer.


2. Output as Integer
Example 2

Write a problem analysis that reads a number in feet, converts it to


meters, and display the results. One feet is 0.305 meter.

Enter a value for feet: 16.5


16.5 feet is 5.0325 meters

Input  read feet


Process  meter = feet * 0.305
Output  display meter
Problem Analysis Chart
Given Data Required Result

Feet Meter

Processing Solution Alternatives

Meter = Feet * 0.305 1. Input as Real


2. Output as Real
* Ignore Module Ref..not included in your syllabus.
Step 3 - Algorithm Development
 Planning the solution to a problem
 Plan on how to solve the problem by using
algorithm.
 Algorithm is a set of specific, sequential steps
that describe exactly what the program must do
to complete the tasks.
Flow chart
 Graphical representation of an
algorithm/pseudocode
 Usespecific shapes/symbols indicate program
behaviours and decision types
Flow chart - Symbols
FLOW CHART – Symbols (cont..)
Example 3
Write an algorithm for a program that input 3 numbers from user. Find
the summation of the number and lastly display the result.Draw the
respective flowchart

Algorithm Flowchart

1. Start Start
2. Set sum = 0
Set sum = 0
3. Read 3 integer number
4. Total up 3 integer Read a, b and c
number
sum = a + b + c Calculate sum =
5. Display sum a+b+c

6. End Display sum

End
Example 4

Write an algorithm that can input 3 integer number from user.


Find the average for the number. Display all the the average.

Input  number1, number2 and number3


Process  1. sum = number1 + number2 +
number3
2. average = sum/3
Output  display average
Algorithm Flowchart

1. Start Start
2. Set sum = 0 Set sum =
3. Read 3 integer number 0
4. Total up 3 integer Read a, b and
number c

sum = a + b + c sum = a+b+c


average = sum / 3
5. Calculate the average
average = sum/3 Display average
6. Display average
7. End End
Step 4 - Coding And Documentation
 Algorithms is translated into a specific
programming language based on its language rules
(syntax)
Step 5 - Testing And Debugging
 Eliminating errors
 Type of errors :
1. Syntax error – violation of rules of a language in which
computer is written (example : leaving out semicolon (;)
would stop the entire program from working)
2. Logic error – error that occurs when a programmer has
used incorrect calculation or left out a programming
procedure (example : number divided by 0  9÷0)
Step 6 – Maintenance
 Integrate your code or program with others (if
necessary)
 Test the whole complete system
 Development team
 User
 Documentation
 Testingresult
 User Manual or User Guide

You might also like