Resources » Articles/Knowledge Sharing » Computer & Technology

Programming Techniques


Posted Date: 02-Mar-2011  Last Updated:   Category: Computer & Technology    
Author: Member Level: Gold    Points: 10


Here we look into the various programming techniques.



Programming Techniques



Every programmer follows a different programming technique. One choses a technique according to his comfort level. Subsequently there are four different programming techniques. A programmer learns all four of them during his tenure.

These four programming techniques are:


Unstructured Programming

Procedural Programming

Modular Programming

Object oriented Programming


Unstructured Programming:



Unstructured programming technique is for beginners. Programmers begin programming by making simple programs which consists of only the main method. All the statements required for the code are written in the main method. It uses and modifies the data global to the program.

For example:
Consider a simple program of addition of two numbers in C++.




#include
#include

void main()
{
int a,b,c;
clrscr();
cout << "Enter the first number";
cin >> a;
cout << "Enter the second number";
cin >> b;
c=a+b;
cout << "The sum is:" << c;
getch();
}


Here all the coding is done in the main program. No other method is created. This is unstructured programming and usually beginners follow this technique.

Drawbacks:
When the program size increases, it becomes difficult to maintain.

If the same code is required elsewhere, it is to be rewritten.

To overcome these drawbacks, procedural programming was introduced.



Procedural Programming:


Here for each task, a new procedure is created. This procedure is called in the main program. Thus if the same code is required elsewhere, it is not rewritten, only the function need to be called. Thus code remains small.

For example:

The same program above is developed using a function add.




#include
#include
void main()
{
int add(int,int);
int a,b,c;
clrscr();
cout << "Enter the first number";
cin >> a;
cout << "Enter the second number";
cin >> b;
c=add(a,b);
cout<<"The sum is:" << c;
getch();
}
int add(int x,int y)
{
int z=x+y;
return z;
}


Here if addition is required elsewhere, only the function need to be called, whole code need not be written.



Modular Programming:


In modular programming procedures with some common functionality are grouped together into separate modules. Thus a program now is not a single entity. It is categorized into several smaller modules. To enable usage of general procedures or groups of procedures also in other programs, they must be separately available. For that reason, modular programming allows grouping of procedures into modules.



Object Oriented Programming:



Object oriented programming technique works on objects which is considered smallest unit of the object oriented languages. Problem is scattered around in the objects and the main method only collects these objects. Here data is given importance rather than procedures, thus maintaining data security.
Also it follows bottom-up approach.

For example:

The same above program using class and object is:




#include
#include

class Addition
{
int a,b,c;
public:
void read()
{
cin >> a;
cin >> b;
}
void add()
{
c=a+b;
}
void display()
{
cout << "The sum is:" << c;
}
};
void main()
{
Addition obj; //object creation
cout << "Enter the numbers";
obj.read();
obj.add();
obj.display();
getch();
}


This technique has become most famous as it correlates with the real world.


Did you like this resource? Share it with your friends and show your love!




Responses to "Programming Techniques"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Awards & Gifts
    Active Members
    TodayLast 7 Daysmore...

    Online Members

    Sudarmani
    More...
    ISC Technologies, Kochi - India. Copyright © All Rights Reserved.