0% found this document useful (0 votes)
107 views12 pages

OOPS Using C++

Uploaded by

Rishu Jaryal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views12 pages

OOPS Using C++

Uploaded by

Rishu Jaryal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

UTTARANCHAL UNIVERSITY

(Established vide Uttaranchal University Act, 2012, Uttarakhand Act No. 11 of 2013)

Premnagar-248007, Dehradun, Uttarakhand, INDIA

ASSIGNMENT COVER PAGE

Name of Student:
Rishabh Jaryal
July 23 Batch
Batch:

Program:
MCA
OOPS using C++
Subject & Code:
1st
Semester:
2316010325
Learner ID:

NECESSARY INSTRUCTIONS
1. Cover Page must be filled in Capital Letters. All Fields of
the Form are compulsory to be filled.
2. The assignment should be written / computer typed on A4 size paper and it
should be neat and clearly readable.
3. The cover page should be stapled at the front of each and every assignment.
4. Incomplete Assignments will not be accepted.

1
Comparative Analysis of Object-Oriented and
Procedure-Oriented Programming Paradigms: -
Object-Oriented Programming (OOP) and Procedure-Oriented Programming
(POP) are two paradigms in software development:

(1) Procedure-Oriented Programming (POP):

● Focus: Organizes the program around functions or procedures.


● Key Characteristics: Emphasizes step-by-step procedure execution, using
functions to manipulate data.
● Significance: It's straightforward and easy to understand for small-scale
programs but can become complex and harder to maintain as the
codebase grows.

(2) Object-Oriented Programming (OOP):

2
● Focus: Organizes the program around objects that encapsulate data and
behaviour.
● Key Characteristics: Encourages the use of classes, objects, inheritance,
and polymorphism.
● Significance: Offers modularity, reusability, and scalability. It enables
better structuring of code, making it easier to manage, maintain, and
extend.

In essence, OOP provides a more organized and manageable way to structure complex
applications compared to POP, due to its focus on encapsulation, inheritance, and
polymorphism.

Object-Oriented Programming
3
Principles of OOP:

Encapsulation: Encapsulation involves bundling data (attributes) and methods


(functions) that operate on the data within a single unit (class). It hides the
internal state of an object from the outside, allowing controlled access only
through defined interfaces.
Inheritance: Inheritance allows a class (subclass) to inherit properties and
behaviour from another class (superclass). It promotes code reusability and
establishes a hierarchical relationship between classes.
Polymorphism: Polymorphism refers to the ability of objects to take on multiple
forms. It allows objects of different classes to be treated as objects of a common
superclass, enabling flexibility and extensibility in code.
Abstraction: Abstraction focuses on hiding complex implementation details and
presenting only essential features of an object. It simplifies the usage of objects
by providing a clear and concise interface.

Objects and Classes:

In OOP, a class serves as a blueprint or template that defines the structure and
behaviour of objects. Objects, on the other hand, are instances of classes, representing
specific entities with distinct attributes (data) and behaviours (methods).

Real-life Analogy:

Consider a car as an object. It has properties (attributes) such as color, model, and
horsepower, and behaviours (methods) like accelerating, braking, and turning. In this
analogy:

4
Class "Car" (Coding Example in Python):

Here, the Car class defines the blueprint for creating car objects. Attributes like color,
model, and horsepower represent the properties of a car, while methods like accelerate,
brake, and turn represent its behaviours.

Creating an object from this class would involve specifying values for these attributes,
allowing the instance to exhibit the defined behaviours. For instance

This code snippet creates an instance my car of the Car class with specific properties

and invokes its accelerate method to simulate the car's acceleration.

Encapsulation:

5
Data hiding in encapsulation refers to the idea of restricting access to certain
components within an object, allowing only designated methods or functions to
access and manipulate that data. Objects encapsulate both data (attributes) and
behaviours (methods) within a single unit, ensuring data integrity and providing
a clear interface for interaction with the object.
Inheritance: Inheritance allows a new class (subclass) to inherit properties and
behaviour (attributes and methods) from an existing class (superclass). This
feature promotes code reusability, where the subclass can access and extend the
functionalities of the superclass, inheriting its characteristics while also adding
its unique attributes or behaviours.

Polymorphism: Polymorphism allows objects to take many forms or have different


behaviours based on the context. This is achieved through two main methods:
● Overloading: In some languages, overloading enables multiple methods
with the same name but different parameters or signatures within a class.
The appropriate method is invoked based on the parameters passed.
● Overriding: Overriding involves providing a new implementation for a
method in the subclass that already exists in the superclass. This allows
objects of different classes to be treated as objects of a common
superclass but behave differently based on their specific class.

Abstraction:

Abstraction involves simplifying complex implementations by providing a clear and


concise interface. It allows programmers to focus on essential functionalities
while hiding unnecessary details. By abstracting away complex internal
workings, it becomes easier to work with objects and use their functionalities
without needing to understand the underlying complexities.

Procedural Approach:

In procedural programming, the focus is on the linear execution of code through


procedures or functions. Programs are structured as a series of steps that are executed
sequentially, and these steps are often encapsulated within functions or procedures.

Use of Functions:

Functions play a crucial role in procedural programming by breaking down the program
into smaller, reusable chunks of code. They encapsulate specific tasks or operations,
promoting code reusability and modularity.

6
Example (C Programming):

Here's a simple example in C that demonstrates a procedural approach using functions


to perform specific tasks, such as calculating the area and perimeter of a rectangle:

7
In this example, the calculate Area and calculate Perimeter functions are responsible for
computing the area and perimeter of a rectangle based on the given length and width.
The main function demonstrates how these functions are called to perform specific
tasks, encapsulating the logic for area and perimeter calculations within their respective
functions.

