Lecture6 Week 3
Lecture6 Week 3
11/05/23 1
Programming Fundamentals
while (condition)
loop-body
yes Loop
end_while Condition?
Statement(s)
no
2
Programming Fundamentals
3
Programming Fundamentals
Counter initialisation
Begin
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
end_while Updating counter
End
Begin
users = 1
while (users <= 10)
read age
print age.
users = users + 1
end_while
End
4
Programming Fundamentals
Begin
users = 1
NO
End users <= 10?
YES
read age
print age
users =users + 1
5
Programming Fundamentals
Subsequently..
You can start the
Begin 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
end_while value it requires to
End stop
Begin
users = 0
while (users < 10)
read age Be
print age. consistent
users = users + 1
end_while
End
6
Programming Fundamentals
Little extra…
Now let us put together everything that you
have learnt so far.
Problem:
Write a program that will calculate and print the
age of 10 persons, given their birth year. If the age
of the person is above 55, then the program will
print “Pencen”, otherwise, the program will print
“Kerja lagi”.
7
Programming Fundamentals
Begin
users = 1 Example 3
while (users <= 10)
begin
Read birth year
age = current year – birth year
print age Note that in this
example, we are
if age > 55 using all the three
print “Pencen” control structures:
else sequence, selection
print “Kerja lagi” and repetition
end_if
users = users + 1
end
end_while
End
8
Programming Fundamentals
Exercise
Draw the flowchart diagram for
Example 3
9
Programming Fundamentals
Implementation
The process of implementing an algorithm by
writing a computer program using a programming
language (for example, using C language)
The output of the program must be the solution
of the intended problem
The program must not do anything that it is not
supposed to do
(Think of those many viruses, buffer overflows, trojan
horses, etc. that we experience almost daily. All these
result from programs doing more than they were
intended to do)
10
Programming Fundamentals
11
Programming Fundamentals
Documentation
Writing description that explain what the
program does.
Can be done in 2 ways:
Writing comments between the line of codes
Creating a separate text file to explain the
program
Important not only for other people to use or
modify your program, but also for you to
understand your own program after a long time
(believe me, you will forget the details of your
own program after some time ...)
12
Programming Fundamentals
Documentation cont…
Documentation is so important because:
You may return to this program in future to use the
whole of or a part of it again
Other programmer or end user will need some
information about your program for reference or
maintenance
You may someday have to modify the program, or may
discover some errors or weaknesses in your program
Although documentation is listed as the last
stage of software development method, it is
actually an ongoing process which should be
done from the very beginning of the software
development process.
13
Programming Fundamentals
Exercise time!!!
14
Programming Fundamentals
Volume calculation
Write a pseudocode and a flowchart for a C+
+ program that reads the value of height,
width and length of a box from the user and
prints its volume.
15
Programming Fundamentals
Sum of 1 to 10
Write a pseudocode or flowchart for a
program that would compute and print the
sum of all integers between 1 and 10.
16
Programming Fundamentals
17
Programming Fundamentals
Summary
This lecture introduced the concept of
problem solving : a process of transforming
the description of a problem into a solution.
A commonly used method – SDM which
consists of 6 steps
3 basic control structures : sequence,
selection and repetition structures
Pseudocode and Flow chart
T.H.E E.N.D
18