Prepared by Norhamreeza Abdul Hamid
Jan 24, 2016
Prepared by Norhamreeza Abdul Hamid
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
Analyze problem
Design algorithm
Implement algorithm
Test and verify program
Maintain and update program
Steps
Prepared by Norhamreeza Abdul Hamid
STATE What problem to be solved?
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
Given the value of x is 10 and a is 12, find the result of the following equation:
y = 2x + a - 6
What is the problem?
Is it possible to
solve the problem
with
programming?
What to solve?
Prepared by Norhamreeza Abdul Hamid
Problem What is the value of y?
Data Given the value of x and a
Solution Solve the equation using the given values
State the problem clearly
Prepared by Norhamreeza Abdul Hamid
IDENTIFY
Input Output
Process
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
Input
Output
Process
Prepared by Norhamreeza Abdul Hamid
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
Identify the problem
Prepared by Norhamreeza Abdul Hamid
Develop a list of steps
called algorithm
Verify that the algorithm
solves the problem
Solve Problem
Prepared by Norhamreeza Abdul Hamid
Convert algorithm into
programming
Writing program
Also known as
CODING
Prepared by Norhamreeza Abdul Hamid
Coding
General steps involved
Documentation
Compile
Execute/Run
Write program code with
specific programming language
in specific programming
tools/software Write explaination/description
for
each line of codes/comment for
future references
Using tool/software function to
check errors in program code
Using tool/software function
to display output of program
Prepared by Norhamreeza Abdul Hamid
To verify the program can
works as desired
Testing program
Executing program to see if it
produce correct results.If not
do debugging.
Prepared by Norhamreeza Abdul Hamid
Remove undetected errors
and keep up-to-date
Modifying program
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
Analyze problem
Design algorithm
Implement algorithm
Test and verify program
Maintain and update program
Steps
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
Going to FSKTM from
FKAAS .
Making a delicious
chocolate cake.
Installing a software
into a pc.
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
Algorithm Requirements
Must have input
Must produce output
Unambiguous
Generality Correctness
Finiteness
Efficiency
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
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.
Example 2: Money withdrawal algorithm
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
A text-based design tool that helps programmers to develop algorithm
Using natural language (communication
language e.g: Malay/English) wording
phrase
Compact and informal
high level language description of a
computer programming
algorithm
Simple codes which
resembles program code that
will be written during
implementation phase
(program coding)
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
START
IF student's grade is greater than or equal to 40
PRINT the statement "passed"
ELSE
PRINT the statement "failed"
ENDIF
END
Keyword?
print means display on the
screen monitor
START
IF credit card number is valid
execute transaction based on number and
order
ELSE
SHOW a generic failure message
ENDIF
END
show also means
display on the screen monitor
Prepared by Norhamreeza Abdul Hamid
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 we’ve done in
earlier?
Prepared by Norhamreeza Abdul Hamid
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
Identify the problem
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
Write a
program!
Keyword Keyword Keyword
Prepared by Norhamreeza Abdul Hamid
Uncle Rahman wants to buy 5 tins of paint from Maria’s 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.
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 DISPLAY/PRINT the result (or the total price)
END
Write a
program!
Keyword
?
Prepared by Norhamreeza Abdul Hamid
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
END
Keyword Keyword
Keyword
Prepared by Norhamreeza Abdul Hamid
A box has height, width and length. Write the pseudo code to calculate the volume of a box.
Test your
understanding!
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
End
y = 2x + a - 6
Print y
Set x = 10
Set a = 12
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)
END Convert
to
flowchart
Prepared by Norhamreeza Abdul Hamid
Start
total price = amount of paint * price per tin
Display total price
End
Set amount of paint = 5
Prepared by Norhamreeza Abdul Hamid
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.
Convert
to
flowchart
Convert
to
flowchart
Prepared by Norhamreeza Abdul Hamid
Given the following formula, write the pseudo code to calculate the porosity of rock: porosity = (pure volume /total rock volume) x 100%
Convert to
flowchart
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
statement 1.
statement 2.
…
…
statement n.
END
statement 1
statement 2
…
statement n
start
end
Prepared by Norhamreeza Abdul Hamid
START
READ birth year, current year
CALCULATE age = current year –
birth year
DISPLAY age
END
Problem: calculate a person’s age
READ birth year – birth year
Age = current year – birth year
Display age
start
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:
IF (condition)
then-part
ELSE
else-part
ENDIF
Condition?
else-
statement(s)
then-
statement(s)
Yes No
Prepared by Norhamreeza Abdul Hamid
start
Read age
End
age > 55 no yes
print “Pencen” print “Kerja lagi” START
READ age
IF age > 55
PRINT “Pencen”
ELSE
PRINT “Kerja lagi”
ENDIF
END
START
READ age
IF age is greater than 55
PRINT “Pencen”
ELSE
PRINT “Kerja lagi”
ENDIF
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 Condition?
Loop
Statement(s)
yes
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
initialization
condition
body of loop
increment
FALSE
TRUE
cnt=0
cnt<5
cnt=cnt+1
FALSE
TRUE
Start
Print “whatever”
End
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
START
number of users giving his age = 1
WHILE number of users giving his age <= 10
READ the age from the user.
PRINT the user age.
number of user giving his age + 1
ENDWHILE
END
START
users = 1
WHILE users <= 10
READ age
PRINT age.
users = users + 1
ENDWHILE
End
Counter initialisation
Loop condition
Updating counter
Prepared by Norhamreeza Abdul Hamid
Start
End users <= 10? NO
YES
users = 1
print age
read age
users =users + 1
Prepared by Norhamreeza Abdul Hamid
START
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.
number of user giving his age + 1
ENDWHILE
END
START
users = 0
WHILE users < 10
READ age
PRINT age.
users = users + 1
ENDWHILE
END
The loop condition
must less than the
value it requires to
stop
You can start the
counter with ZERO
Be consistent
Prepared by Norhamreeza Abdul Hamid