You are on page 1of 9

Thematic Courses leading to

Diploma in Information Communication Technology


for Educational Managers (DICTEM)
South Asian Center for Teacher Development
National Institute of Education(NIE), Meepe Junction, Padukka.

Course No 3: Computer Programming I

D. Anura Jayalal
Director (Education Administration & Development)
Center for Education Leadership Development
National Institute of Education
2014
1. Introduction to Programming
1.1. Evolution of computer programming languages

The first computer programming language was machine code and the computer language
available in 1st Generation computers with vacuumed tube was machine code. Machine codes are
binary codes and each instruction performs a single machine action. Therefore, program code is
long and very difficult to write and manage machine code. The second generation programming
language is Assembly Language. A symbolic set of instructions is used in assembly language.
These symbolic instructions are meaningful abbreviations or mnemonics. These instructions are
converted to machine codes by the assembler program when instructions execute by the
computer. The conversion is required because the computer knows machine code only.
Assembly coding is also very long and difficult to write and maintain. Then the high level
languages were developed. A series of English like words were used in high level languages.
One word represented large set of machine codes. These words have closer meaning in human
language. A high level language program is not readable to the computer and the program is
converted to machine code by interpreter or compiler. The examples for 3rd generation languages
are COBOL, FORTRAN, BASIC, PASCAL and C. Then, Object oriented programming
languages and visual programming languages were developed. They are Java, C++, C# and
Visual Basics. Artificial Intelligence (AI) incorporated languages are the latest programming
languages. AI languages consider functioning in human brain and they have developed with
these features. Such, languages are PROLOG, LISP and MERCURY. It is difficult to start
learning the computer programming through these AI languages for a beginner. Therefore, this
course is designed to learn visual programming language.

The foremost visual programming language is Visual Basic (VB). The Visual Basic 6.0 was very
popular and most of programmers still use the Visual Basic 6.0 to developed software. Later VB
.Net was released. Visual Basic 2010 and Visual Basic 2012 are latest released languages. Most
of the current languages are visual languages. A visual language has Graphical/Visual IDE
(Integrated Development Environment). The output of the program can be designed through this
type of IDE. Current Operating systems also have Graphical User Interface (GUI).

Visual Programming Languages as well as programs of current operating systems do not use text
based data input and output objects. Visual programming languages have already developed
visual objects to use directly. An essential competency to be achieved by learner is that how to
apply these visual objects in programming with visual IDE. Therefore, visual languages are very
popular and it is essential requirement in programming. But, most of courses in Sri Lanka still
teach non visual languages. In this course, we learn with Visual Basic 2010 programming
language.

1.2. Compilers/Interpreters
A program written by programming languages is called source code and it is not readable to
computer. The instructions in such source code are as English words. Therefore, these
instructions have to be converted to Machine language. After converted to machine code, the
computer can perform the instruction in the program. There are two types of programs to convert
this source code to machine code. They are called compilers and interpreters.
An interpreter converts instructions in source code line by line to machine code and send them to
execute. Therefore, the interpreter program should be installed in the computer to run such
program. But, the compiler program converts the source code to machine code and do not run the
program at the conversion time. It converts entire program and creates a machine code
instruction file with .exe or .com extension. This file has machine code instructions and it can
run on the Operating System directly without any other program. If you wish to develop a
software package and deploy on several computers it is better to use a programming language
with compiler. Otherwise, you may need to install the programming language also on these
computers. But, you may not have legal licenses to install the programming language on other
computers.

1.3. Software Development Process


There are several phases in software development process. This process is called software
development life cycle. The software development life cycle has following phases.
 Identification
 Feasibility Study
 Analysis
 Designing
 Coding
 Debugging and testing
 Maintenance
Initially, it is required to identify the software system to develop. Although a software system is
identified it may not feasible to develop when it considers development and maintenance cost
and benefits can be achieved from the system.

In the analysis phase system is divided to parts and identifies the features and functionalities of
each part. While dividing the system to parts, it considers how to join these parts as whole.
Purpose of analysis phase is to achieve the correctness and the optimization of the program.

In the design phase each part identified in the analysis phase are graphically designed and are
explained well. Each part is coded by developing computer programs in the coding phase.

Developed program code may not work as required. There may be errors when it applies
practically. Therefore, these coding has to be debugged and tested. There are two types of
testing. Initially, programmer will test and debug the coding considering developed code
segments. If there are errors programmer will remove these errors in the debugging and testing
phase. Later, the system is given to users of the system and they will use the system without
considering internal code segments. Sometimes, there may have extra errors that were not
identified by the programmer because all possible practical situations may not identify in
analysis and design phases. Similarly, there may be various reasons to have more errors. These
errors may be identified when the users apply the system initially. These errors of the system
are also rectified by the programmer. When the system is used regularly, it may find more
errors. Therefore, debugging and testing and maintenance will do continuously for long period
because user will find faults while it uses generally.
When a software system is developed, it will go to earlier phases regularly when there is a
problem. If it is identified the system is not feasible to develop, it will go to 1st phase to identify
different system. Similarly in the each phase it will go to earlier stages if there is a problem.

2. Flow Chart/pseudo code

There are several methods to design software. Flow charts and pseudo code are used from early
stage of programming. But the flow chart is very effective for a short segment of code. It shows
the program graphically. There are graphic symbols to design the features in programming. The
basic symbols are as follows.

Flow of the program Terminate Symbol Input/ Output symbol

Process Symbol Decision Symbol

Example 1:
For example, let us consider how to draw a flow chart for a program to add two numbers.

Start

Enter a Number
(A)

