KEMBAR78
C++ Unit - 1 | PDF | Object Oriented Programming | Class (Computer Programming)
0% found this document useful (0 votes)
21 views11 pages

C++ Unit - 1

The document discusses Procedure-Oriented Programming (POP) and Object-Oriented Programming (OOP), highlighting their features, advantages, and disadvantages. POP focuses on procedures and functions, while OOP emphasizes objects that encapsulate data and behavior, promoting code reusability and easier maintenance. Key concepts of OOP include classes, objects, inheritance, polymorphism, abstraction, encapsulation, dynamic binding, and message passing.

Uploaded by

jaynthir01
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)
21 views11 pages

C++ Unit - 1

The document discusses Procedure-Oriented Programming (POP) and Object-Oriented Programming (OOP), highlighting their features, advantages, and disadvantages. POP focuses on procedures and functions, while OOP emphasizes objects that encapsulate data and behavior, promoting code reusability and easier maintenance. Key concepts of OOP include classes, objects, inheritance, polymorphism, abstraction, encapsulation, dynamic binding, and message passing.

Uploaded by

jaynthir01
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/ 11

UNIT - 1

Procedure-oriented programming (POP)


Procedure-oriented programming is a programming model that uses a set
of procedures, or subroutines, to solve problems. The procedures are
executed in a specific order.

 The given problem is divided into number of sub problems depending


upon its functionality.
 The sub problems are called Procedures or Methods.
 Any procedure can be called at any point during the program execution.
 The program has global and local variables.
 Global variables can be only be used.

Features of Procedural Programming Language


 Local Variables: A local variable is a variable that is limited to a
specific part of a program and is announced locally in the procedural
language, local on the specific function, as the only place to access it.
 Global Variables: A global variable is a variable that is declared
outside a function and is able to be accessed by any function of the
program. It is also known as the opposite of the local variable.
 Modularity: The practice of splitting a program into modules or
functions so that each function is devoted to a certain task is referred
to as modularity.
 Pre-Defined Functions: Pre-defined functions are the amplification of
functions which are already defined by the user and don't need the
programmer to define them again. A built-in function is already defined
in the system libraries, so it is also called a library function.
 Parameter Passing: Parameter passing is a mechanism that allows
the transfer of data between different functions of the program. The
parameters are passed between the called and the calling function,
thus allowing data exchange.

Advantage of Procedural Languages


There are various advantages of Procedural Languages, which are given below:

o The program of Procedural Programming language forwardness


apace with the utilization of interpreters and accumulators.
o This language clarifies the source code and can be understood
easily.
o Without the need for copying this, the code may reuse in various
piece of code.
o For various purposes, the Procedural Programming language
utilizes different parts of memory.
o There are multiple General-Purpose programming languages,
which support it.
o It makes it easy to track as it flows the program in a linear
direction.

Disadvantages of Procedural Languages


o When Procedural languages are employed, its program is harder
to write.
o Also, with a real-world problem, this language is not very practical.
o It builds less safety inviting because the information is available to
the whole code.
o It can form a complex program as it has the potential to solve real-
world problems.
o The information is vulnerable in this, and it is not practicable with a
true issue.
OBJECT ORIENTED PROGRAMMING :

OOP stands for Object-Oriented Programming.

Procedural programming is about writing procedures or functions that


perform operations on the data, while object-oriented programming is
about creating objects that contain both data and functions.

Object-oriented programming has several advantages over procedural


programming:

 OOP is faster and easier to execute


 OOP provides a clear structure for the programs
 OOP helps to keep the C++ code easier to maintain, modify and
debug
 OOP makes it possible to create full reusable applications with
less code and shorter development time.

The main aim of OOP is to bind together the data and the functions
that operate on them so that no other part of the code can access
this data except that function.

OOP Paradigm:
The program is divided into number of small units called objects.
The data and function are built around these objects.
The data of the objects can be accessed only by the functions
associated with that object.
The functions of one object can access the functions of other object.
Features of OOPs:
 Emphasis is on data rather than procedure (function).
 Programs are divided into objects.
 Functions that operate on the data of an object are ties together in the
data structure.
 Data is hidden and cannot be accessed by external function.
 Objects may communicate with each other through function.
 New data and functions can be easily added whenever necessary.
 Follows bottom up approach in program design.

Differences Between OOP and POP:

 Structure: OOP emphasizes organizing code into reusable objects, while


POP structures code around procedures or functions.
 Data Manipulation: OOP focuses on manipulating data through objects with
defined behavior, whereas POP manipulates data through functions.
 Code Reusability: OOP facilitates code reusability through inheritance and
polymorphism, allowing objects to inherit properties and behaviors from other
objects. POP lacks such mechanisms.
 Encapsulation: OOP promotes encapsulation, where data and
 methods are bundled within an object, enhancing data security. POP does not
inherently enforce encapsulation.
 Complexity Management: OOP handles complex systems by breaking them
