0% found this document useful (0 votes)
29 views28 pages

MTS 3013 Structured Programming

Uploaded by

d20231106422
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views28 pages

MTS 3013 Structured Programming

Uploaded by

d20231106422
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 28

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
 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

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 – steps that should be followed in
order to solve the problem.
 Example – a cookie recipe – you need to
follow each recipe instruction in order,
beginning with the first instruction and ending
the last
 ?? Cooking rice – what are the steps?
Example: Algorithm
 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.
Example: Algorithm

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

Input nom1,nom2, nom3

sum = nom1 + nom2 + nom3

average = sum / 3

print nom1,nom2, nom3


print average

END
Exercise
 Write a pseudo-code 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 : radius

 Process :Calculate volume of a sphere


Volume = 4/3 x pi x radius x radius
 Output : print volume of a sphere
Solution (Pseudo code)
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

pi = 3.41

Input radius

Volume = 4/3 x pi x radius x 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

Example Pseudo code


if student’s grade is greater than or equal to 60
Print “Passed”
Flow Chart for Selection
Structure 2

false true
Condition / Boolean Statement 1
Statement 2 operator

Pseudo code
if condition Example Pseudo code

statement 1 if student’s grade is greater than or equal to 60

Else Print “Passed”

statement 2 Else
Print “Failed”
Flow Chart for Repetition
Structure

True
Condition / Boolean Statement 1 (inside if
operator structure)

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 Main module


Call sub module
End of main module
Sub module Sub module
1 2 Sub module name
Statements
End of sub module
TQ

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy