SlideShare a Scribd company logo
MTS 3013
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
Defining Control Structures
 All computer programs are written using one
or more of three basic structures:
 Sequence
 Repetition
 Selection
 These are called control structures or logic
structures because they control the flow of a
program’s logic.
The sequence structure
 You use it each time you follow a set of
directions, in order, from beginning to end.
 Example – a cookie recipe – you need to
follow each recipe instruction in order,
beginning with the first instruction and ending
the last
 Example – a robot named Didi. Didi can understand
only a specific number of instructions / commands :
walk, turn, sit
 Walk – takes one complete step forward
 Turn – turns 180 degree
 Sit – sits down
 Assume that Didi is facing a chair that is two steps
away from him.
 Write the instructions using only commands that Didi
understands, that direct Didi to sit in the chair.
1. Walk
2. Walk
3. Turn
4. Sit 2 steps
algorithm
A set of step-by-step
instructions that
accomplish a task
The repetition structure
 Example – shampoo bottles typically include
repetition structure in the directions for
washing your hair. Those direction usually tell
you to repeat the “apply shampoo to hair”,
“lather”, and “rinse” steps until your hair is
clean.
 Repetition structure referred to as loop,
directs the computer to repeat one or more
instructions until some condition is met, at
which time the computer should stop
repeating the instructions.
 Example : Didi is facing a chair that is 50
steps away from him. Write the algorithm that
directs Didi to sit in the chair.
 Extra command : repeat x times
 Solution:
 Write “walk” instruction 50 times
 Use the “repeat 50 times.”
1. repeat 50 times:
walk
2. turn
3. sit
The selection structure
 Also called decision structure
 Makes a decision, and then takes appropriate
action based on that decision
 Example: you drive your car and approach an
intersection, whether you need to stop or
proceed.
Example
 Example: Didi is holding either a red or yellow
balloon and that he is facing two boxes. One of the
box is colored yellow and the other is colored red.
The two boxes are located 20 steps away from Didi.
Your task is have Didi to drop the balloon into the
appropriate box. The yellow balloon belongs to the
yellow box and the red balloon belongs to the red
box. After Didi drops the balloon you should return
him to the original position.
 You may add additional instructions to Didi’s
instruction set
The algorithm
1. repeat 20 times:
walk
2. if the balloon is red, do this:
drop the balloon in the red box
otherwise
drop the balloon in the yellow box
3. turn
4. repeat 20 times
walk
5. turn
 Calculate the bonus by multiplying the salary 1%
 Calculate the bonus by multiplying the salary 2%
 If the years employed are greater than or equal to 5,
do this:
 If the years employed are less than 5, do this:
 Otherwise, do this:
 Print the bonus
 Read the salary and years employed
 Repeat for each employee:
Exercise
 Assume a company pays an annual bonus to
its employees. The bonus is based on the
number of years the employee has been with
the company. Employees working at the
company for less than 5 years receive a 1%
bonus, all others receive a 2% bonus. Write
an algorithm that prints each employee’s
bonus. Use only the instructions given:
Answer??
Problem Solving
 Problem solving involves:
 Analysis
 Algorithm or pseudo code or flow chart or
combination of them.
Problems Analysis
 Identify problems:
 Input
 Output
 Process
INPUT PROCESS OUTPUT
Problem
 Write a program obtain average of 3 numbers
given by a user. Display the 3 numbers and
the average of the numbers.
Problems Analysis
 Input : 3 numbers
 Process : 1. Add 3 numbers
2. Divide sum of the numbers by 3
 Output : Print 3 numbers & average
Algorithm
 Algorithm
 Any computing problem can be done by executing
a series of actions in a specific order.
 A procedure for solving a problem in terms of the
actions to be executed and the order in which
these actions are to be executed is called an
algorithm.
 Is a logical solution that is inline with our daily
language or mother tongue language.
Algorithm
Start
1. Set sum = 0 and average = 0
2. Read 3 numbers: nom1, nom2, nom3
3. Add 3 numbers
4. Calculate the average, average = (sum)/3
5. Print 3 numbers(nom1, nom2, nom3) and
the average
End
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
FLOW LINES
Used to connect the flowchart symbols and
indicate the logic flow
LOOP
Indicates the initial, final and increment
values of a loop
Example of a flow chart
START
END
sum = 0, average = 0
Input nom1,nom2, nom3
sum = nom1 + nom2 + nom3
average = sum / 3
print nom1,nom2, nom3
print average
Exercise
 Write an algorithm and a flow chart to
