Week 1.2
Week 1.2
2
PROBLEM SOLVING
Class discussion:
Write down the steps to take from waking up in the
morning until you get to class.
3
PROBLEM SOLVING
5
UNDERSTANDING THE PROBLEM
Example 3
The sum of two numbers must be calculated, but the problem statement doesn’t supply the
values. The algorithm can ask the user to supply the values of the numbers before
calculating the sum.
The most important aspect of solving a problem using a computer is writing the algorithm,
or steps, to solve it.
An algorithm must be written in such a way that is it unambiguous and precise. The
computer cannot think for itself – you need to tell the computer exactly what to do. You
should never assume that the computer will do something that you haven’t explicitly
specified in a step.
Another essential aspect of understanding a problem statement is understanding the
individual words in the statement.
6
DATA PROCESSING
7
DATA PROCESSING
8
DATA PROCESSING
Calculate the sum of two numbers where the problem statement does not
supply the values
Example 3:
Input: Not available in the problem statement. The user has to supply the numbers.
Processing: Add the two numbers to determine the sum.
Output: The sum as calculated in the processing phase and displayed on the computer
screen.
Note the following:
The value of the numbers must be available before the sum can be calculated.
It is impossible to display the sum before it has been calculated.
From this, it is clear that the steps in an algorithm must always be written in logical order.
9
THE PROBLEM-SOLVING APPROACH SUMMARY
10
PROBLEM SOLVING APPROACH
Example:
Peter sells oranges, pears, guavas and apples. Last week he sold 50 apples, 100
pears, 80 oranges and some guavas. This week he sold twice as many items. How
many did he sell?
To solve the problem:
Ask the question to obtain the number of guavas sold last week.
Get the number of guavas.
Calculate the total number by adding the four numbers to determine the total number
sold last week.
Multiply last week’s total by 2 to obtain this week’s total.
12
PSEUDO-CODE
13
PSEUDO-CODE
• Pseudocode is much
easier to follow than the
program in a
programming language,
such as the Visual Basic
program
14
WHAT DOES PSEUDO-CODE ENTAIL
also used.
WHAT DOES PSEUDO-CODE ENTAIL
A computer can assign a value to a
variable.
Three different cases are identified:
A computer can compare two pieces of
To give variables an initial value information and select one of two
Initialise, set alternative actions.
To assign a value as a result of if condition then
processing some action
? = ? else
x = 5 + y alternative action
To keep information for later use endif
16
Save, store
WHAT DOES PSEUDO-CODE ENTAIL
A computer can repeat a group of
actions
while condition (is true)
some action
loop
18
FLOWCHARTS
19
FLOWCHART SYMBOLS
20
ALGORITHM VS FLOWCHART
21
EXERCISE
22