Designing a solution to a problem involves 6 steps:
Analyze the problem
Plan the algorithm
Desk-check the algorithm
Code the algorithm into a program
Desk-check the program
Evaluate and modify the program ( if necessary).
Step 1 − Analyzing the Problem
It is essential to understand a problem before creating a solution to it. During analysis, the goal
(output) to solve the problem and the items needed (Input) to achieve the goals are determined.
An IPO (Input, processing, and output) chart is used to organize and summarize the
results of a problem analysis.
Example: of an IPO chart
Scenario: write a program that calculates and displays the circumference of a circle given the
radius
(r). The circumference is computed as 2Pi(r).
Based on this scenario, the following IPO Chart can be designed to help design a programmer to
solve the above problem. Note that Processing Item is a variable that is needed to hold a value
while processing.
Step 2 − Planning the Algorithm
An Algorithm is a set of instructions that will transform the problem’s input
into
a output.
It can be written either as pseudocode or a flowchart. It is recorded in the Processing column
of
the IPO chart.
Pseudocode is short English statements to plan an algorithm.
Example 1: An algorithm to calculate the circumference of a circle
Get the radius
Calculate the Circumference of the circle by using the formula: 2 * PI * radius
Display Circumference of Circle
Example 2: An algorithm to print "passed" if the students marks is greater than 50 and
prints "failed" otherwise
If student's mark is greater than or equal to 50 then
Print "passed"
else
Print "failed"
Example 3: An algorithm to determine the average marks for the class size of 10
Set total to zero
While grade counter is less than or equal to ten
Input the next grade
Add the grade into the total
endwhile
Set the class average to the total divided by ten
Print the class average.
A Flowchart uses standardized symbols to design the algorithm.
Example of a flowchart which calculates the circumference of a circle
Step 3 − Desk-check the algorithm
Desk-checking (also called hand-tracing) is checking an algorithm by hand (e.g.
using pen and paper) to verify its correctness.
A set of sample data is chosen and the expected output value is manually computed.
A desk-check table is used while desk-checking an algorithm. It should contain valid and invalid
data
Valid data: data that the algorithm is expecting the user to enter
Invalid data: data that the algorithm is not expecting the user to enter. Users may make
mistakes when entering data so your program should handle these errors appropriately.
Example of a desk-check table:
Table i
Sample
Radius
Circumference
1
2
12.57
2
5.5
34.57
3
0
Radius should be positive
4
-5
Radius should be positive
5
m
Radius should be numerical
Step 4 − code the algorithm into the program
In this step, each unique input, processing, and output item in the IPO chart is given a
descriptive
name, data type, and (optionally) an initial value.
Then the algorithm is written using a programming language.
Step 5 − Desk-Check the program
This step is performed to ensure that the instructions were translated correctly. The program is
desk-checked using the sample data used to desk-check the algorithm in step 3.
The results of both desk checks should be the same.
Step 6 – Evaluate and Modify the Program
This is the final step in the problem-solving process where errors (known as bugs) are fixed
which
were found while evaluating the program in step 5.
The process of locating and fixing errors is called debugging. There are two types of bugs:
syntax
errors and logic errors.
Syntax errors are caused by violating the rules of a programming language.
Compilers can detect these errors.
Logic errors are caused by applying incorrect logic in the program. The
compiler is not able to detect these types of errors and can be hard to identify. E.g.
entering instructions in the wrong order.