0% found this document useful (0 votes)
9 views

02 Introduction To Problem Solving

java

Uploaded by

a77md2
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

02 Introduction To Problem Solving

java

Uploaded by

a77md2
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Introduction to Problem

Solving
Reference:
Problem Solving and Programming Concepts 9th
Edition
by Maureen Sprankle and Jim Hubbard

1
Outlines

• General Problem Solving

• Six Steps of Problem Solving

• Structure of Programs

• Beginning Computer Concepts for Problem Solving

• Problem Solving Organization Tools

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.

• Clearly define the goal that you want to achieve.


Output
• What are you trying to achieve?

• Determine what are the inputs and outputs

• 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.

• List the features for each possible solution

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?

• Does the solution solve the original problem?

• Does it satisfy the needs of the user?

• Is it acceptable to the user?

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.

• The Decision Structure.


• Ex: Decide if student pass or fail.

• The Loop Structure.


• Ex: Repeat displaying a warning message 10 times.

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

• Can be of any data type: numeric, alphabetical or special symbols

• 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

• Computer should know the data type of each variable or constant .

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.

• The tools include the:


• Pseudocode Algorithm

• Flowchart

20
Algorithm

• The next step of organizing a solution is to develop sets of


instructions for the computer, called algorithms.
Input list
Algorithm

A step-by-step method for solving a problem or doing a task

Output list

21
Writing the Algorithm

• The next step of organizing a solution is


to develop sets of instructions for the
computer, called algorithms.

22
Writing the Algorithm

• The programmer writes a separate set of instructions for each


program or (module).

• The number of instruction is determined by the way the


programmer chooses to solve the problem.

23
Drawing the Flowchart

• Flowchart is a graphic representations of the algorithms.

• The algorithms and flowcharts are the final steps in organizing a

solution.

• A flowcharts shows the flow of the processing from the beginning to

the end of a solution.


24
Drawing the Flowchart

• Each block in a flowchart represents one instruction from an

algorithm.

• Flowlines indicate the direction of the data flow.

• Most block have one or more entrances and have only one exit .

25
Flowchart Symbol

Flowchart Symbol Explanation

• Flowlines are indicated by straight lines with arrows to show the


Flowline
direction of data flow.

• Flowlines are used to connect blocks by exiting from one and

entering another.

26
Flowchart Symbol
Flowchart Symbol Explanation

Start
• Flattened ellipses indicate the start and the end of a module. An

ellipse uses the name of the program (module) at the start.


End
• The end is indicated by the word end or stop.

• A start has no flowlines entering it and only one exiting it; an end

has one flowline entering it but none exiting it.

27
Flowchart Symbol
Flowchart Symbol Explanation

• The rectangle indicates a processing block, for such things as

calculations,
Processing
• opening and closing files, and so forth. A processing block has

one entrance and one exit.

28
Flowchart Symbol
Flowchart Symbol Explanation

• The parallelogram indicates input to and output from the

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

• The diamond indicates a decision. It has one entrance and two

False True and only two exits from the block.


condition
• One exit is the action when the resultant is True, and the other
Decision
exit is the action when the resultant is False.

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

Gross Pay = Hours * Pay Step 5


Rate
Problem

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

Read Hours and


Gross Pay Calculation Pay Rate
1. Enter Hours Worked
2. Enter Pay Rate Gross Pay = Hours * Pay Rate

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

Step 1&2 Step 3&4


Input
Distance

Time=Distance??/Speed
Problem

Output
Time 34
Solution
Step 5

Travelling Time Calculation

1. Enter travelling distance

2. Calculate required time for first half distance

3. Calculate required time for second half distance

4. Total time=Time 1+Time 2

5. Print Total Time

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

Print Total Time

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.

Give student 5 min to solve

37
Solution
Step 5

Test Score Calculation

1. Enter the five test grades

2. Calculate total grades

3. Calculate average of grades

4. Print average

5. End

38
Solution
Step 5

Start

Read grade 1, grade2,


grade 3, grade 4, grade 5

Total= grade1 + grade2+


grade3+ grade4+ grade5

Average=total/5

Print Average

End 39

You might also like