DFC1023
PROBLEM SOLVING
AND PROGRAM
DESIGN
CHAPTER 2.0
PROBLEM SOLVING METHODS
1
COURSE LEARNING OUTCOME (CLO):
Upon completion of this course, students should be able to:
1) Explain the basic computer and programming
fundamentals with appropriate examples of languages.
2) Practice different types of algorithm to solve problem
efficiently.
3) Solve problem by applying related theories of the basic
programming technique to a given particular scenario
using programming life cycle.
2
SPECIFIC OUTCOME:
2. 1 Understand problem solving concept.
2.2 Demonstrate the understanding of Programming
Life Cycle.
2.3 Apply the different types of algorithm to solve
problem.
3
2.1 UNDERSTAND PROBLEM SOLVING CONCEPT
4
5
PROBLEM SOLVING CONCEPT
Identifying the problem--Which problem should I address? If
there are several, how do I choose the most important one?
Describing the problem--How do I accurately and completely
describe the problem?
Analyzing the problem--What are the different causes of the
problem, and which causes are most important to solve right
away?
Planning the solutions--What are the different alternative
solutions for solving the problem?
Implementing the solutions--How do I make sure the
solutions are implemented correctly and effectively?
Monitoring/evaluating the solutions--How did the solutions
work? What needs to be changed? 6
Define Input, Process
And Output
DEVELOPING THE INPUT PROCESS OUTPUT (IPO)
CHART
⚫ Extends and organizes the information in the
Problem Analysis Chart.
⚫ It shows in more detail what data items are input,
what are the processing or modules on that data,
and what will be the result or output.
Input Processing Output
All input All processing steps All output
data from from IPO requirements
PAC from PAC 7
Identify Input, Process
And Output
DEVELOPING THE INPUT PROCESS OUTPUT (IPO)
CHART
Problem
Write a Input Process Output (IPO) to find an area of
a circle where area = pi * radius * radius
Input Processing Output
- Area of a circle
- radius - Area = 3.14 x radius x radius
-Display area 8
Example
A program is required to read three (3) numbers,
add them and print their total. It is usually helpful
to write down the three (3) components in a defining
diagram as shown below:
9
STEPS OF PROGRAM EXECUTION
Input – Refers to the process of entering data, program and
instructions into the computer system using input devices.
Process – Computer processes raw data into usable
information to be used by user. Data processing is done by the
CPU (Central Processing Unit).
Output – Output is raw data that has been processed by the
computer (result). Output will be converted to an
understandable form before being displayed or printed.
10
EXAMPLE: FLOW OF ATM PROGRAM
• Assume that our transaction is money withdrawal.
The instructions are:
a. Get the card number from the user (Input)
b. Get pin number from the user (Input)
c. Process the input data (Process)
d. Get the transaction chosen by the user (Input)
e. Get the account type from the user (Input)
f. Process the transaction as wanted by the user (Process)
g. Withdraw amount of money required by the user(Output)
h. Print receipt for the user (Output)
11
INPUT PROCESS OUTPUT
Input: Example: Card number, ATM pin number, type of
transaction, type of account, amount of money to
withdraw.
Process: Example: Process to identify card number, valid pin
number, type of transaction, type of account and deducts
the withdrawal from the user’s account.
Output: Example: Receipt will show balance in user’s account
and money withdrawn.
12
EXECUTING A PROGRAM 13
To execute a program, CPU will examine each
program instruction in memory and send out the
required command signals to carry out the
instruction.
During execution, data can be entered into memory
and manipulated in some specific way (delete and
modify) as required.
Program instructions are used to copy a program's
data (program input) into memory.
After the input data were processed, instructions for
displaying or printing will be executed.
Result displayed by a program is called “program
output”.
Example: Cash withdrawal from ATM machine.
Step 1 Machine language Step 2
program for processing Central Processing Unit.
Input data: card number and PIN
Card Number, Program Output Step 3
PIN Number, number. Output results:
transaction.
Data entered during Receipt and money
execution.
Computed results.
• First step:
– Data entered by user are stored in memory (input).
• Second step:
– CPU will instruct program to process the card number and
ATM pin number with the data in memory concurrently.
Program will execute the transaction chosen by the user and
store the result in memory.
• Third step: 14
– The outputs are money withdrawal and receipt (output).
ACTIVITY 1: FIRE SIDE CHAT
1. Build a group in 3
2. Recall what you have learn in chapter 1 and
chapter 2 (2.1)
3. Write down 3 things that you have learned in
class (only 3 parts)- 3 minutes
4. Move to your friends in class and share the
answer (1 friend=1 aswer)
5. Move again to other friends and share the answer
until you fullfill 7 parts of TREE GRAPHIC
6. I will call 3 people to share the answer
15
DISCUSS ☺
1. Show step of mailing a copy of your SPM
transcript using photocopy machine.
2. Show step of making call from your telephone.
3. Show step of saving your document in your
computer.
4. Show steps of buying a tin of soft drink for a
vending machine.
5. Show steps of sending an email to your friend.
16
2.2 DEMONSTRATE THE
UNDERSTANDING OF
PROGRAMMING LIFE CYCLE
17
PROGRAMMING LIFE CYCLE
Life Cycle: Refers to the changes made from an old
to a new program (the cycle starts again).
Programming Life Cycle: A framework or discipline,
which uses certain techniques needed in computer
programming development.
18
STEPS INVOLVED IN PROGRAMMING LIFE
CYCLE:
1. Specify the 2. Analyze the 3. Program
problem problem design(the
algorithm)
6. Maintain 5. Test and 4. Program
and update verify coding(Implem
7. ent the
Documentatio algorithm)
n 19
STEP 1: SPECIFY THE PROBLEM
• Describe exactly what you are doing as clear as
possible
• the data to be used, and what can be assumed.
Also, the desired output and its layout.
• Specification of needs
what the problem is
what is needed to solve it
what the solution should provide
if there are constraints and special conditions.
20
EXAMPLE
Situation:
Joe Jambul was borrowing a book form PBU library.
He was late returning a book late. Calculate the total
fine charged to Joe Jambul by library for late-return
books. The charge is RM0.20 for 1 day.
Specify the problem:
Calculate the total fine charged to Joe Jambul by
library for late-return books.
Data given (RM 0.20/day)
21
STEP 2: PROBLEM ANALYSIS
▪ To describe in detail a solution to a problem and
information needed in solving the problem. Study and
understand the problem.
▪ Identify:
▪ The needed input.
▪ The needed process.
▪ The required output.
▪ Special constraints (if any)
▪ Formulas or equations to be used
22
STEP 3: PROGRAM DESIGN
Definition:
It is a framework or flow that shows the steps in
problem solving.
23
Step 3: Program Design cont.
METHODS TO DESIGN A PROGRAM:
1. Algorithm
⚫ Algorithm is a sequence of instructions to solve a
problem, written in human language, and it can
solve any problems when it is used with the correct
procedure. (Example)
2. Flowchart
✔ A graphical representation of data, information
and workflow using certain symbols that are
connected to flow lines to describe the instructions
done in problem solving.
✔ It shows the flow of the process from the start to24
the end of the problem solving. (Example)
EXAMPLE OF ALGORITHM
situatiowCqnuhailezcrzueelastht.eeaunsderdsishpalavey the total mark of three quizzes,
to enter the mark of each
algorit12h.. mICnapluctumlaaterktostfaolrmqaurizk1:,tqoutaizlM2,aarknd= quiz3
quiz1+quiz2+quiz3
3. Print totalMark
25
BACK
26
ACTIVITY 2:DISCUSSION 27
(20 MINUTES)
1. Create 8 group (7 people/group)-
2 minutes
2. Get a topic, marker pen, paper
3. Discuss in group
4. Write the algorithm in paper
given
5. Choose BEST GROUP as
WINNER
(faster, correct , creative and
tidiness)
EXAMPLE OF FLOWCHART Start
TotalMark = 0
ALGORITHM: Input quiz1, quiz2, quiz3
1. Input marks for quiz1, quiz2,
TotalMark = quiz1+quiz2+quiz3
and quiz3
2. Calculate total mark :
TotalMark = quiz1+quiz2+quiz3
3. Print TotalMark
print TotalMark 28
End
Step 3: Program Design
Methods to design a program:
Basic flowchart symbol
29
Step 3: Program Design
Methods to design a program:
Basic flowchart symbol
Symbol Explanation
Flow Lines •Indicate the direction of data flow.
•Used to connect a block to another
block.
•Indicates operations / process involved.
Process •Receive / read value
Input / Output •Display value
30
Step 3: Program Design
Methods to design a program:
Basic flowchart symbol
Symbol Explanation
Decision •Execute decision based on
condition.
Start / End Flow •Test is performed and the program
Lines flow continues, based on the result
On-page •Indicates the beginning and end of
connector Flow a flowchart.
Lines •Show the continuing flowchart in
the same page. 31
Step 3: Program Design
Methods to design a program:
Flowchart symbol usage
START
Input
True
Condition True Statement
False Output
False statement END
32
Step 3: Program Design
Example Flowchart
Flowchart to calculate the total of fine for late returning of library books.
RM0.20 perday
START
Input
total_of_day
Fine = total_of_day * 0.20
Output Fine
END
33
ACTIVITY 2:DISCUSSION 34
(20 MINUTES)
1. Create 8 group (7 people/group)-
2 minutes
2. Get a topic, marker pen, paper
3. Discuss in group
4. Draw the flowchart in paper
given
5. Choose BEST GROUP as
WINNER
(faster, correct , creative and
tidiness)
Step 3: Program Design
METHODS TO DESIGN A PROGRAM:
3. Pseudocode
⚫ Steps in problem solving that is written half in programming
code and half in human language.
Advantages:
Easily understood.
Easily maintained.
The codes are changeable.
Disadvantages:
Cannot be executed in the computer.
35
EXAMPLE OF PSEUDOCODE
START
Input quiz1, quiz2, quiz3
TotalMark= quiz1+quiz2+quiz3
Print TotalMark
END
36
ACTIVITY 2:DISCUSSION 37
(20 MINUTES)
1. Create 8 group (7 people/group)-
2 minutes
2. Get a topic, marker pen, paper
3. Discuss in group
4. Draw the pseudocode in paper
given
5. Choose BEST GROUP as
WINNER
(faster, corret , creative and
tidiness)
Step 3: Program Design
METHODS TO DESIGN A PROGRAM:
4. Structure Charts
⚫ An additional method in preparing programs that has many
sub modules.
⚫ It consists rectangular boxes, which represents all the sub
modules in a program and is connected by arrows.
⚫ It illustrates the top-down design of a program and is also
known as hierarchical chart because its components are in
hierarchical form.
⚫ The advantage is that it is easy to be drawn and to be changed.
38
Step 3: Program Design
METHODS TO DESIGN A PROGRAM:
⚫ Structure Chart:
The problem is normally big and complex.
Thus, requires big program.
Thus, the processing can be divided into subtasks called
modules.
Each module accomplishes one function.
These modules are connected to each other to show the
interaction of processing between the modules.
39
Step 3: Program Design
Methods to design a program:
Structure chart
40
Step 3: Program Design
Example Structure Chart
Problem
Write a Structure Charts to find an area of a
circle where area = pi * radius * radius
Area
radius area = 3.14 x Display area
radius x radius
41
Step 3: Program Design
Example Structure Chart
Problem: To calculate the amount of water bill
Water bill
Display Get / Compute Determine Display Print
instructions read the charge the late the bill the bill
data charge
for user
Represent the modules in the program 42
STEPS 4: PROGRAM CODING
Definition: Writing problem solving into certain
programming language such as C, COBOL , C++
and others.
Problem solving: Instructions before it is coded into
programming language.
Purpose: To produce a program to develop a system
The process of implementing an algorithm by
writing a computer program using a programming
language (for example, using C or C++ language)
The output of the program must be the solution of
the intended problem. 43
STEP 5: TESTING AND VERIFY
Testing :
⚫ Using a set of data to discover errors and to ensure accuracy
of the program.
⚫ Process of testing: is the process of executing a program to
demonstrate its correctness
⚫ Program verification is the process of ensuring that a
program meets user-requirement
44
Step 5: Testing And
Debugging
TWO TYPES OF ERROR:
1. Syntax Error (grammatical error)
⚫ Occurs when the rules of programming language are not
applied.
⚫ Correction is done during the program coding.
⚫ The bug can be traced during the compilation.
⚫ Also known as compile-time error
⚫ Must be corrected before executing and testing the
program.
45
Step 5: Testing And
Debugging
TWO TYPES OF ERROR:
2. Logic error
⚫ Cannot be traced by compiler.
⚫ Corrected during the problem solving process.
⚫ Also known as run time error.
⚫ Example : output for average is 4, but when it runs, the
output is 2.
46
STEP 6: MAINTAIN AND UPDATE
Definition:
Activity that verifies whether the operational system is
performing as planned or an activity to modify the
system to meet the current requirement.
The process of changing a system after it has been
applied to maintain its ability. The changes may involve
simple changes such as error correcting.
Process of changing a system after it has been delivered
and is in use.
Adaptive Maintenance - modifications to properly
interface with changing environments -> new
hardware, OS, devices
Perfective Maintenance - implementing new system
requirements after system is successful 47
Step 6: Maintenance
HOW TO DO MAINTENANCE?
✔ Testing – Test the ability of the system.
✔ Measurement – Access data time. Example, time
to save, print and others.
✔ Replacement – Replace the old system to new
system.
✔ Adjustment – Adding needs to new system.
✔ Repair – For example: An old system cannot
update the new data
✔ Updating – Update the database.
48
STEP 7: DOCUMENTATION
Definition: A written or graphical report of the
steps taken during the development of a
program.
Purpose: It will be useful in the future, in case
of modification or maintenance.
49
Step 7: Documentation
CONTENT OF DOCUMENTATION:
✔ Description of the program.
✔ Specification of program requirement
✔ Program design such as pseudocode and
flowchart
✔ List of program and comments (to explain about
the program).
✔ Test results. 50
✔ User’s manual book.
✔ Program capabilities and limitation.