calculate and display a volume of a sphere.
Volume = 4/3 x pi x radius x radius , where pi = 3.41
Solution
 Analyze the problem
 Input :
 Process :
 Output :
radius
Calculate volume of a sphere
Volume = 4/3 x pi x radius x radius
print volume of a sphere
Solution (algorithm)
Start
1. Input radius
2. Calculate volume of a sphere
Volume = 4/3 x pi x radius x radius
3. print volume of a sphere
End
Solution (Flow Chart)
START
END
pi = 3.41
Input radius
Volume = 4/3 x pi x radius x radius
Print volume
Control Structures Flow Chart
 3 types of control structures:
 Sequence structure
 Selection structure
 If
 If… else
 Repetition structure
 For
 While
 Do… while
Flow Chart for Selection
Structure 1
Pseudo code
if condition
statement 1
Condition / Boolean
operator
Statement 1 (inside if
structure)
True
False
Example Pseudo code
if student’s grade is greater than or equal to 60
Print “Passed”
Flow Chart for Selection
Structure 2
Condition / Boolean
operator
true
false
Statement 2 Statement 2
Pseudo code
if condition
statement 1
Else
statement 2
Example Pseudo code
if student’s grade is greater than or equal to 60
Print “Passed”
Else
Print “Failed”
Flow Chart for Repetition
Structure
Condition / Boolean
operator
Statement 1 (inside if
structure)
True
False
Example Pseudo code
While there are more items on the shopping list
Purchase next item and cross it off my list
Module Structure
 Used for a big and complex problem
 Divide the problem into smaller problem –
sub module
 To simplify a problem solving
Module structure Pseudo code
Main module
Call sub module
End of main module
Sub module name
Statements
End of sub module
Main module
Sub module
1
Sub module
2
TQ

More Related Content

PDF
Nota (first)
PPTX
Programming Fundamentals
PPTX
Algorithm and pseudo codes
PPT
Programing Fundamental
PDF
4 coding from algorithms
PPTX
Algorithms
PPT
Algorithms
PPTX
Programming process and flowchart
Nota (first)
Programming Fundamentals
Algorithm and pseudo codes
Programing Fundamental
4 coding from algorithms
Algorithms
Algorithms
Programming process and flowchart

What's hot (20)

PPTX
STRUCTURED PROGRAMMING Chap2
PPTX
Modular programming
PPTX
Programing techniques
PDF
Basic of qbasic
PDF
Algorithm and c language
PDF
problem solving and design By ZAK
PPTX
The Knowledge of QBasic
DOC
Unit 3
PPTX
Software develop....
PDF
Programming concepts By ZAK
PPTX
Algorithm - Introduction
PDF
POLITEKNIK MALAYSIA
PDF
POLITEKNIK MALAYSIA
PDF
Modular programming in qbasic
PPTX
Pseudocode-Flowchart
PPT
Lec 1 intro
PPT
Pseudocode algorithim flowchart
PPT
Jeremiah Yancy - Objectives for Software design and testing
PPTX
Raptor tool
PPTX
Programming flowcharts for C Language
STRUCTURED PROGRAMMING Chap2
Modular programming
Programing techniques
Basic of qbasic
Algorithm and c language
problem solving and design By ZAK
The Knowledge of QBasic
Unit 3
Software develop....
Programming concepts By ZAK
Algorithm - Introduction
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Modular programming in qbasic
Pseudocode-Flowchart
Lec 1 intro
Pseudocode algorithim flowchart
Jeremiah Yancy - Objectives for Software design and testing
Raptor tool
Programming flowcharts for C Language
Ad

Similar to Pengenalan kepada pengaturcaraan berstruktur (20)

