SlideShare a Scribd company logo
5
Most read
7
Most read
11
Most read
Encapsulation C++
Object Oriented
Programming
Encapsulation
Group Members:
 Oman Mahmood
 Abdul Rehman
 Basit Ali
Objectives:
 What is Encapsulation?
 Why Encapsulation?
 Syntax
 Example
 Advantages and achievements
What is Encapsulation?
 "A language mechanism for restricting access to some of
the object's components"
 Encapsulation is the process of combining data and
functions into a single unit called class.
 Data is only accessible through the functions present
inside the class.
What is Encapsulation?
 Hiding the implementation details and providing
restrictive access leads to the concept of abstract data
type.
 Data encapsulation led to the important concept of data
hiding.
Why Encapsulation?
 "It gives us secure and consistence results".
Means that it gives the user access to a limited data and
keeps our valuable data which can change our program or
increase the possibilities of mistakes hidden from the
user.
 We can understand this more by this example:
Assume we made a Rectangle class that contained four
variables - length, width, area, and perimeter.
Why Encapsulation?
 Please note that area and perimeter are derived from
length and width, so that changing length would change
both area and perimeter. If you did not use proper
information hiding (encapsulation), then another
program utilizing that Rectangle class could alter the
length without altering the area, and you would have an
inconsistent Rectangle..
Why Encapsulation?
 Using encapsulation, we can create a function that, if a
program wanted to change the length of the rectangle,
that the object would appropriately update its area and
perimeter without being inconsistent.
 The ideal is to keep as many of the details of each class
hidden from all other classes as possible.
Syntax:
 The syntax of encapsulation is very easy, for
