You are on page 1of 84

Prepared by Norhamreeza Abdul Hamid

Computer
programmer

WHAT

Program ??
Prepared by Norhamreeza Abdul Hamid

Steps used to solve problem in


computer programming

Also known as
Software/ System
Development Life Cycle
(SDLC) or software
process

A development of a software/computer
program product.
Prepared by Norhamreeza Abdul Hamid

Specify problem

Steps

Analyze problem
Design algorithm
Implement algorithm
Test and verify program
Maintain and update program
Prepared by Norhamreeza Abdul Hamid

What
problem to
be solved?

STATE

What is the
problem?

Is it possible to solve
the problem with
programming?
Prepared by Norhamreeza Abdul Hamid

State the
problem
clearly

Gain a clear
understanding of
what are
required for its
solution.
Prepared by Norhamreeza Abdul Hamid

What is the
problem?
Given the value of x is 10 and a is 12,
find the result of the following equation:

y = 2x + a - 6

What to
solve?

Is it possible to
solve the problem
with
programming?
Prepared by Norhamreeza Abdul Hamid

State the problem clearly


Problem
Data
Solution

What is the value of y?

Given the value of x and a


Solve the equation using the given
values
Prepared by Norhamreeza Abdul Hamid

IDENTIFY

Output

Input
Process

Prepared by Norhamreeza Abdul Hamid

Input
Given the value of x is 10 and a is 12,
find the result of the following equation:

y = 2x + a - 6

Process

Output
Prepared by Norhamreeza Abdul Hamid

Identify the problem


Input

Value of x and a

Process

Replace the value of x and a in the


formula, y = 2x +a -6

Output

The value of the equation, y


Prepared by Norhamreeza Abdul Hamid

Solve Problem
Develop a list of steps
called algorithm

Verify that the algorithm


solves the problem

Prepared by Norhamreeza Abdul Hamid

Writing program
Convert algorithm into
programming

Also known as
CODING

Prepared by Norhamreeza Abdul Hamid

General steps involved

Write program code with


specific programming language
in specific programming
Coding
Writetools/software
explaination/description
for
Documentation
each line of codes/comment for
future references
Compile
Using tool/software function to
check errors in program code
Execute/Run Using tool/software function
to display output of program

Prepared by Norhamreeza Abdul Hamid

Testing program
To verify the program can
works as desired

Executing program to see if it


produce correct results.If not
do debugging.

Prepared by Norhamreeza Abdul Hamid

Modifying program
Remove undetected errors
and keep up-to-date

USE and MODIFY the program


to meet changing requirements
or correct errors that show up
in using it

Prepared by Norhamreeza Abdul Hamid

Specify problem

Steps

Analyze problem
Design algorithm
Implement algorithm
Test and verify program
Maintain and update program
Prepared by Norhamreeza Abdul Hamid

Algorithm

Pseudocode

Flowchart

Control
Structure

Prepared by Norhamreeza Abdul Hamid

Programming is a problem solving activity. When you write


a program, you are actually writing an instruction for the
computer to solve something for you.

Problem solving is the process of transforming the


description of a problem into a solution by using our
knowledge of the problem domain and by relying on our
ability to select and use appropriate problem-solving
strategies, techniques and tools.
Prepared by Norhamreeza Abdul Hamid

Making a delicious
chocolate cake.

Installing a software
into a pc.

Going to FSKTM from


FKAAS .

Log into a system.

Prepared by Norhamreeza Abdul Hamid

How to make a delicious chocolate cake?


Prepare the ingredients.
Beat the butter and the eggs.
Mix with cake flour and sugar.
Add chocolate to the mixture.
Pour the mixture
Put the mixture in the oven.
Bake for 45 minutes.
Wipe chocolate cream around the baked
cake.
Prepared by Norhamreeza Abdul Hamid

How to install a software into a pc?


Put the software CD in the CD driver.
Open the CD directory in pc.
Click the installer file in the CD, install.exe.
Follow the setup instructions for installation
process.
Or use Control Panel > Add programs.

Prepared by Norhamreeza Abdul Hamid

How to log into an online system?


If you are a registered user,
Enter your ID or username
Enter your password
Click on the submit button
If you are not registered, do the registration
process by filling in the registration form.

Prepared by Norhamreeza Abdul Hamid

How to go to FSKTM from


FKAAS?

Prepared by Norhamreeza Abdul Hamid

Withdraw money from ATM machine