PPT
3 algorithm-and-flowchart
PPT
Programming algorithms and flowchart.ppt
PDF
Problem solving (C++ Programming)
PPTX
UNIT 1.pptx
PPSX
Algorithm and flowchart
PPTX
Std 10 computer chapter 9 Problems and Problem Solving
PPT
PDF
ALGORITHM PPT GUIDE.pdf
PPTX
Algorithm for computational problematic sit
PDF
Algorithms and how to write an algorithms
PDF
What is an Algorithm and Flow Chart along with step wise problem solvingt
PDF
2021 CSE031.Lecture 6.Flow_Charts_Pseudocode.pptx.pdf
PPT
Penyelesaian masalah
PPT
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
PPTX
Psuedocode1, algorithm1, Flowchart1.pptx
PPT
Lect1 - Algorithms-and-Flowchart-ppt.ppt
PPT
Lect1-Algorithms-and-Flowchart-ppt (1).ppt
PPT
Lecture1-Algorithms-and-Flowchart-ppt.ppt
PPT
Lect1-Algorithms-and-Flowchart PPT presentation
PPT
Lecture1-Algorithms-and-Flowchart-ppt.ppt
3 algorithm-and-flowchart
Programming algorithms and flowchart.ppt
Problem solving (C++ Programming)
UNIT 1.pptx
Algorithm and flowchart
Std 10 computer chapter 9 Problems and Problem Solving
ALGORITHM PPT GUIDE.pdf
Algorithm for computational problematic sit
Algorithms and how to write an algorithms
What is an Algorithm and Flow Chart along with step wise problem solvingt
2021 CSE031.Lecture 6.Flow_Charts_Pseudocode.pptx.pdf
Penyelesaian masalah
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
Psuedocode1, algorithm1, Flowchart1.pptx
Lect1 - Algorithms-and-Flowchart-ppt.ppt
Lect1-Algorithms-and-Flowchart-ppt (1).ppt
Lecture1-Algorithms-and-Flowchart-ppt.ppt
Lect1-Algorithms-and-Flowchart PPT presentation
Lecture1-Algorithms-and-Flowchart-ppt.ppt
Ad

More from Unit Kediaman Luar Kampus (8)

Recently uploaded (20)

PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
PDF
SparkLabs Primer on Artificial Intelligence 2025
PPTX
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
PDF
creating-agentic-ai-solutions-leveraging-aws.pdf
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
PDF
Google’s NotebookLM Unveils Video Overviews
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
PPTX
How Much Does It Cost to Build a Train Ticket App like Trenitalia in Italy.pptx
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
PDF
Event Presentation Google Cloud Next Extended 2025
PPTX
CroxyProxy Instagram Access id login.pptx
PDF
Doc9.....................................
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
ChatGPT's Deck on The Enduring Legacy of Fax Machines
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
Revolutionize Operations with Intelligent IoT Monitoring and Control
SparkLabs Primer on Artificial Intelligence 2025
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
creating-agentic-ai-solutions-leveraging-aws.pdf
Transforming Manufacturing operations through Intelligent Integrations
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Google’s NotebookLM Unveils Video Overviews
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
How Much Does It Cost to Build a Train Ticket App like Trenitalia in Italy.pptx
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Chapter 2 Digital Image Fundamentals.pdf
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Event Presentation Google Cloud Next Extended 2025
CroxyProxy Instagram Access id login.pptx
Doc9.....................................
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
NewMind AI Weekly Chronicles - July'25 - Week IV