encapsulation we have to declare a class and then we
have to mark or tell in our program which data we want
to show and which we want to hide.
class Box
{
public:
double getVolume(void)
Syntax:
{
return length * breadth * height;
}
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
Example:
 We can understand it more by a C++ program
#include <iostream>
#include<stdlib.h>
using namespace std;
class Adder{
public:
Adder(int i = 0)
Example:
{
total = i;
}
// interface to outside world
void addNum(int number)
{
total += number;
}
int getTotal()
Example:
{
return total;
};
private: // This keeps our data hidden from the world
int total;
};
int main( )
{
systam("color A");
Adder a;
Example:
a.addNum(10);
a.addNum(20);
a.addNum(30);
cout << "Total " << a.getTotal() <<endl;
return 0;
}
Example:
 When the above code is compiled and executed, it
produces the following result :
Result is 60.
Advantages and Achievements
 Makes Maintenance of Application Easier.
 Improves the Understandability of the Application
 Enhanced Security

More Related Content

PPTX
[OOP - Lec 08] Encapsulation (Information Hiding)
PPTX
encapsulation
PPTX
Encapsulation
PPTX
Encapsulation
PDF
Chapter2 Encapsulation (Java)
PDF
Access specifiers (Public Private Protected) C++
PPTX
OOPS Basics With Example
PPTX
This pointer
[OOP - Lec 08] Encapsulation (Information Hiding)
encapsulation
Encapsulation
Encapsulation
Chapter2 Encapsulation (Java)
Access specifiers (Public Private Protected) C++
OOPS Basics With Example
This pointer

What's hot (20)

PPTX
Data types in c++
PPTX
Chapter 07 inheritance
PPTX
virtual function
PPT
friend function(c++)
PPTX
Method overloading
PPTX
Data types in java
PPT
Function overloading(c++)
PPTX
PPT
Method overriding
PPTX
Oop c++class(final).ppt
PPTX
Java package
PPTX
The string class
PPTX
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
PPTX
Exception handling
PPTX
Interface in java
PPTX
Abstract class in c++
PPTX
Inheritance in JAVA PPT
PPTX
Inline function
PPTX
Friend function
PPTX
Access modifiers in java
Data types in c++
Chapter 07 inheritance
virtual function
friend function(c++)
Method overloading
Data types in java
Function overloading(c++)
Method overriding
Oop c++class(final).ppt
Java package
The string class
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
Exception handling
Interface in java
Abstract class in c++
Inheritance in JAVA PPT
Inline function
Friend function
Access modifiers in java
Ad

Similar to Encapsulation C++ (20)

PPTX
Presen5416846534653416354165341864adeadvdes
PPTX
Prese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptx
PPTX
Prese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptx
PPTX
Presentation related to Encapsulation and OOPs
PPTX
Presentation - Copy no vaperpoit asd.pptx
PPTX
Module 4 Effect of Reuse on using Encapsulation.pptx
PPTX
Presentation - 001jasfcjedhfuj5454545.pptx
PPTX
oop ppt.pptxfwefwefweqwedrqwerwerweewrewe
PPTX
ENCAPSULATION module for IT or comsci.pptx
PPTX
Encapsulation C++ Piller of OOP it is the important piller
PPTX
g3-encapsulation.pptxyyyyyyy66te5ujuuuyyt6
PPTX
g3-encapsulationhshshshshhshshhshshshshshh
PPTX
g3-encapsulation.pptxhhhhhhhsususuududjd
PPTX
g3-encapsulation.pptxgggggghyhftyhfyyghgh
DOCX
Benefits of encapsulation
PPTX
Encapsulation_in_CPP_Presentation.pptxesfwefrwefrwefwefeqweqweqweqweqweqwe
PPTX
cryptography
PPT
C# Encapsulation
PPTX
Encapsulation
PPT
C++Presentation 2.PPT
Presen5416846534653416354165341864adeadvdes
Prese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptx
Prese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptx
Presentation related to Encapsulation and OOPs
Presentation - Copy no vaperpoit asd.pptx
Module 4 Effect of Reuse on using Encapsulation.pptx
Presentation - 001jasfcjedhfuj5454545.pptx
oop ppt.pptxfwefwefweqwedrqwerwerweewrewe
ENCAPSULATION module for IT or comsci.pptx
Encapsulation C++ Piller of OOP it is the important piller
g3-encapsulation.pptxyyyyyyy66te5ujuuuyyt6
g3-encapsulationhshshshshhshshhshshshshshh
g3-encapsulation.pptxhhhhhhhsususuududjd
g3-encapsulation.pptxgggggghyhftyhfyyghgh
Benefits of encapsulation
Encapsulation_in_CPP_Presentation.pptxesfwefrwefrwefwefeqweqweqweqweqweqwe
cryptography
C# Encapsulation
Encapsulation
C++Presentation 2.PPT
Ad

Recently uploaded (20)

PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
history of c programming in notes for students .pptx
PPTX
Essential Infomation Tech presentation.pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
top salesforce developer skills in 2025.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Digital Strategies for Manufacturing Companies
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
System and Network Administration Chapter 2
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
history of c programming in notes for students .pptx
Essential Infomation Tech presentation.pptx
PTS Company Brochure 2025 (1).pdf.......
top salesforce developer skills in 2025.pdf
Understanding Forklifts - TECH EHS Solution
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Odoo Companies in India – Driving Business Transformation.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Upgrade and Innovation Strategies for SAP ERP Customers
Wondershare Filmora 15 Crack With Activation Key [2025
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Internet Downloader Manager (IDM) Crack 6.42 Build 41
wealthsignaloriginal-com-DS-text-... (1).pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Digital Strategies for Manufacturing Companies
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
System and Network Administration Chapter 2

Encapsulation C++

  • 3. Group Members:  Oman Mahmood  Abdul Rehman  Basit Ali
  • 4. Objectives:  What is Encapsulation?  Why Encapsulation?  Syntax  Example  Advantages and achievements
  • 5. What is Encapsulation?  "A language mechanism for restricting access to some of the object's components"  Encapsulation is the process of combining data and functions into a single unit called class.  Data is only accessible through the functions present inside the class.
  • 6. What is Encapsulation?  Hiding the implementation details and providing restrictive access leads to the concept of abstract data type.  Data encapsulation led to the important concept of data hiding.
  • 7. Why Encapsulation?  "It gives us secure and consistence results". Means that it gives the user access to a limited data and keeps our valuable data which can change our program or increase the possibilities of mistakes hidden from the user.  We can understand this more by this example: Assume we made a Rectangle class that contained four variables - length, width, area, and perimeter.
  • 8. Why Encapsulation?  Please note that area and perimeter are derived from length and width, so that changing length would change both area and perimeter. If you did not use proper information hiding (encapsulation), then another program utilizing that Rectangle class could alter the length without altering the area, and you would have an inconsistent Rectangle..
  • 9. Why Encapsulation?  Using encapsulation, we can create a function that, if a program wanted to change the length of the rectangle, that the object would appropriately update its area and perimeter without being inconsistent.  The ideal is to keep as many of the details of each class hidden from all other classes as possible.
  • 10. Syntax:  The syntax of encapsulation is very easy, for encapsulation we have to declare a class and then we have to mark or tell in our program which data we want to show and which we want to hide. class Box { public: double getVolume(void)
  • 11. Syntax: { return length * breadth * height; } private: double length; // Length of a box double breadth; // Breadth of a box double height; // Height of a box };
  • 12. Example:  We can understand it more by a C++ program #include <iostream> #include<stdlib.h> using namespace std; class Adder{ public: Adder(int i = 0)
  • 13. Example: { total = i; } // interface to outside world void addNum(int number) { total += number; } int getTotal()
  • 14. Example: { return total; }; private: // This keeps our data hidden from the world int total; }; int main( ) { systam("color A"); Adder a;
  • 16. Example:  When the above code is compiled and executed, it produces the following result : Result is 60.
  • 17. Advantages and Achievements  Makes Maintenance of Application Easier.  Improves the Understandability of the Application  Enhanced Security