Professional Documents
Culture Documents
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.
5 steps? 3
Definition of the Problem
What is the Problem Statement?
E.g. Accept two numbers (values). Calculate and display the sum of the two numbers.
4
Analyze the Problem
What is the Problem Statement?
components.
ADD A FOOTER 6
Propose and Evaluate Possible Solutions
An algorithm is a sequence of finite instructions which; if followed, produces a solution to the given problem 8
Test And Validate The Algorithm
We trace through the program using actual values into the system. Kinda like substitution. 9
Implement Algorithm
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
BEGIN
Read a, b
sum 🡨 a + b
END
14
Developing the Algorithm
Flowchart
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
• 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.
• 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.
• 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:
• 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
• BEGIN
• PRINT “Enter two numbers please”
• READ A
• READ B
• END
• 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
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