Computer L-1
Computer L-1
Programming Concepts
We all know that a computer works on human instructions. It takes
a “command” or “instruction”, works upon it and gives an output.
The language which a computer can understand is binary language
or binary code which is made up of 0 (zero) and 1 (one). But writing
instructions in 0s and 1s is very difficult. That is why over a period
of time, computer science engineers and mathematics developed
languages closely related to English Language to write instructions
for the computer. These languages are called programming
languages.
Hello, World !
Flow Control
This is very interesting part of learning a program. Flow of
control is the main concept of the program which enables one to
write a program in such a way that different conditions can lead
to different outputs.
To understand this concept, let me take you to a little bike ride.
Suppose you are on a bike, going to school. There can be more
than one path to reach your school and depending on each turn or
four ways you have to take a decision of going straight, left or
right. Depending on the number of four ways and turns between
your home and your school there can be many possible paths. In a
similar manner, there can be many different algorithms for a
particular problem depending on how you manage the execution
control of your program.
In this example, you are the control head, who is going through a
path to reach a particular destination. In an algorithm or
program, there is also a control head that goes through each line
of program and the path of that control head depends on what
you have written in the statements.
An Example
Let x = 4
If x is greater than 5
Say “you are allowed in the group”.
Else say “you are not allowed in the group”.
In this example of the algorithm, the control head will go through
first and second line then it will skip the third line and directly go
to fourth line. If the value of x were greater than 5 than control
head will run through on first three line of code and will never go
to fourth line. This is how the flow of control is managed.
PROGRAMMING PARADIGMS
Programming languages can be classified on the basis of their
features. This classification is referred to as a programming
paradigm.
A programming paradigm is style or way of programming.
All computer programs consist of two elements: code and data. A
program can be conceptually organized into ways, around its
code or around its data there are basically two programming
paradigms
Procedure oriented programming (POP)
Object oriented programming (OOP)
The first programming is called procedure oriented model.
Procedural languages such as BASIC employ this model. The
second approach is called object oriented model. It organizes the
program around its data (i.e. objects) and a set of interfaces to
that data.
Procedure Oriented Programming
The focus is on procedure or function as seen in the example
given below:
An Example
If we are developing a calculator program there can be a function
foe addition of two numbers. This add function can take two
numbers, make a sum of them and then can be returned. Similarly
we will create all the functions for each operation of the
calculator then combining them with another master program
will create a calculator.
The program is written in a well defined step by step
procedure in top down approach.
It defines a systematic order of statements and tracking down
the position of control head during execution is very easy.
A problem is broken into small functions are routines for
solving a very specific part of a big problem. This function then
can be implemented with a small set of statement in an
ordered way.
A popular procedural programming language is C languages.
Other examples include COBOL, FORTRAN, ALGOL and BASIC.