You are on page 1of 30

Problem Solving

Technology
Department

2021
What is a Problem?

A problem can be
defined as a difference
between the actual
situation and the
desired situation.
The discrepancy
between the way
things are and the way
we want them to be.

Are you the problem? 2


Steps to Problem Solving
Steps to Problem Solving

• Problem Definition & Problem Analysis


• Propose and Evaluate Possible Solutions
• Determine the most effective solution
• Develop the Most Appropriate Algorithm
• Test and Validate the Algorithm
• Implement the Algorithm (Write the Program)
• Test and Debug the Program
• Document and Maintain the Program

5 steps? 3
Definition of the Problem
What is the Problem Statement?

Defining the problem the user wants to solve and


deciding what the user wants to achieve and writing it
down.
State what are the features wrong with the existing
system. Then list what the system needs.

E.g. Accept two numbers (values). Calculate and display the sum of the two numbers.
4
Analyze the Problem
What is the Problem Statement?

This step helps you to take a complexed problem and

break it into smaller or easily manageable

components.

Bottom Up and Top Down Approach 5


IPO Chart
Input – Process – Output – Store

Input – Process Output - Storage


Identify the inputs to be used or required (INPUT) Identify required outputs (OUTPUT)

Identify values to be stored if any (STORAGE)


Identify the processing required to achieve correct
output (PROCESSING)

ADD A FOOTER 6
Propose and Evaluate Possible Solutions

This step involves examining all the possible


solutions to the problem and then select the
best one, given the resources available (e.g.
time)

From all the possible solutions we chose 1.

Which solution will we choose? 7


Develop an Algorithm
An algorithm is a finite number of accurate, unambiguous steps that solve a problem

There are many different methods used for writing algorithms.


Examples of algorithms are: narrative, flowcharts, pseudocode, design structures, top down design approach,
bottom up design approach, etc.

An algorithm is a sequence of finite instructions which; if followed, produces a solution to the given problem 8
Test And Validate The Algorithm

This step involves a desk check with test data


to see if the algorithm performs as expected.

One good way of testing an algorithm is to use trace table.

A trace table is a table that tests an algorithm for logical

errors by calculating each of the variables in your

algorithm one statement at a time.

We trace through the program using actual values into the system. Kinda like substitution. 9
Implement Algorithm

This step is where we write actual CODE.

For this course we will be using PASCAL code.

Did you know Blaise Pascal is a founding father of Computing


https://history.computer.org/pioneers/pascal.html 10
Test and Debug Program

After the program is written, we must use


actual data again in the program to see if it
actually works.
If it doesn’t do what we intended, we must
debug!

For this course we will be using PASCAL code.

Did you know Blaise Pascal is a founding father of Computing


https://history.computer.org/pioneers/pascal.html 11
Document and Maintain

Documentation is an important aspect of


programing. In this section we create user
manuals and training manuals to let the user of
the system know HOW to use the system.

Maintenance is also provided as a way of ongoing support

for the software that is developed. If the company grows

or changes the system also should grow/change with it.

Did you know Blaise Pascal is a founding father of Computing


https://history.computer.org/pioneers/pascal.html 12
Developing the Algorithm
The Narrative

The Narrative Algorithm is the step by step instructions


in regular English that will explain what the program will
do.
This is in the solution design phase.

EG
• The program will show a menu and the user has the
option 1 to 5 to select.
• If option 1 is selected the user will be taken to the
Information entering screen where they will be required
to enter their name, telephone number and grade.
• Once the user completes the form the information is
13
stored in the User Info File.
Developing the Algorithm
Pseudocode

Pseudocode algorithm uses words and symbols that


closely resemble computer programming language
instructions

Example Problem Statement: Accept two numbers


(values) into variables a and b. Add the two values.

BEGIN

Read a, b
sum 🡨 a + b
END
14
Developing the Algorithm
Flowchart

A Flowchart is a visual/pictorial representation of the


algorithm and how each step flows into the other.

BEGIN

Read a, b
sum 🡨 a + b
END
15
Characteristics of a Good Algorithm

The
number of
steps must Steps must be Must
be finite unambiguous terminate

Must be Must
precise have Must
flow lead
control to an
output

16
Pseudocode
Algorithm
Lets start writing
pseudocode!

17
Steps for Developing an Algorithm

Creating an IPO Chart is important in breaking down the different


parts of the problem that we want to program. 18
The Pseudocode

