0% found this document useful (0 votes)
98 views30 pages

Chapter 1.0 - Steps in Problem Solving

The document outlines the 5 main steps in problem solving: 1) Problem analysis to identify the inputs, processes, and outputs. 2) Designing a solution such as creating an algorithm using pseudocode or a flowchart. 3) Implementation by coding the design into a programming language like Java. 4) Testing the program with sample inputs to check for errors. 5) Creating documentation through comments in the code or a separate document.

Uploaded by

azlan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views30 pages

Chapter 1.0 - Steps in Problem Solving

The document outlines the 5 main steps in problem solving: 1) Problem analysis to identify the inputs, processes, and outputs. 2) Designing a solution such as creating an algorithm using pseudocode or a flowchart. 3) Implementation by coding the design into a programming language like Java. 4) Testing the program with sample inputs to check for errors. 5) Creating documentation through comments in the code or a separate document.

Uploaded by

azlan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

1.

0
Steps in Problem
Solving
1
1.1 Identifying steps in problem solving

At the end of this lessons, students should able to :


a) Describe five steps in problem solving: problem analysis,
design a solution, implementation, testing and
documentation. (CLO 1)

2
a) Describe steps in problem solving : problem
analysis, design a solution, implementation, testing
and documentation

Define problem solving :


is the process of transforming the description of a problem into
a solution

3
Steps in Problem Solving

4
Step 1 : Problem Analysis

An analysis of a problem statement to identify input,


process and output (IPO)

5
Step 1 : Problem Analysis

INPUT Identifying required data to solve the problem

PROCESS Explanation of how the data is processed based on


the input entered

OUTPUT The result- can be value or message 6


Problem Analysis :
Types of Control Structure

Types of Control Description


Structure
Sequence a series of actions that are sequentially
executed in the order they are written
Decide which statements to execute
Selection
based on a condition
Repetition / Looping used to tell a program to execute
/ Iteration statements repeatedly

7
Problem Analysis :
Types of Control Structure
Loop / Repetition
Sequence Selection /Iteration

8
Step 2 : Design a Solution

Design a solution involves creating an algorithm.

Definition :
An algorithm describes how a problem is solved by
listing the actions that need to be taken and the order
of their execution.
It lists the steps you can follow to solve a problem.

* (for details, please refer to Chapter 3.0 : Design a


solution) 9
Algorithm - Purpose

Purpose :
Algorithms can help the programmer plan a
program before writing it in a programming
language.

10
Techniques in Algorithm

Two techniques that can be used to represent


algorithm :
- Pseudocode : natural language mixed with some
programming code
- Flowchart : is a diagram that describes an
algorithm or process, showing the steps as boxes
of various kinds, and their order by connecting
these with arrows.

11
Pseudocode and Flowchart

Problem Analysis Pseudocode Flowchart

Input : - Start Start


display “Hello World”
Process : - Stop

Output : “Hello World” display “Hello


World”

Stop
12
Step 3 : Implementation

- Implementation involves translating the system


design into programs.
- also known as coding (writing the code)
- This phase requires the use of a programming
language such as Java.
- The implementation involves coding, self testing,
and debugging (that is, finding errors, called bugs,
in the code).
* (for details, please refer to Chapter 4.0 : Java Language)
13
Step 4 : Testing

After the program is implemented, test it with some


sample input data and verify whether the output is
correct.

Testing ensures that the code meets the requirements


specification and weeds out bugs.

14
Purpose of Testing

i) To ensure that the system meets the user's


requirement
ii) To ensure the programs run correctly

15
Types of Error

- Error also called bug


- Debugging : process of removing errors from the
program
Programming errors can be categorized into three
types:
i) Syntax error
ii) Runtime error
iii) Logical error
16
i) Syntax Error

- Errors that are detected by the compiler


* The Program will not run

Syntax errors result from errors in code construction, such as


i) mistyping a keyword
ii) omitting some necessary punctuation
iii) using an opening brace without a corresponding closing
brace

syntax errors are easy to find and easy to correct because the
compiler gives indications as to where the errors came from
and why they are wrong.
17
Syntax Error - Example

18
ii) Runtime Error

Runtime errors are errors that cause a program to


terminate abnormally.

Runtime errors are not difficult to find, either, since


the reasons and locations for the errors are displayed
on the console when the program aborts.

19
Runtime Error - Example

Example :
i) Input mistakes typically cause runtime errors.
- An input error occurs when the program is waiting for
the user to enter a value, but the user enters a value
that the program cannot handle.
ii) division by zero
- This happens when the divisor is zero for integer
divisions. (eg : 1 / 0)

20
Runtime Error - Example

21
iii) Logic Error

Logic errors occur when a program does not perform


the way it was intended to.
The only sign of logical error is incorrect output

22
Logic Error - Example 1

Example 1:
- Wrong Semicolon at the if Line

23
Logic Error - Example 2

You will get Fahrenheit 67 degrees, which is wrong.


It should be 95.0. In Java, the division for integers is the quotient
—the fractional part is truncated—so in Java 9 / 5 is 1.
To get the correct result, you need to use 9.0 / 5, which results in
1.8. 24
Step 5 : Documentation

- Documentation is the body of explanatory remarks


and comments pertaining to a program.
- It contains a description of the program that helps
other programmers in editing or maintaining the
program later.
- They are not programming statements and thus are
ignored by the compiler.

25
Documentation

Can be done in 2 ways:


- i) Writing comments between your lines of codes
- ii) Creating a separate text file to explain the
program

26
Comment Style

In Java, comments are preceded by


i) line comment
- two slashes (//) on a line,
ii) block comment (paragraph comment)
- enclosed between /* and */ on one

27
Comment Style - Example

// This application program displays Welcome to Java!

/* This application program displays Welcome to Java! */

/* This application program


displays Welcome to Java! */

28
Documentation - Purpose

i) Comments help programmers to communicate and


understand the program.
ii) make programs easy to read.
iii) understand the flow of the program for future
reference.
iv) Explain the purpose of code statement

29
Quick Test 2

30

You might also like