Register subjects through online system
Buy cold drinks from vending machine
Calculate the monthly salary payment
Calculate car loan interest
Determine odd and even numbers
Count the total visitor of a Web
Determine air velocity in physic lab
Prepared by Norhamreeza Abdul Hamid

Prepared by Norhamreeza Abdul Hamid

Writing computer program

Prepared by Norhamreeza Abdul Hamid

Algorithm is a sequence of a finite


number of steps arranged in a specific
logical order to produce the solution for a
problem.

Prepared by Norhamreeza Abdul Hamid

Steps in
Computer program
for computer
to do its job

Famous muslim
scientist/
mathematician
Prepared by Norhamreeza Abdul Hamid

Procedure or formula
for solving problem
Sequence set of
steps taken to
solve a problem
Instructions for actions to be executed by computer
(input/process/output)
Prepared by Norhamreeza Abdul Hamid

Must have
input

Must produce
output

Efficiency

Algorithm
Requirements
Finiteness

Unambiguous

Correctness

Generality

Prepared by Norhamreeza Abdul Hamid

Step 1: Go to the taxi stand.


Step 2: Get in a taxi.
Step 3: Give the taxi driver the destination
address.
Step 4: Once arrived, pay the taxi fare.
Step 5: Get out from the taxi.

Prepared by Norhamreeza Abdul Hamid

Example 2: Money withdrawal algorithm


Step 1: Go to the ATM machine.
Step 2: Insert ATM card.
Step 3: Select language.
Step 4: Enter pin number.
Step 5: Select withdrawal option from menu.
Step 6: Enter amount of money to withdraw.
Step 7: Take the money.
Step 8: Take the bank slip.

Prepared by Norhamreeza Abdul Hamid

Do computer can really


understand algorithm?
Algorithm is used by programmer to plan
the instructions to be written in the
computer program and executed by
computer
Prepared by Norhamreeza Abdul Hamid

Prepared by Norhamreeza Abdul Hamid

Prepared by Norhamreeza Abdul Hamid

Pseudocode is a semiformal, English-like language with


limited vocabulary that can be used to design & describe
algorithms.
Purpose: to define the procedural logic of an algorithm in
a simple, easy-to-understand for its readers.
Free of syntactical complications of programming
language.
Prepared by Norhamreeza Abdul Hamid

Simple
codes
which
resembles program code that
will
be
written
during
implementation
phase
(program coding)

A text-based design tool


that helps programmers to
develop algorithm
Compact and informal
high level language
description of a
computer programming
algorithm

Using natural language


(communication
language e.g:
Malay/English) wording
phrase
Prepared by Norhamreeza Abdul Hamid

i.

Consists of a statement of instructions in sequence.

ii.

Every steps consists of keyword which explain the


actions/operation/process to be executed by
computers

iii. Every steps should be written in different steps, if


continued, the next row must be indented.
iv. Can use IF/ELSE for conditional statement and WHILE,
DO/WHILE and FOR repetition statement
v. Every steps should use clear statements and easy to
understand.
vi. Use START to represent the beginning of the operation
and END to show the end of the operation.

Prepared by Norhamreeza Abdul Hamid

Keyword?
START
IF student's grade is greater than or equal to 40
PRINT the statement "passed"
ELSE
PRINT the statement "failed"
ENDIF
END

print means
display on the
screen
monitor

show also
START
means
IF credit card number is valid
execute transaction based on number and
display on
order
the screen
ELSE
monitor
SHOW a generic failure message
ENDIF
Prepared by Norhamreeza Abdul Hamid
END

START
SET total to zero
SET grade counter to one
WHILE grade counter is less than or equal to
ten
INPUT the next grade
ADD the grade into the total
ENDWHILE
SET the class average to the total divided
by ten
PRINT the class average.
END

set means
assign the
value,e.g:
total = 0
while is used
whenever
the process is
to be
continued

Prepared by Norhamreeza Abdul Hamid

Write the pseudo code based on the IPO


(input/process/output) which you have identified during
the analyzing phase
Identify the keyword(s) based on the IPO

Did you remember the steps weve done in


earlier?
Prepared by Norhamreeza Abdul Hamid

Identify the problem


Input

Value of x and a

Process

Replace the value of x and a in the


formula, y = 2x +a -6

Output

The value of the equation, y


Prepared by Norhamreeza Abdul Hamid

Given the value of x is 10 and a is 12,


find the result of the following equation:

Write a
program!

y = 2x + a - 6
Keyword
Keyword
START
SET the value of x to 10
SET the value of a to 12
COMPUTE the value of y as y = 2x + a - 6
DISPLAY/PRINT the result (or the value of y)
END

