02 Introduction To Problem Solving
02 Introduction To Problem Solving
Solving
Reference:
Problem Solving and Programming Concepts 9th
Edition
by Maureen Sprankle and Jim Hubbard
1
Outlines
• Structure of Programs
2
General Problem Solving
• People make decisions every day to solve problems that affect their
lives
• Important problems
• Unimportant problem
• Bad/Good decision
3
Six Steps of Problem Solving
• There are six steps to follow to ensure the best decision.
• Most people use them without even knowing it:
1. Identify the problem.
2. Understand the problem.
3. Identify alternative ways to solve the problem.
4. Select the best way to solve the problem from the list of alternative
solutions.
5. List instructions that enable you to solve the problem using the selected
solution.
6. Evaluate the solution.
4
Six Steps of Problem Solving
1. Identify the problem
• The first step toward solving a problem is to identify the problem
Input
• What is the specific problem?
Problem
• This means you should determine what is that you want to change.
• If you don’t know what the problem is, you cannot solve it.
5
Six Steps of Problem Solving
2. Understand the problem
• You must understand what is involved in the problem before you can continue
toward the solution.
• This includes understanding the knowledge base of the person or machine for
whom you are solving the problem.
• Also, you must know your own knowledge base., You cannot solve a problem if
you do not know the subject. For example, to solve a problem involving
accounting, you must know accounting.
6
Six Steps of Problem Solving
3. Identify alternative ways to solve the problem
• Generate as many potential solutions as possible.
7
Six Steps of Problem Solving
4. Select the best way to solve the problem from the list of
alternative solutions
• In this step, you need to identify and evaluate the pros and cons of each
possible solution before selecting the best one
• In order to do this, you need to select criteria for the evaluation
8
Six Steps of Problem Solving
5. List instructions that enable you to solve the problem using the
selected solution
• Create a numbered, step-by-step instructions that must fall within the knowledge base
set up in step 2
9
Six Steps of Problem Solving
6. Evaluate the solution
• To evaluate or test a solution means to check its result to see if it is correct,
and to see if it satisfies the needs of the person(s) with the problem.
• Test the solution
• Are the results accurate?
10
Problem Solving Example
11
Structure of Programs
• Use modules to break the whole problem into parts, with each part
having a particular function.
• Use the three logic structures to ensure that the solution flows
smoothly from one instruction to the next, rather jumping from one
point in the solution to another.
12
Beginning Computer Concepts for
Problem Solving
• There are 3 types of problem that can be solved in computer:
• Computational problems
• involving some kind of mathematical processing
• Logical Problems
• involving relational or logical processing
• Repetitive Problems
• involving repeating a set of mathematical and/or logical instructions.
13
Structure of Programs
• Program Structures:
• The sequential Structure.
• Ex: Simple calculation.
14
Beginning Computer Concepts for
Problem Solving
• Basic building programming blocks:
• Equations
• Consist of constant, variables and operators.
• Expressions
• Decisions and repeat control statements.
• Functions
15
Beginning Computer Concepts for
Problem Solving
• Constants:
• Does not change during the processing of all the instructions in a solution
• Examples
• 3, 5, 10, “Sara”, “+”, “-”, “/”
16
Beginning Computer Concepts for
Problem Solving
• Variables:
• May change during processing
• In many programming languages, variables are called identifiers.
• A name is assigned to each variable used in a solution and should be
consistent with what the value of the variable represents.
• The computer uses the variable name to find the location; it uses the value
found at the memory location to do the processing.
• Ex:
• Name=“Java”
• Test_Score=95
17
Beginning Computer Concepts for
Problem Solving
• Data Types:
• Data can come with different type:
• Numeric
• Character
• Logical
18
Beginning Computer Concepts for
Problem Solving
19
Solution Organization Tools
• Certain organizational tools will help you learn to how solve problems
on the computer.
• Flowchart
20
Algorithm
Output list
21
Writing the Algorithm
22
Writing the Algorithm
23
Drawing the Flowchart
solution.
algorithm.
• Most block have one or more entrances and have only one exit .
25
Flowchart Symbol
entering another.
26
Flowchart Symbol
Flowchart Symbol Explanation
Start
• Flattened ellipses indicate the start and the end of a module. An
• A start has no flowlines entering it and only one exiting it; an end
27
Flowchart Symbol
Flowchart Symbol Explanation
calculations,
Processing
• opening and closing files, and so forth. A processing block has
28
Flowchart Symbol
Flowchart Symbol Explanation
computer memory.
Input/Output (I/O)
• An input/output (I/O) block has one entrance and only one exit.
29
Flowchart Symbol
Flowchart Symbol Explanation
30
Example: Payroll System
• Problem: Calculate the gross pay of an employee given the hours
worked and the rate of pay. The gross pay is calculated by multiplying
the hours worked by the rate of pay.
Step 1&2 Step 3&4
Input
Hours & Pay rate
Output
Gross Pay
31
Example: Payroll System
• Problem: Calculate the gross pay of an employee given the hours
worked and the rate of pay. The gross pay is calculated by multiplying
the hours worked by the rate of pay.
Step 5 Start
3. Calculate Pay
4. Print Pay Print Gross Pay
5. End
End 32
Develop a flowchart
• Sarah is traveling from city A to city B. The distance between the two
cities is a variable because she would like to use the equation to use
for other cities. She knows that 50% of the distance she will be
traveling 50 kilometre an hour and the remaining 50% she will be
traveling 100 kilometre per hour. Write an equation that will calculate
the time it will take to travel from one city to the next.
33
Solution
50 k/h 100 k/h
City A City B
Time=Distance??/Speed
Problem
Output
Time 34
Solution
Step 5
6. End
35
Solution
Step 5
Start
Read distance
Time 1= 0.5*distance/50
Time 2= 0.5*distance/100
Total time=Time1+Time2
End 36
Develop a flowchart & algorithm
• Ahmad would like to know the average of his test scores. Write an
equation that would calculate the average given five test scores.
37
Solution
Step 5
4. Print average
5. End
38
Solution
Step 5
Start
Average=total/5
Print Average
End 39