Focus on Functions:

In Procedure-Oriented Programming (POP), breaking down tasks into smaller


functions is crucial. This approach emphasises dividing the program into
manageable chunks by encapsulating specific operations or procedures within
functions. By doing so, it enhances readability, simplifies debugging, and
promotes a structured approach to solving problems.

Data and Procedures Separation:

POP maintains a separation between data and procedures. Functions primarily


manipulate data passed to them as parameters. However, these functions are
distinct from the data they operate on. Data is often stored in global variables or
passed explicitly between functions, and procedures act upon this data without
being directly associated with it. This separation can lead to potential issues like
accidental data manipulation.

Limited Reusability:

In POP, due to the lack of strong modularity, code reusability is limited. Functions
are specific to tasks and are not easily reusable across different parts of the
program. As a result, if a similar operation needs to be performed in multiple
places, the s

ame code might need to be replicated, leading to redundancy and making


maintenance more cumbersome. The absence of clear modular structures can
hinder the scalability and maintainability of the codebase.

8
Differences and Comparisons:

Code Structure:

Modularity:

● OOP (Objects): OOP promotes a modular structure through objects, where


data and behaviour are encapsulated within objects. Objects are self-
contained units that interact with each other through well-defined
interfaces. This modular approach allows for better organisation, ease of
maintenance, and scalability of the codebase.
● POP (Functions): POP follows a more linear structure, where code is
organised around functions or procedures. While functions break down
tasks into smaller units, the overall structure tends to be less modular
compared to OOP. Functions often manipulate shared global data, leading
to potential complexities in managing dependencies.

Code Reusability:

● OOP (Inheritance): OOP facilitates high code reusability through


inheritance. Inheritance allows classes (subclasses) to inherit properties
and behaviours from other classes (superclasses). This promotes the
reuse of code by extending existing classes, reducing redundancy, and
enhancing maintainability.
● POP: In contrast, POP typically has limited code reusability. Functions in
procedural programming are specific to particular tasks and aren't
inherently designed for reuse across different parts of the program. As a
result, code duplication is more common in POP, making it harder to
maintain and update the codebase.

Abstraction and Encapsulation:

Level of Abstraction:

9
● OOP (High-Level Abstraction): OOP facilitates high-level abstraction
through interfaces. Interfaces in OOP define a set of methods that a class
must implement, allowing for abstraction of implementation details. This
enables loose coupling between components and hides complexities by
focusing on essential functionalities.
● POP (Limited Abstraction): In POP, abstraction tends to be more limited.
While functions can abstract specific tasks, the overall level of abstraction
in managing complex systems or interactions between different parts of
the program is less pronounced compared to OOP's interface-based
abstractions.

Data Encapsulation:

● OOP (Encapsulation within Objects): OOP strongly emphasizes


encapsulating data within objects. Objects encapsulate both data
(attributes) and behaviour (methods), controlling access to data through
methods and access modifiers (like private, public, protected). This
safeguards data integrity and allows for controlled manipulation of data.
● POP (Absence of Encapsulation): In POP, there's a lack of inherent data
encapsulation. Data and functions are often treated separately, with
functions operating on shared global data. There's no inherent
mechanism to enforce encapsulation or to restrict access to data within
functions, potentially leading to data integrity issues.

Flexibility and Maintenance:

Flexibility:

● OOP: Offers greater flexibility due to features like inheritance,


polymorphism, and encapsulation. Inheritance allows for easy
modifications and extensions by deriving new classes from existing ones.
Polymorphism enables objects to be treated as instances of their parent
classes, allowing for interchangeable use. Encapsulation ensures that
changes to the internal workings of an object don't affect other parts of
the program.
● POP: Tends to be more rigid when adapting to changes. As functions are
more linear and interconnected, modifications or additions might require
altering multiple sections of the code. This can lead to increased chances

10
of unintended consequences and higher coupling between different parts
of the codebase, reducing flexibility.

Maintenance Ease:

● OOP: Generally, offers easier maintenance due to its modular and


organized structure. Objects encapsulate their own data and behavior,
making it easier to isolate and troubleshoot issues. Additionally, the use of
inheritance and interfaces promotes code reuse and reduces redundancy,
simplifying updates and modifications.
● POP: Maintenance in POP can be more challenging. The linear structure
and lack of strong modularity can make it harder to isolate issues.
Changes might require extensive modifications across multiple functions,
potentially leading to errors or unintended side effects. The absence of
clear modular structures can hinder the ease of maintaining and updating
the codebase.

Differences between OOP and POP:

Differences:

● Approach: OOP focuses on objects, emphasizing encapsulation, inheritance,


polymorphism, and abstraction. POP revolves around procedures or functions,
with a linear execution flow.
● Structure: OOP offers a modular structure with objects encapsulating data and
behaviour, promoting organization and scalability. POP tends to have a more
linear structure, potentially leading to spaghetti code as the program grows.
● Advantages: OOP provides code reusability through inheritance, better
maintainability with encapsulation, and flexibility via polymorphism. POP is
straightforward for smaller programs but can become complex and harder to
maintain as the codebase grows.

Significance of Choosing Paradigm:

● Project Requirements: Choosing the right paradigm depends on project needs.


OOP suits larger, complex projects where modularity, maintainability, and code
reusability are crucial. POP might be suitable for smaller projects with
straightforward logic and limited scalability requirements.
● Complexity Consideration: The choice should align with project complexity.
OOP's structured approach helps manage complexity well, whereas POP might
struggle with scalability and maintenance in complex systems.
11
Selecting the paradigm that best aligns with project requirements and complexity is
crucial for achieving maintainable, scalable, and efficient software development. The
choice should consider factors like project size, complexity, maintainability, and long-
term scalability.

12

You might also like