SlideShare uma empresa Scribd logo
1 de 14
DATA ABSTRACTION
(with examples) …
Presented by :-
Manav Sharma
Kanika Behl
Kartik Gupta
Data Abstraction in C++ …
 Data Abstraction is a process of providing only the essential details to
the outside world and hiding the internal details, i.e., representing only
the essential details in the program.
 Data Abstraction is a programming technique that depends on the
separation of the interface and implementation details of the program.
 C++ provides a great level of Abstraction.
 For example, pow() function is used to calculate the power of a number
without knowing the algorithm the function follows.
 Consider one real life example of a TV, which you can turn on and off, change the channel,
adjust the volume, and add external components such as speakers, VCRs, and DVD
players, But you do not know its internal details, that is, you do not know how it receives
signals over the air or through a cable, how it translates them, and finally displays them on
the screen.
Thus, we can say a television clearly separates its internal implementation from its external
interface and you can play with its interfaces like the power button, channel changer, and
volume control without having any knowledge of its internals.
 C++ provides great level of data abstraction. It provides sufficient public methods to the
outside world to play with the functionality of the object and to manipulate object data, i.e.,
state without actually knowing how class has been implemented internally.
 In C++, we use classes to define our own abstract data types (ADT). You can use the cout object
of class ostream to stream data to standard output like this −
#include< iostream> output :-
using namespace std ; Hello C++
int main( )
{
cout << “ Hello C++ “ << endl ;
Return 0 ;
}
Here, you don't need to understand how cout displays the text on the user's screen. You need to only
know the public interface and the underlying implementation of ‘cout ’ is free to change.
 C++ classes use the technique of abstraction and are defined
as a list of abstract attributes and functions to operates on
them.
 The Attributes which holds all the information about the
properties of the object required to form are called data
members.
 The functions which operates on Data Members are called
Member Functions.
 Access specifiers are used to Implement Abstraction.
Access Specifiers in C++
 Access specifiers define how the members (attributes and methods) of a
class can be accessed.
 Access Specifiers Implement Abstraction:
• Public specifier: When the members are declared as public members can be
accessed anywhere from the program.
• Protected Specifier : members cannot be accessed from outside the class,
however, they can be accessed in inherited classes.
• Private specifier: When the members are declared as private members can
only be accessed only by the member functions of the class.
 Data Abstraction can be achieved in two ways:
• Abstraction using classes
• Abstraction in header files.
Abstraction using Classes
#include<iostream>
using namespace std; Output :-
class Sum {
Enter two numbers :
private : int x , y, x; 3
public : 6
void add( ) { Sum of two numbers is : 9
cout << “ Enter two numbers : “ ;
cin >> x >> y ;
z= x + y ;
cout<<“ Sum of two numbers is : “ << z << endl ;
}
} ;
int main ()
{
Sum sm;
sm.add();
return 0 ;
}
Abstraction in Header Files
// Program to print power of a number :
#include<iostream.h> Output :-
#include<math.h>
Using namespace std ; The Value is : 81
int main( ) {
int x = 3 ;
int power = 4;
int result = pow( x, power) ;
cout <<“ The Value is : “ << result << endl ;
return 0 ;
}
Types of Abstraction..
 There are 2 types of abstraction :-
1. Data Abstraction
Hiding the details about the data is called data abstraction.
2. Control Abstraction
Hiding the details about the implementation is called control abstraction.
Advantages of Abstraction..
 Increases reusability of the code.
 Avoids duplication of your code.
 Makes the application secure by not allowing anyone else to see the
background details.
 A programmer does not need to write the low level code.
 Internal implementation can be changed without affecting the user
level code.
Designing Strategy
 Abstraction separates code into interface and implementation.
 So while designing your component, you must keep interface independent of the
implementation so that if you change underlying implementation then interface
would remain intact.
In this case whatever programs are using these interfaces, they would not be
impacted and would just need a recompilation with the latest implementation.
Q/A Session ..
DATA ABSTRACTION.pptx

Mais conteúdo relacionado

Semelhante a DATA ABSTRACTION.pptx

Semelhante a DATA ABSTRACTION.pptx (20)