Enter a Number
(B)
Pseudo Code for Example 1

C=A+B
Enter a number to A
Enter a number to B
Print C Let C=A+B
Print C

End
Example 2:
The following is a flow chart to calculate the multiplication of three numbers.

Start

Enter Numbers
(A, B and C)
Pseudo Code for Example 2

C=A*B*C Enter a number to A


Enter a number to B
Enter a number to C
Print C
Let C=A*B*C
Print C

End

The above flow charts have set of symbols in a sequence. They will activate from start to end one
by one. Organizing as above is called sequencing. Now let us consider, different situation which
break this sequence style.
Example 3:
People in our country can vote if their age is greater than 18. Let us draw a flow chart to identify
whether a person can or cannot vote according to the age of the person.

Start

Enter the Age

If Print “Can Pseudo Code for Example 3


Age>18 vote”
Yes
Enter a number to Age
If Age is greater than 18
No
Print “Can vote”
Print “Can’t
vote” else
Print “Can’t vote”

End
The above flow chart has sequence order as well as decision making situation. Such program
shows computer can think and give a decision. But we have to design the implementation of
thinking.

The decision symbol has a condition of Age>18. Here, Age is given by the user and now we do
not know the value in the Age. The Age and 18 are numbers. But when it applies greater than
comparison, Age>18 become true or false value. We called that value is a Boolean value.
Therefore, a condition in a decision symbol should have a Boolean value of true or false.

Example 4:
In the above example, they can vote if they are only citizens of Sri Lanka. Therefore, the flow
chart can be changed as follows. The condition in the decision symbols, should be as Age>18
and Citizen=”Yes”. There are two conditions. Both conditions have Boolean values. Boolean
values can be joined with Boolean operators. Both conditions should have true values to vote.
That means, they should be over 18 and a citizen of Sri Lanka to vote. If it is used “or” operator,
one condition is enough to be true to make final result to be true. Here “or” operator cannot be
used because both conditions should have true values to vote.

Start

Enter the Age


and Citizen

If Age>18 and Print “Can vote”


Citizen=”Yes” Yes

Yes

No

Pseudo Code for Example 4


Print “Can’t Enter a number to Age
vote”
Enter a value to Citizen (“Yes”/”No”)
If Age>18 and Citizen=”Yes” then
End
Print “Can vote”
else
Print “Can’t vote”
Example 5:
A company provides lots of items for the customers. Some customers are registered as
regular customers. This company provides 10% discounts for customers if they buy items
over Rs. 50,000/=. They provide 10% discounts for regular customers without considering
the total bill value.
Pseudo Code for Example 5
Start
Enter the Bill Value to BV
Enter Regular Customer (True/False)
Enter the Bill If BV> 50000 or RC then
Value (BV)
Enter Regular
Let FBV=BV*90/100
Custer (RC) else
Let FBV=BV
Print FBV

If BV>50000 or
Yes FBV=BV*90/100
RC

No

FBV=BV

Print FBV

End

In this example also two conditions are available and these conditions should be joined with
or operator. Any one of the condition out of two conditions is enough to be true to provide
the 10% discount. Therefore, here “or” operator has been used.

Example 6:

Earlier examples, explain drawing of flow charts for sequences and decisions. This example
explains about repetitions. This flow chart shows addition of numbers from 1 to 10. The
process of addition is repeated from the value 1 to 10.
Start

N=1
T=0

If
N<=10 Print “Total=”,T
No

Yes
Pseudo Code for Example 6
End Let N=1
T=T+N
N=N+1 Let T=0
While N<=10
T=T+N
N=N+1
Print “Total=”,T

Initially, N is equal to 1 and T is equal to 0. Here, N is to represent numbers from 1 to 10 and T is


the total of each number from 1 to 10. Then it comes to the decision symbol. Now, value in N is
one. When N is equal to one the condition N<=10 is true and it goes to Yes direction.

Then it reaches process symbol. There are two lines. The equation T=T+N create the total of all
numbers. The equation N=N+1 is to make increment to the number N. This equation is
mathematically wrong. The equation N=N+1 is similar to 0=1. That is wrong expression. The
performance of such equation in programming is not like in mathematics. There are one variable
in left hand side and there is an expression in the right hand side. The expression in the right
hand side is evaluated and is found a value for right hand side. Then, that value is assigned to the
variable in left hand side. Therefore, these equations are meaningful in programming. Then the
value 1+1, that means value 2 will assigned to N. Similarly 1(=0+1) is assigned to T.

After the process symbol, it comes to the decision symbol again. Now, value in N is two. When
N is two, N<=10 is true and it goes to Yes direction again. Then it reaches process symbol. Then
T becomes 3 (1+2) and N becomes 3. Similarly, in the next round T and N become 6 (3+3) and 4
(3+1) respectively. This repetition will do up to T becomes 55 and N becomes 11. Then N<=10
(11<=10) is false and it comes to No direction. Then the repetition will be terminated and it will
print as Total =55.

There is no exact symbol for the repetition. Same decision symbol is used for repetition. It will
be realized in following Pseudo Code. Similar Pseudo Code for above flow chart is as follows.
Pseudo Code for Example 6
Let T=0
For N=1 to 10
T=T+N
Next
Print “Total=”,T

The above coding is also suitable for the above example. Usually, “for next” is easy to use than
“while” because “for next” gets auto increment for variable N. Therefore, flow chart is not good
to learn about programming. It is not suitable to current computer programming languages.
Therefore, learning flow charts, instead of learning programming languages is not advisable.
Anyway, it is useful certain level only to display complex code segment graphically.

You might also like