MTS 3013 Structured Programming
MTS 3013 Structured Programming
STRUCTURED
PROGRAMMING
INTRODUCTION
Never tire of learning new things. Stretch your
mind. Broaden your experience.
Introduction
A computer is an electronic device capable of
performing commands given by human.
Program – Are sequences of instructions and
decisions that the computer carries out to
achieve a task
Programmer – person responsible in writing a
program
Learning Programming – learning to solve
problem using computer
Problem Solving Using
Computer
Computer Problem Solving – involve
programming – involve 6 phases
Define the problem (understand problems need)
Problem Analysis
Design the Problem Solving
Implementation
Test and Verify involve programming
Documentation language
Problem Solving Using
Computer
Define the problem – read - understand
Problem Analysis – identify 3 main things
- input (data)
- process (use formula)
- output (answer)
Design the problem – use algorithm –
Flowchart or Pseudo-code
Problems Analysis
Identify problems:
Input
Process
Output
1. Walk
2. Walk
algorithm
3. Turn
4. Sit 2 steps
A set of step-by-step
instructions that
accomplish a task
Example Algorithm
Example : Didi is facing a chair that is 50
steps away from him. Write the algorithm that
directs Didi to sit on the chair.
Extra command : repeat x times
Solution:
1. repeat 50 times:
Write “walk” instruction 50 times
walk
Use the “repeat 50 times.”
2. turn
3. sit
Pseudo code
Pseudo code
Is an artificial and informal language
Usually it is use English language
Quite similar to programming language
The purpose of pseudo code is to make
humans who do not understand computer
programming can easily understand the flow
of the problem solving.
Pseudo code
START
SET sum = 0, average = 0
INPUT nom1, nom2, nom3
sum = nom1 + nom2 + nom3
average = sum / 3
PRINT nom1, nom2, nom3
PRINT average
END
Flow Chart
Flow Chart
It is represents by using geometry shapes with
connected line
Use a standard symbol
Flow Chart
TERMINAL
Indicates the beginning or end of an algorithm
PROCESS
Indicates an input computational or data
manipulation.
INPUT / OUTPUT
Indicates an input or output operation
Flow Chart
DECISION
Indicates a decision point in the algorithm
CONNECTOR
Indicates an entry to or exit from another
part of the flowchart
LOOP
Indicates the initial, final and increment
values of a loop
FLOW LINES
Used to connect the flowchart symbols and
indicate the logic flow
Example of a flow chart
START
sum = 0, average = 0
average = sum / 3
END
Exercise
Write a pseudo-code and a flow chart to
calculate and display a volume of a sphere.
pi = 3.41
Input radius
Print volume
END
Control Structures Flow Chart
There are three type of control structures in
programming
Sequence structure
Selection structure
If
If… else
Repetition structure
For
While
Do… while
Flow Chart for Selection
Structure 1
Pseudo code
if condition True
Condition / Boolean Statement 1 (inside if
statement 1 operator structure)
False
false true
Condition / Boolean Statement 1
Statement 2 operator
Pseudo code
if condition Example Pseudo code
statement 2 Else
Print “Failed”
Flow Chart for Repetition
Structure
True
Condition / Boolean Statement 1 (inside if
operator structure)
False