Prepared by Norhamreeza Abdul Hamid

Uncle Rahman wants to buy 5 tins of paint from Marias


shop. The price of each tin of the paint is RM 15.60.
Calculate the price which Uncle Rahman have to pay for
all the tin of paints he bought.
Write a
program!
START
SET the amount of paint to 5
SET the price per tin to 15.60
COMPUTE the total price as price per tin times by
amount of paint
Keyword
DISPLAY/PRINT the result (or the total price)
?
Prepared by Norhamreeza Abdul Hamid
END

Keyword
START
READ the student mark
IF mark is greater than 85 and mark is less than 100
set grade as A
ENDIF
DISPLAY/PRINT the grade Keyword
END

Prepared by Norhamreeza Abdul Hamid

Test your
understanding!

A box has height, width and length.


Write the pseudo code to calculate the volume
of a box.

Write the pseudo code to calculate salary of


an employee for a month.
Prepared by Norhamreeza Abdul Hamid

START
INPUT/READ height, width, length
CALCULATE the volume = height * width * length
PRINT/DISPLAY volume
END

START
INPUT/READ salary per day
CALCULATE the salary= salary per day*30 days
PRINT/DISPLAY salary
END
Prepared by Norhamreeza Abdul Hamid

START
READ/INPUT pure volume, total rock
CALCULATE porosity = (pure volume / total
rock volume) x 100%
DISPLAY porosity
END

Prepared by Norhamreeza Abdul Hamid

Prepared by Norhamreeza Abdul Hamid

Flowchart is a graph of geometrical shapes that are


connected by lines.
2 important elements in flowchart:
Geometrical shapes represent type of
statements in the algorithm.
Flow line show the order in which the
statements of an algorithm are executed.
Prepared by Norhamreeza Abdul Hamid

Schematic representation of an
algorithm or process

Helps to visualize the


content/steps better or to find
flaws in process
Illustrate the steps in the
process
Prepared by Norhamreeza Abdul Hamid

Start/End
The terminator symbol marks
the starting or ending point of
the system. It usually contains
the word "Start" or "End."

Action or Process
A box can represent a single
step ("add two cups of flour"),
or and entire sub-process
("make bread") within a larger
process.
Prepared by Norhamreeza Abdul Hamid

Decision

A decision or branching
point.
Lines
representing
different decisions emerge
from different points of the
diamond.

Input/Output

Represents
material
or
information
entering
or
leaving the system, such as
customer order (input) or a
product (output).
Prepared by Norhamreeza Abdul Hamid

Flow Line
Lines indicate the sequence
of steps and the direction of
flow.

Connector
Indicates
that
the
flow
continues where a matching
symbol (containing the same
letter) has been placed.

Prepared by Norhamreeza Abdul Hamid

Off Page
Indicates that the process
continues off page.

Database
Indicates a list of information
with a standard structure that
allows for searching and
sorting.

Prepared by Norhamreeza Abdul Hamid

What software use


to draw flowchart?
You can use
Ms word >
AutoShapes >
Flowchart or
other flowchart
drawing tools
e.g: SmartDraw/Visio
Drawing,etc.
Prepared by Norhamreeza Abdul Hamid

Given the value of x is 10 and a is 12,


find the result of the following equation:

y = 2x + a - 6
START
SET the value of x to 10
SET the value of a to 12
compute the value of y as y = 2x + a -6
DISPLAY/PRINT the result (or the value of y)
END
Prepared by Norhamreeza Abdul Hamid

Start
Set x = 10

Set a = 12
y = 2x + a - 6

Print y
End
Prepared by Norhamreeza Abdul Hamid

START
SET the amount of paint to 5
COMPUTE the total price as price per tin times by
amount of paint
DISPLAY/PRINT the result (or the total price)
Convert
END

to
flowchart

Prepared by Norhamreeza Abdul Hamid

Start

Set amount of paint = 5

total price = amount of paint * price per tin

Display total price

End
Prepared by Norhamreeza Abdul Hamid

A box has height, width and length.


Write the pseudo code to calculate the volume
of a box.
Convert
to
flowchart
Write the pseudo code to calculate salary of
an employee for a month.

Prepared by Norhamreeza Abdul Hamid

Convert to
flowchart

Given the following formula, write the pseudo code


to calculate the porosity of rock:
porosity = (pure volume /total rock volume) x 100%

Prepared by Norhamreeza Abdul Hamid

