Professional Documents
Culture Documents
1 Introduction
1
2 Theoretical Background
3 Step 1: Analysis
In this step, you have to highlight the problem statement and eliminate unimportant
aspects in the problem. There are two main activities in this step:
a) Identify what are the input, processes and output of the problem.
b) Draw a structure chart of needed. The structure chart is developed if only you
want to use top-down design, in which you divided the problem into several sub
problems.
This step is to define the process outlined in Step 1 in details. The process consists of
using the input and executing a series of actions in a specific order to produce the desired
output. This process is referred as algorithm.
Algorithm is 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. •Algorithm can be
written in pseudo codes or flowchart:
a) Pseudocode
Pseudocode is informal language that helps programmers develop
algorithms.
Its purpose is to describe in precise algorithm detail, what the program
being designed is to do.
Pseudocode defined the steps to accomplish the tasks in sufficient
details so that they can be converted to computer program.
b) Flowchart
A diagram that shows the step by step execution of a program.
Table 1 shows common flowchart’s symbols.
2
Table 1: Common flowchart’s symbols
Symbol Name Description
Terminal/Terminator The beginning or end of a
program
3
Basic control structures:
i. Sequence: is a series of statements that execute one after another
FALSE
Condition Statement 2
TRUE
Statement 1
ii. Repetition (loop): is used to repeat statements while certain conditions are
met.
CONDITION FALSE
TRUE
Statement
4
4.1 Step by step Examples
1. Start Visio 2000 : Click Start -> Program -> Microsoft Office > Microsoft
Visio
2. Choose the drawing type: On the Category section (on the left), click on the
Flowchart folder, and select Basic Flowchart on template column.
5
4. To create a new symbol, (e.g. process symbol), , click on the process item and
drag it on to the grid paper.
5.
6
To save the drawing, click on File menu ->Save as -> click the Save button.
6. To add others drawing type. Click File ->New -> and select the drawing type you
want.
ware that can be used to draw a flowchart is Dia(https://wiki.gnome.org/Dia). Dia is an open source application, and work cross
7
4.2 Problem Solving (Step 1 and Step 2)
Given the employee’s working hour, a program will calculate salary for an employee.
The pay rate for an hour is RM 6.50. The program will display the total salary of the
employee.
Step 1: Analysis
Employee’s salary
problem
i. Pseudocode
1. Start
2. Set salary=0
3. Call input() function
4. Call calculateSalary() function
5. Call display() function
6. End
Input() Function
1. Start
2. Read the employee’s working hour, hour
3. End
8
calculateSalary() Function
1. Start
2. Salary = 6.5*hour
3. End
Display() Function
1. Start
2. Display Salary
3. End
ii. Flowchart
START
input()
Read employee’s working
hour, HOUR
calculateSalary()
SALARY = HOUR*6.5
displaySalary()
Print SALARY
END
9
4.2.2 Example 2: Arithmetic Problem
A program will add two numbers and print a statement whether the sum is an even
number or an odd number. The program will repeat for five times.
Step 1: Analysis
i. Pseudocode:
1. Start
2. Set COUNTER=0
3. If COUNTER < 5
4. Read two numbers: A, B
5. C = A + B
6. If C is an even number
Print “EVEN NUMBER”
7. Else
Print “ODD NUMBER”
8. Add 1 to COUNTER
9. Repeat step (3)
10. End
10
ii. Flowchart
START
COUNTER = 0
True
READ A,B
C=A+B
False PRINT
C IS EVEN
“ODD
NUMBER?
NUMBER”
True
PRINT “EVEN
NUMBER”
COUNTER = COUNTER + 1
11
4.3
12
Exercises
2. The System will print “A” for exam grades greater than or equal to 90, Print “B” for
grades in the range 80 to 89, Print “C” for grades in the range 70 to 79, Print “D” for
grades in the range 60 to 69 and “F” for all other grades.
3. The system will calculate the perimeter of a circle. The radius is 5.With the perimeter
formula (2*radius*PI), print the output of the perimeter for the circle. Value of PI is
3.142.
4. A program will change a temperature reading from Farenheit to Celcius using the
following formula:
Celcius = (100/180) * (Farenheit – 32)
Building’s height
85 degree
13
4.4 Self-Review Questions
14
3. The flowchart below represent a program that will calculate the time takes for a ball to
hit the ground after it has been dropped from a tower. The tower’s height is to be read
from the user. Write a pseudocode for the flowchart. (You may used C++ sqrt() library
function)
START
INPUT
HEIGHT,
h
TIME = sqrt(2 * height / 32.2)
PRIN
T
TIME
STOP
4. Develop a pseudocode to interchange the content of two cups of liquid. Assume that
the third cup is available to hold the content of either cup temporarily. Each cup