Explain the differences between procedural programming and object oriented programming with the help of one example program of each.
Procedural programming and object-oriented programming (OOP) are two fundamental programming paradigms used in software development, each with its own approach to organizing and structuring code.
Procedural programming is based on the concept of procedure calls, where a program is divided into functions or procedures that perform operations on data. It follows a top-down approach, focusing on the sequence of actions or instructions that the program executes. Data and functions are separate entities in procedural programming. The main idea is to write a set of instructions that the computer follows step-by-step to solve a problem.
In contrast, object-oriented programming organizes a program around objects, which are instances of classes. A class is like a blueprint that defines properties (attributes) and behaviors (methods) for objects. OOP emphasizes encapsulation, inheritance, and polymorphism. Encapsulation means that data and methods are bundled together inside objects, protecting the internal state of the object. Inheritance allows a new class to inherit properties and methods from an existing class, promoting code reuse. Polymorphism allows objects of different classes to be treated as objects of a common superclass, making the program more flexible.
### Example of Procedural Programming
Below is a simple procedural program in C language that calculates the area of a rectangle:
```c
#include <stdio.h>
float calculateArea(float length, float width) {
return length * width;
}
int main() {
float length, width, area;
printf("Enter length of rectangle: ");
scanf("%f", &length);
printf("Enter width of rectangle: ");
scanf("%f", &width);
area = calculateArea(length,
______ ___ _____ _____ ________ ___.
_________ _________ ___ _______ ____ _________ __________ __________.
______ ________ ____ ____ _________ _______.
_________ ________ ______ _______ _____ _________ _____.
__________ ______ _____ _________ __________ _______ ____ ____ ___ ____ _______.
____ ___ _______ ________ ___ _________ _____ ____ ________ _________.
____ ______ __________ ______ ___ _________ ______ ____ __________ ____.
_________ ________ ________ _______ ____ __________ __________ __________ ___ ___.
_______ ________ ___ ____ ________ __________ _________.
_______ ________ ____ _____ _____ ____ _____ ___ ___ _________ __________ _________.
__________ _________ _______ ________ ___ _______ __________ ____ ____ _______ __________.
______ ______ ____ ____ ______ _______ ______.
___ __________ __________ __________ ______ ______ ______.
_____ _____ _______ _____ ________ ___ ______ ______.
____ ________ _________ ______ ____ __________ _____ _______ _____ _____ ______ ____.
_______ __________ _____ __________ ____.
_______ ______ __________ _______ ______ ___ _________ _________ ________ ______ _________.
___ ________ ________ __________ _______ ___.
______ ________ ______ _______ __________ __________ _______ _______ __________.
_________ ______ ______ _____ ____ _________ ____ __________.
________ _______ ____ __________ ________ ___ _________ ____ _________ ___ ___ _________.
_____ _________ ____ ______ ________ ___ ____.
____ _______ _________ ________ ____ _______ __________ _____.
____ ____ ____ ____ _______ _____ _____ ____ ____ ___ _______ ____.
_______ _______ __________ _____ ______.
______ ___ _______ ___ ________ _____ _____ _________ _____ ____ _____ __________.
_____ ______ __________ _____ ____.
__________ __________ _________ _______ ________ _________.
________ _______ _____ ______ _______ ___ ______.
_____ ___ ________ ________ _____ ___ ____ ______ ___ ___ _______.
______ _______ __________ _______ ___ ___ _______ _____ ____ ________ _______ ________.
___ _______ ____ ______ _________ __________ _______.
___ ________ __________ _______ _________ ________ ________ __________ ____.
______ ________ ___ _________ ___ _____ ____ _________ ____ _________.
_____ ____ ___ _________ ________ ______ __________ _________ _________ _______ ____ ____.
___ _____ _______ _____ __________ ____ _________ __________ ________ _____.
___ _______ ________ ____ _______ _____ ________ _____ ____ _____.
________ ________ __________ ______ _________ _______ __________ ______ ____.
________ ___ _____ ______ _________ ____ ______.
__________ ____ _________ ___ _______ ________ _________ ___.
__________ ____ _____ ______ _________ ____ ___.
________ ____ ___ _______ ____ ___ ____.
__________ ______ ______ ___ ____ _____ _____ ______ _______ __________ __________.
__________ _____ __________ ____ ___ ______.
___ ____ ___ _______ __________ _______ ______ ________ _______ ______.
_________ ___ __________ __________ ________.
______ _________ __________ ___ ___ ___ _______ _______.
_________ ____ __________ _________ _______ ____ _________ ________.
____ _______ __________ ____ ________ _________ _______ _____ _____ _________ __________.
______ ____ __________ _____ ___ ______ _____ _________ __________ __________ __________.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required