Unit 3: Objectives
Unit 3: Objectives
Unit 3: Objectives
UNIT 3
OBJECTIVES
INPUT
The first step in writing instructions to carry out a task is to determine what the
output should be – that is, what the task should produce. The second step is to
identify the data, or input, necessary to obtain the output. The last step is to
determine how to process the input to obtain the desired output. The general process
of writing program is to analyze the problem, design and plan the solution, coding
B3062/3/3
which is to translate the algorithm into a programming language and finally testing
and debugging.
In this unit we shall discuss the logical sequence of precise steps that solve the
problem known as algorithm and three popular programming tools or techniques
used to develop the logic plan: flowcharts, pseudo code and structure chart or input-
process-output chart.
3.0.1 Algorithm
3.0.2 Flowcharts
The main advantage of using a flowchart to plan a task is that it provides a pictorial
representation of the task, which makes the logic easier to follow. We can clearly see
each and every step and how it is connected to the next step. For example lets look at the
discount sales program.
Start
End
The major disadvantage with flowcharts is that when a program is very large, the
flowcharts may continue for many pages, making them difficult to follow and modify.
3.0.3 Pseudocode
Pseudocode is an abbreviated version of actual computer code. The
geometric symbols used in flowcharts are replaced by English-like statements that
outline the process. Pseudocode looks more like computer code than does flowchart.
It allows programmer to focus on the steps required to solve a problem rather than on
how to use computer language.
Calculate price
discount value = price * rate of discount discount price = price – discount value
Activity 3A
Question 3.1
i. input/output
ii. processing
iii. decision
Question 3.2
Question 3.3
What is an algorithm?
B3062/3/9
Feedback To Activity 3A
Question 3.1
i. input/output
ii. processing
iii. decision
Question 3.2
1. Pseudocode
2. flowchart
3. structure chart
Question 3A.3
sequencing which emphasize the translating of each step of program outline into one
INPUT
Discussion: The average grade equals the sum of all grades divided by
number of students. We need a loop to read and then add (accumulate) the
grades for each student in the class. Inside the loop, we also need to total
(count) the number of students in the class.
Processing: Find the sum of the grades; count the number of students;
calculate average grades = sum of grades / number of students.
Start
counter and
Initialize sum start at 0
counter and
sum to 0
Are
There more No
Data?
Yes
read next
Get next
grade
grade
add 1 to
Increment counter
counter
accumulate
Add grade sum of grades
to sum
End
B3062/3/12
Activity 3B
Question 3.1
You are to plan a program to sum two integer entered by user and display the result
of the summation by using the flowchart technique, from the following pseudocode;
Feedback To Activity 3B
Question 3.1
Start
Calculate sum of
two number
End
B3062/3/14
KEY FACTS
1. The algorithm should be tested at the flowchart stage before being coded
into a program.
2. Pseudocode, flowcharts and structure charts are universal problem
solving tools that can be used to construct program in any computer
language
3. Flowcharts are used to provide visualization of the flow of certain
programming tasks
B3062/3/15
1.
SELF-ASSESSMENT
You are approaching success. Try the question in this self-assessment section and
check your answers with those given in the Feedback on Self-Assessment given on
the next page. If you face any problems, discuss it with your lecturer. Good luck.
Question 3-1
Every employee who earns more than RM 50,000.00 per annum is required to pay
2.5 % of their nett yearly income. Write a complete program algorithm which will
calculate and display all the employees income tax return. Also, show the flowchart
for the program.
B3062/3/16
Feedback To Self-Assessment
Have you tried the question????? If “YES”, check your answer now:
Question 3-1
Discussion: The program must read the yearly income entered by user and select
income more than RM 50,000.00 to be multiplied by 2.5 %. Income less than
RM50,000.00 will be multiplied by 0. The result will be displayed..
Processing: Select the value of income; more than 50000.00 calculate the income
tax return = yearly income * 0.025. Less than 50000.00 calculate the income tax
return = yearly income * 0.00.
Start
End
CONGRATULATIONS!!!!…..
May success be with you
always….