Start

Read height, width,


length

volume = height * width * length

Display volume

End
Prepared by Norhamreeza Abdul Hamid

Start

Read salary per day

salary = salary per day * 30 days

Display salary

End
Prepared by Norhamreeza Abdul Hamid

Start

Read pure volume,


total rock volume

porosity = (pure volume / total rock


volume) x 100%

Display porosity

End
Prepared by Norhamreeza Abdul Hamid

Prepared by Norhamreeza Abdul Hamid

Sequential
Selection
Repetition

Prepared by Norhamreeza Abdul Hamid

Sequence: A series of steps or statements that


are executed in the order they are written in an
algorithm.
Selection: Defines two courses of action
depending on the outcome of a condition. A
condition is an expression that is, when
computed, evaluated to either true or false.
Repetition: Specifies a block of one or more
statements that are repeatedly executed until a
condition is satisfied.
Prepared by Norhamreeza Abdul Hamid

You may have more


than
one
control
structure in one program
in order to solve a
problem.
Prepared by Norhamreeza Abdul Hamid

A series of steps or statements that are executed


in the order they are written in an algorithm.
The beginning and end of a block of statements
can be optionally marked with the keywords
START and END.
start

START
statement 1.
statement 2.

statement n.
END

statement 1

statement 2

statement n
end

Prepared by Norhamreeza Abdul Hamid

Problem: calculate a persons age


START
READ birth year, current year
CALCULATE age = current year
birth year
DISPLAY age
END

start

READ birth year birth year

Age = current year


birth year

Display age

end

Prepared by Norhamreeza Abdul Hamid

Defines two courses of action depending on the


outcome of a condition. A condition is an
expression that is, when computed, evaluated to
either true (1) or false (0).
The keyword used are if and else.

Prepared by Norhamreeza Abdul Hamid

Format:
No

IF (condition)
then-part
ELSE
else-part
ENDIF

elsestatement(s)

Condition?

Yes

thenstatement(s)

Prepared by Norhamreeza Abdul Hamid

START
READ age
IF age is greater than 55
PRINT Pencen
ELSE
PRINT Kerja lagi
ENDIF
END
START
READ age
IF age > 55
PRINT Pencen
ELSE
PRINT Kerja lagi
ENDIF
END

start

Read age

yes

age > 55

no

print Kerja lagi

print Pencen

End

Prepared by Norhamreeza Abdul Hamid

Specifies a block of one or more


statements that are repeatedly executed
until a condition is satisfied.
The keyword used is while.

Prepared by Norhamreeza Abdul Hamid

Format:
WHILE (condition)
loop-body
ENDWHILE

yes
Condition?

Loop
Statement(s)

no

Prepared by Norhamreeza Abdul Hamid

Counter
Can be used to control execution of the loop
(loop control variable)
It will increment or decrement each time a
loop repeats
Must be initialized before entering loop

Prepared by Norhamreeza Abdul Hamid

Start
initialization

cnt=0
FALSE

condition
TRUE

body of loop
increment

FALSE

cnt<5

End

TRUE

Print whatever
cnt=cnt+1

Prepared by Norhamreeza Abdul Hamid

Problem: Write a program that reads and displays


the age of 10 people (one after another).
For this problem, we need a way to count how many
people whose age have been processed (read and
displayed). Therefore, we introduce a concept of counter,
a variable used to count the number of people whose
age have been processed by the program.

Prepared by Norhamreeza Abdul Hamid

Counter initialisation
START
number of users giving his age = 1
WHILE number of users giving his age <= 10
READ the age from the user.
Loop condition
PRINT the user age.
number of user giving his age + 1
ENDWHILE
Updating counter
END

START
users = 1
WHILE users <= 10
READ age
PRINT age.
users = users + 1
ENDWHILE
End
Prepared by Norhamreeza Abdul Hamid

Start

users = 1

NO
End

users <= 10?


YES
read age

print age

users =users + 1
Prepared by Norhamreeza Abdul Hamid

You can start the


START
counter with ZERO
number of users giving his age = 0
WHILE number of users giving his age < 10
READ the age from the user.
PRINT the user age.
The loop condition
number of user giving his age + 1
must less than the
ENDWHILE
value it requires to
END
stop

START
users = 0
WHILE users < 10
READ age
PRINT age.
users = users + 1
ENDWHILE
END

Be
consistent

Prepared by Norhamreeza Abdul Hamid

Prepared by Norhamreeza Abdul Hamid

You might also like