Introduction:
Most of us have heard the word programming. Programming means telling the computer how to work. There are several alternative approaches to the programming process, referred to as programming paradigms. Different paradigms use different approaches to solve a particular problem. Most common Programming Paradigms are imperative, procedural, object-oriented, functional, logical, etc. Here, we will talk about procedural and object-oriented programming paradigms.
Procedural Programming(POP):
In simple words, “Procedure means a series of actions conducted in a certain order or manner.” So, Procedural Programming is, “ Set of instructions given to the computer to solve a particular problem step by step.” In such programming, you know what part of the program is going to execute next. In Procedural Programming, the program is organized into a set of procedures called functions. These functions perform specific tasks based on logic. Functions can be declared outside or inside the main function. Procedural Programming works on a “top-down approach”. No doubt, the first language used was Procedural. It is relatively the best choice for beginners. As most educational institutes, teaching procedural programming as a first language.
Example Of Procedural Programming
#include <iostream>
using namespace std;
//function declaration
int addition(int a,int b);
int main()
{
int num1; //to store first number
int num2; //to store second number
int add; //to store addition
//read numbers
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
//call function
add=addition(num1,num2);
//print addition
cout<<"Addition is: "<<add<<endl;
return 0;
}
//function definition
int addition(int a,int b)
{
return (a+b)
}
Object-Oriented Programming(OOP):
In object-oriented programming, all actions are carried out using an object. Object: An object is a data field that knows how and when to perform a certain task and how to interact with other parts of a program. Human beings can be referred to as real-world objects that have some properties like their name, actions, roles, etc. Similarly, objects have properties like their methods(functions as in procedural programming) and attributes. Methods are functions that are defined inside a class that describe the behaviors of an object and attributes are defined inside the class and define the state of an object. So, the class is the blueprint of an object and the object is an instance of a class. We will understand these concepts more deeply in upcoming blogs with help of programs. So, Stay tuned!
Difference Between POP And OOP:
POP revolves around functions, OOP revolves around objects. POP provides no restriction to access some data but OOP provides restriction using an access specifier. In POP, data and functions are not binded at the same place but in OOP, data and methods are binded. OOP is a good approach for the maintenance of complex programs/software.