OOPS Using C++
OOPS Using C++
(Established vide Uttaranchal University Act, 2012, Uttarakhand Act No. 11 of 2013)
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:
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:
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
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.
Abstraction:
Procedural Approach:
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):
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:
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
8
Differences and Comparisons:
Code Structure:
Modularity:
Code Reusability:
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:
Flexibility:
10
of unintended consequences and higher coupling between different parts
of the codebase, reducing flexibility.
Maintenance Ease:
Differences:
12