C++
C++C++
C++
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Programming in c
Programming in cProgramming in c
Programming in c
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Managing console input
Managing console inputManaging console input
Managing console input
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
c.ppt
c.pptc.ppt
c.ppt
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
01_intro-cpp.ppt
01_intro-cpp.ppt01_intro-cpp.ppt
01_intro-cpp.ppt
 
01_intro-cpp.ppt
01_intro-cpp.ppt01_intro-cpp.ppt
01_intro-cpp.ppt
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Pointer
PointerPointer
Pointer
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
C++ language
C++ languageC++ language
C++ language
 

Último

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Último (20)

DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 

DATA ABSTRACTION.pptx

  • 1. DATA ABSTRACTION (with examples) … Presented by :- Manav Sharma Kanika Behl Kartik Gupta
  • 2. Data Abstraction in C++ …  Data Abstraction is a process of providing only the essential details to the outside world and hiding the internal details, i.e., representing only the essential details in the program.  Data Abstraction is a programming technique that depends on the separation of the interface and implementation details of the program.  C++ provides a great level of Abstraction.  For example, pow() function is used to calculate the power of a number without knowing the algorithm the function follows.
  • 3.  Consider one real life example of a TV, which you can turn on and off, change the channel, adjust the volume, and add external components such as speakers, VCRs, and DVD players, But you do not know its internal details, that is, you do not know how it receives signals over the air or through a cable, how it translates them, and finally displays them on the screen. Thus, we can say a television clearly separates its internal implementation from its external interface and you can play with its interfaces like the power button, channel changer, and volume control without having any knowledge of its internals.  C++ provides great level of data abstraction. It provides sufficient public methods to the outside world to play with the functionality of the object and to manipulate object data, i.e., state without actually knowing how class has been implemented internally.
  • 4.  In C++, we use classes to define our own abstract data types (ADT). You can use the cout object of class ostream to stream data to standard output like this − #include< iostream> output :- using namespace std ; Hello C++ int main( ) { cout << “ Hello C++ “ << endl ; Return 0 ; } Here, you don't need to understand how cout displays the text on the user's screen. You need to only know the public interface and the underlying implementation of ‘cout ’ is free to change.
  • 5.  C++ classes use the technique of abstraction and are defined as a list of abstract attributes and functions to operates on them.  The Attributes which holds all the information about the properties of the object required to form are called data members.  The functions which operates on Data Members are called Member Functions.  Access specifiers are used to Implement Abstraction.
  • 6. Access Specifiers in C++  Access specifiers define how the members (attributes and methods) of a class can be accessed.  Access Specifiers Implement Abstraction: • Public specifier: When the members are declared as public members can be accessed anywhere from the program. • Protected Specifier : members cannot be accessed from outside the class, however, they can be accessed in inherited classes. • Private specifier: When the members are declared as private members can only be accessed only by the member functions of the class.
  • 7.  Data Abstraction can be achieved in two ways: • Abstraction using classes • Abstraction in header files.
  • 8. Abstraction using Classes #include<iostream> using namespace std; Output :- class Sum { Enter two numbers : private : int x , y, x; 3 public : 6 void add( ) { Sum of two numbers is : 9 cout << “ Enter two numbers : “ ; cin >> x >> y ; z= x + y ; cout<<“ Sum of two numbers is : “ << z << endl ; } } ; int main () { Sum sm; sm.add(); return 0 ; }
  • 9. Abstraction in Header Files // Program to print power of a number : #include<iostream.h> Output :- #include<math.h> Using namespace std ; The Value is : 81 int main( ) { int x = 3 ; int power = 4; int result = pow( x, power) ; cout <<“ The Value is : “ << result << endl ; return 0 ; }
  • 10. Types of Abstraction..  There are 2 types of abstraction :- 1. Data Abstraction Hiding the details about the data is called data abstraction. 2. Control Abstraction Hiding the details about the implementation is called control abstraction.
  • 11. Advantages of Abstraction..  Increases reusability of the code.  Avoids duplication of your code.  Makes the application secure by not allowing anyone else to see the background details.  A programmer does not need to write the low level code.  Internal implementation can be changed without affecting the user level code.
  • 12. Designing Strategy  Abstraction separates code into interface and implementation.  So while designing your component, you must keep interface independent of the implementation so that if you change underlying implementation then interface would remain intact. In this case whatever programs are using these interfaces, they would not be impacted and would just need a recompilation with the latest implementation.