into smaller, manageable objects. POP may become unwieldy and difficult to
maintain as complexity increases.
Feature Object-Oriented Programming Procedural Programming
Key Focus Objects and their interactions Procedures and functions
Data Data and behavior are Data and behavior are separate
Management encapsulated in objects entities
Encourages the use of abstract
Abstraction Does not emphasize abstraction
classes and interfaces
Supports inheritance, allowing
Inheritance classes to inherit properties and Does not support inheritance
methods
Allows objects of different types Does not provide inherent
Polymorphism
to be treated as the same type polymorphism
High level of code reusability
Relies on functions and
Code Reusability through inheritance and
subroutines for code reusability
composition
Follows a modular approach,
Code Relies on functions and
with objects as self-contained
Organization procedures for code organization
modules
Provides flexibility through Relies on structured
Flexibility polymorphism and dynamic programming, offering less
binding flexibility
Encourages managing Manages complexity through
Complexity
complexity through modular code organization and
Management
encapsulation and abstraction stepwise design
Well-suited for modeling real- May not align well with real-world
Real-World
world entities and their modeling, focusing more on
Modeling
interactions processes
Basic OOP Concepts in C++
The concept of OOPs in C++ programming language is based on eight major
pillars which are

1. Class
2. Object
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation
7. Dynamic Binding
8. Message Passing

1.) Class
A class in C++ is one of the fundamental concepts in Object-Oriented
Programming (OOP). It acts as a blueprint or a template for creating objects,
which represent real-world entities. A class encapsulates data members
(attributes) and member functions (methods) that operate on the data,
providing a way to model complex systems.

A class is like a blueprint for an object.


For Example: Consider the Class of Cars. There may be many cars with
different names and brands but all of them will share some common
properties like all of them will have 4 wheels, Speed Limit, Mileage range,
etc. So here, the Car is the class, and wheels, speed limits, and mileage
are their properties.

2. Object
It is a basic unit of Object-Oriented Programming and represents the real-
life entities. An Object is an instance of a Class. When a class is defined,
no memory is allocated but when it is instantiated (i.e. an object is
created) memory is allocated. An object has an identity, state, and
behavior. Each object contains data and code to manipulate the data.
Objects can interact without having to know details of each other’s data or
code, it is sufficient to know the type of message accepted and type of
response returned by the objects.
For example “Dog” is a real-life Object, which has some characteristics
like color, Breed, Bark, Sleep, and Eats.
3. Inheritance:
Inheritance is an important pillar of OOP(Object-
Oriented Programming). The capability of a class to
derive properties and characteristics from another class
is called Inheritance. When we write a class, we inherit
properties from other classes. So when we create a
class, we do not need to write all the properties and
functions again and again, as these can be inherited
from another class that possesses it. Inheritance allows
the user to reuse the code whenever possible and
reduce its redundancy.
4. Polymorphism:
The word polymorphism means having many forms. In simple words, we
can define polymorphism as the ability of a message to be displayed in
more than one form. For example, A person at the same time can have
different characteristics. Like a man at the same time is a father, a
husband, an employee. So the same person posses different behavior in
different situations. This is called polymorphism.

5. Data Abstraction:
Data abstraction is one of the most essential and important features of
object-oriented programming. Data abstraction refers to providing only
essential information about the data to the outside world, hiding the
background details or implementation. Consider a real-life example of a
man driving a car. The man only knows that pressing the accelerators will
increase the speed of the car or applying brakes will stop the car, but he
does not know about how on pressing the accelerator the speed is
increasing, he does not know about the inner mechanism of the car or the
implementation of the accelerator, brakes, etc in the car. This is what
abstraction is.

6. Encapsulation:
Encapsulation is defined as the wrapping up of data under a single unit. It
is the mechanism that binds together code and the data it manipulates. In
Encapsulation, the variables or data of a class are hidden from any other
class and can be accessed only through any member function of their
class in which they are declared. As in encapsulation, the data in a class
is hidden from other classes, so it is also known as data-hiding.
Consider a real-life example of encapsulation, in a company, there are
different sections like the accounts section, finance section, sales section,
etc. The finance section handles all the financial transactions and keeps
records of all the data related to finance. Similarly, the sales section
handles all the sales-related activities and keeps records of all the sales.
Now there may arise a situation when for some reason an official from the
finance section needs all the data about sales in a particular month. In this
case, he is not allowed to directly access the data of the sales section. He
will first have to contact some other officer in the sales section and then
request him to give the particular data. This is what encapsulation is. Here
the data of the sales section and the employees that can manipulate them
are wrapped under a single name “sales section”.

7. Dynamic Binding:
In dynamic binding, the code to be executed in response to the function
call is decided at runtime. Dynamic binding means that the code
associated with a given procedure call is not known until the time of the
call at run time. Dynamic Method Binding One of the main advantages of
inheritance is that some derived class D has all the members of its base
class B. Once D is not hiding any of the public members of B, then an
object of D can represent B in any context where a B could be used. This
feature is known as subtype polymorphism.

8. Message Passing:
It is a form of communication used in object-oriented programming as well
as parallel programming. Objects communicate with one another by
sending and receiving information to each other. A message for an object
is a request for execution of a procedure and therefore will invoke a
function in the receiving object that generates the desired results.
Message passing involves specifying the name of the object, the name of
the function, and the information to be sent.

You might also like