Pengenalan kepada pengaturcaraan berstruktur

  • 2. Never tire of learning new things. Stretch your mind. Broaden your experience.
  • 3. 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
  • 4. Defining Control Structures  All computer programs are written using one or more of three basic structures:  Sequence  Repetition  Selection  These are called control structures or logic structures because they control the flow of a program’s logic.
  • 5. The sequence structure  You use it each time you follow a set of directions, in order, from beginning to end.  Example – a cookie recipe – you need to follow each recipe instruction in order, beginning with the first instruction and ending the last
  • 6.  Example – a robot named Didi. Didi can understand only a specific number of instructions / commands : walk, turn, sit  Walk – takes one complete step forward  Turn – turns 180 degree  Sit – sits down  Assume that Didi is facing a chair that is two steps away from him.  Write the instructions using only commands that Didi understands, that direct Didi to sit in the chair.
  • 7. 1. Walk 2. Walk 3. Turn 4. Sit 2 steps algorithm A set of step-by-step instructions that accomplish a task
  • 8. The repetition structure  Example – shampoo bottles typically include repetition structure in the directions for washing your hair. Those direction usually tell you to repeat the “apply shampoo to hair”, “lather”, and “rinse” steps until your hair is clean.  Repetition structure referred to as loop, directs the computer to repeat one or more instructions until some condition is met, at which time the computer should stop repeating the instructions.
  • 9.  Example : Didi is facing a chair that is 50 steps away from him. Write the algorithm that directs Didi to sit in the chair.  Extra command : repeat x times  Solution:  Write “walk” instruction 50 times  Use the “repeat 50 times.” 1. repeat 50 times: walk 2. turn 3. sit
  • 10. The selection structure  Also called decision structure  Makes a decision, and then takes appropriate action based on that decision  Example: you drive your car and approach an intersection, whether you need to stop or proceed.
  • 11. Example  Example: Didi is holding either a red or yellow balloon and that he is facing two boxes. One of the box is colored yellow and the other is colored red. The two boxes are located 20 steps away from Didi. Your task is have Didi to drop the balloon into the appropriate box. The yellow balloon belongs to the yellow box and the red balloon belongs to the red box. After Didi drops the balloon you should return him to the original position.  You may add additional instructions to Didi’s instruction set
  • 12. The algorithm 1. repeat 20 times: walk 2. if the balloon is red, do this: drop the balloon in the red box otherwise drop the balloon in the yellow box 3. turn 4. repeat 20 times walk 5. turn
  • 13.  Calculate the bonus by multiplying the salary 1%  Calculate the bonus by multiplying the salary 2%  If the years employed are greater than or equal to 5, do this:  If the years employed are less than 5, do this:  Otherwise, do this:  Print the bonus  Read the salary and years employed  Repeat for each employee:
  • 14. Exercise  Assume a company pays an annual bonus to its employees. The bonus is based on the number of years the employee has been with the company. Employees working at the company for less than 5 years receive a 1% bonus, all others receive a 2% bonus. Write an algorithm that prints each employee’s bonus. Use only the instructions given:
  • 16. Problem Solving  Problem solving involves:  Analysis  Algorithm or pseudo code or flow chart or combination of them.
  • 17. Problems Analysis  Identify problems:  Input  Output  Process INPUT PROCESS OUTPUT
  • 18. Problem  Write a program obtain average of 3 numbers given by a user. Display the 3 numbers and the average of the numbers.
  • 19. Problems Analysis  Input : 3 numbers  Process : 1. Add 3 numbers 2. Divide sum of the numbers by 3  Output : Print 3 numbers & average
  • 20. Algorithm  Algorithm  Any computing problem can be done by executing a series of actions in a specific order.  A procedure for solving a problem in terms of the actions to be executed and the order in which these actions are to be executed is called an algorithm.  Is a logical solution that is inline with our daily language or mother tongue language.
  • 21. Algorithm Start 1. Set sum = 0 and average = 0 2. Read 3 numbers: nom1, nom2, nom3 3. Add 3 numbers 4. Calculate the average, average = (sum)/3 5. Print 3 numbers(nom1, nom2, nom3) and the average End
  • 22. 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.
  • 23. 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
  • 24. Flow Chart  Flow Chart  It is represents by using geometry shapes with connected line  Use a standard symbol
  • 25. 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
  • 26. Flow Chart DECISION Indicates a decision point in the algorithm CONNECTOR Indicates an entry to or exit from another part of the flowchart FLOW LINES Used to connect the flowchart symbols and indicate the logic flow LOOP Indicates the initial, final and increment values of a loop
  • 27. Example of a flow chart START END sum = 0, average = 0 Input nom1,nom2, nom3 sum = nom1 + nom2 + nom3 average = sum / 3 print nom1,nom2, nom3 print average
  • 28. Exercise  Write an algorithm and a flow chart to calculate and display a volume of a sphere. Volume = 4/3 x pi x radius x radius , where pi = 3.41
  • 29. Solution  Analyze the problem  Input :  Process :  Output : radius Calculate volume of a sphere Volume = 4/3 x pi x radius x radius print volume of a sphere
  • 30. Solution (algorithm) Start 1. Input radius 2. Calculate volume of a sphere Volume = 4/3 x pi x radius x radius 3. print volume of a sphere End
  • 31. Solution (Flow Chart) START END pi = 3.41 Input radius Volume = 4/3 x pi x radius x radius Print volume
  • 32. Control Structures Flow Chart  3 types of control structures:  Sequence structure  Selection structure  If  If… else  Repetition structure  For  While  Do… while
  • 33. Flow Chart for Selection Structure 1 Pseudo code if condition statement 1 Condition / Boolean operator Statement 1 (inside if structure) True False Example Pseudo code if student’s grade is greater than or equal to 60 Print “Passed”
  • 34. Flow Chart for Selection Structure 2 Condition / Boolean operator true false Statement 2 Statement 2 Pseudo code if condition statement 1 Else statement 2 Example Pseudo code if student’s grade is greater than or equal to 60 Print “Passed” Else Print “Failed”
  • 35. Flow Chart for Repetition Structure Condition / Boolean operator Statement 1 (inside if structure) True False Example Pseudo code While there are more items on the shopping list Purchase next item and cross it off my list
  • 36. Module Structure  Used for a big and complex problem  Divide the problem into smaller problem – sub module  To simplify a problem solving Module structure Pseudo code Main module Call sub module End of main module Sub module name Statements End of sub module Main module Sub module 1 Sub module 2
  • 37. TQ