• A pseudocode is an imitation computer program written using mathematical notations and English-like
statements to describe the logics to solve a problem or carry out a procedure.
• Pseudocode is made up of several statements:
• Output Statements
• Input Statements
• Assignment statements
• Control statements
• When writing pseudocodes we use two key words BEGIN and END to state that we are starting our process and
stopping the process.

We could also use START and STOP. 19


Output Statements

• The output statement is a statement used to get information from the program to the user. The key words used
for output statements are PRINT, OUTPUT, DISPLAY or WRITE; however we will be using PRINT.
• The information that we print to the screen must be placed between quotation marks “ “. Whatever is
between the quotation marks will be seen on screen in its exact format.
• Print statements are used to either request information from the user
(prompt) or to give results of certain processes in the pseudocode
to the user.

• BEGIN
• PRINT “you are the best”
• END The co
you are the best
d
it prod e to what
uces.

All Key Words are written in ALL CAPS. 20


Exercise

• 1. Write a pseudocode algorithm to print to the screen “Hello. My name is (your name)”

 
• 2. Write a pseudocode algorithm to prompt the user to enter two numbers

 
• 3. Write a pseudocode algorithm to print to the screen “If you’re happy and you know it say amen”

21
The only way you learn is if you try! Strive for PROGRESS not
PERFECTION!
Input Statements

• The input statement is used to get data from outside the computer via some input device into a variable for
manipulation by the pseudocode. The two key words used for input statements are READ and INPUT, however
we will be using READ.
• When we accept data from the user, that data needs to be stored somewhere before we can do anything with it.
• That data is stored in a LOCATION IN MEMORY. That location in memory will have a name for ease of
reference. That name is called the variable name.
• Variable: In math a variable is a symbol, word or letter used to represent an unknown value. When we write
programs we don’t know the value of which the user will enter into the program. But instead of naming our
variables x and y as we do in Math, we need to give out program variables more meaningful names. These
variable names are called IDENTIFIERS.

ADD A FOOTER 22
Rules for writing variable names:

• Variable names must be one word.


• Variable names should not begin with a number
• Variable names should reflect what is being stored in them
• Names should not be more than 64 characters.
• Variable names should not be a reserved word

• Constant: This provides locations for storing data which do not change value during execution of a program.
• Identifier: This is the name invented by a programmer for a data item. An identifier can be the name of a
variable or a constant. E.g. Num or Pi.
• The value of a variable can be changed by an input statement or an assignment statement (This will be
looked at later).

ADD A FOOTER 23
Example

• Write a pseudocode algorithm to read two numbers into variable A and B.

• BEGIN
• PRINT “Enter two numbers please”
• READ A
• READ B
• END

A B Enter two numbers


please

All Key Words are written in ALL CAPS. 24


Example

• Write a pseudocode algorithm to read two numbers into variable A and B and print back the numbers to the user.
• BEGIN
• PRINT “Please enter two numbers”
• READ A
• READ B
• PRINT “The first number you’ve entered is”, A
• PRINT “The second number you’ve entered is”, B
• END
A B Enter two numbers
please

All Key Words are written in ALL CAPS.


The first number you’ve 25
entered is
Exercise

• Write a pseudocode algorithm to input the colour and price of a car.

• Write a pseudocode algorithm to enter three values into variable A, B and C.

• Write a pseudocode algorithm to read the name and sex of a student.


 

26
Assignment Statement

• Assignment statements are used to give initial value to variables and to change the value assigned to a variable.
• The assignment statement has two parts, the Lvalue and the Rvalue. The Lvalue refers to the variable as the
storage location where the Rvalue will be stored.
• fname🡨”Peter”
• rate🡨50
• hours🡨100
• salary🡨 rate*hours
• When using assignment statements we assign literals, values or formulas.

ADD A FOOTER 27
Exercise

• Write a pseudocode algorithm to accept three numbers and find and print their sum.
• Start by creating the IPO Chart.

28
Data Types

ADD A FOOTER 29
Trace table example

• Look at this code SNIPPET.


1. Score 🡨75
2. Sum 🡨 220
3. Value 🡨 Sum + Score
4. Sum 🡨Score
5. Score 🡨 Value + Sum
6. Value 🡨 Sum + Score
•  
• Answer the following questions using the lines of codes above.
• What is the value stored in value in line 3. _________
• What is the value stored in sum in line 4. __________
• What is the value stored in value in line 5. _________
• What is the value stored in score in line 5. _________
• What is the value stored in value in line 6. _________
30
• What is the value stored in sum in line 6. __________

You might also like