07 PRG1X1- Algorithms
07 PRG1X1- Algorithms
Objectives
Defining Algorithms
Pseudocode
Flowchart
IPO Diagram
Problem Solving Tools in Programming
– Programmers must :
Unstructured
Structured
Modular
Top-Down
Bottom-Up
Object-oriented Programming
Unstructured Programming
repetitive
PRINT “Belgium Campus”
PRINT “Belgium Campus”
– It is harder to do changes in the program.
PRINT “Belgium Campus”
PRINT “Belgium Campus”
– This paradigm was used in earlier versions END
of BASIC, COBOL, and FORTRAN
Structured Programming
– Converts large or complex programs into more manageable and small pieces
of code.
– The code is divided into functions or modules.
Structured Programming
– We sub-divide the whole program into small modules so that the program
becomes easy to understand.
o Sequence
o Repetition, and
o selection
Bottom-Up Approach
– Is the opposite of Top-Down Approach.
– The parts are linked to form larger components, which are in turn linked
until a complete system is formed.
1) Pseudocode
2) Flowcharts
BEGIN
Order Pizza
If Cold drinks available, Then
Order Cold drinks
Otherwise
Order Cold coffee
End If
Pay the bill
END
Example Algorithm
Flowchart
Example Algorithm
IPO
• BEGIN
• END
• IF…ELSE…THEN
• PRINT or DISPLAY
• SET
• WHILE, DO…WHILE, FOR…TO
• INPUT, OUTPUT
Pseudocode
Example 1: Add Two Numbers
Declaring variables
BEGIN
price = INPUT
– it does not matter if there are errors in the syntax - it is usually still obvious
what is intended.
– Different graphical figures or shapes are used to represent each step in the
flowchart.
Flowcharts Symbols
Flowcharts Symbols Examples
Flowcharts
• Describes a simple way of how your program processes input and turns
it into output.
• Usually, you develop an IPO chart to represent all the input, processes
and outputs of a program, before creating an pseudocode.
• Making an IPO chart helps you understand what you can expect to get
out of the data you gather and process.
IPO
Create an IPO chart of a program that takes 2 numbers from the user,
calculates the sum, average and product, and prints the outputs.
Exercise
Go on Teams