- C++ Programming Basics
- C++ Tutorial
- C++ Environment Setup
- C++ Character Set
- C++ Keywords
- C++ Identifiers
- C++ Constants
- C++ Punctuators
- C++ Program Structure
- C++ Basic Syntax
- C++ Comments
- C++ Basic Programs
- C++ Input Output Operator
- C++ Input Output Stream
- C++ Type & Variable
- C++ Data Types
- C++ Data Type Modifiers
- C++ Variables
- C++ Variable Types
- C++ Variable Scope
- C++ Storage Classes
- C++ Formatting Output
- C++ Operators
- C++ Operators
- C++ Type Conversion
- C++ Numbers
- C++ Assignment Operator
- C++ Shorthand
- C++ Flow of Control
- C++ Statements
- C++ Flow Control
- C++ Decision Making
- C++ if if-else if-else-if switch
- C++ Loops
- C++ for while do-while Loop
- C++ break continue goto
- C++ Standard Library
- C++ Standard Library
- C++ Header Files
- C++ Character String
- C++ Mathematical Functions
- C++ Functions
- C++ Functions
- C++ Function Types
- C++ Function Prototype
- C++ Function Call
- C++ Function Return
- C++ Friend Function
- C++ Scope Rules
- C++ Arrays & Strings
- C++ Arrays
- C++ One Dimensional Arrays
- C++ Two Dimensional Arrays
- C++ Strings
- C++ Data Structure
- C++ Data Structure
- C++ Access Structure Member
- C++ Nested Data Structure
- C++ Structure Array
- C++ Pass Structure to Function
- C++ typedef
- C++ #define
- C++ Programming Pointers
- C++ Pointers
- C++ Memory Map
- C++ Free Store
- C++ Declare Initialize Pointers
- C++ Dynamic Memory Allocation
- C++ Pointers & Arrays
- C++ Pointers & Const
- C++ Pointers & Functions
- C++ Pointers & Structures
- C++ Objects as Function Arguments
- C++ Pointers & Objects
- C++ References
- C++ File Handling
- C++ File Handling
- C++ File Streams
- C++ Data Files
- C++ Opening & Closing Files
- C++ Steps to Process Files
- C++ Change Stream Behaviour
- C++ Sequential I/O Operations
- C++ Detecting EOF
- C++ File Pointers Random Access
- C++ Binary Files Operations
- C++ Error Handling
- C++ Object Oriented
- C++ Object Oriented
- C++ Function Overloading
- C++ Classes & Objects
- C++ Constructors & Destructors
- C++ Inheritance
- C++ Encapsulation
- C++ Polymorphism
- C++ Data Abstraction
- C++ Interfaces
- C++ Programming Advance
- C++ Linked Lists
- C++ Stacks
- C++ Queues
- C++ Date Time
- C++ Preprocessors
- C++ Exception Handling
- C++ Namespaces
- C++ Dynamic Memory
- C++ Multithreading
- C++ Templates
- C++ Signal Handling
- C++ Web Programming
- C++ Programming Examples
- C++ Programming Examples
- C++ Programming Test
- C++ Programming Test
- Give Online Test
- All Test List
C++ Data Abstraction
Data abstraction is the process of representing the essential features without including the implementation details. In other words, you can say that, data abstraction refers to, providing only the essential features by hiding the background details.
To create abstraction, or to abstract data from outside the world, then follow these two steps to provide or hide the implementation details from outside the world:
- Members which are defined with a public label are accessible to the all parts of the program.
- And the members which are defined with a private label are not accessible to the code that uses the class.
Data Abstraction Example Program in C++
Let's take some example program which illustrates data abstraction practically in C++. Here is the first example program demonstrating data abstraction in C++
/* C++ Data Abstraction - Example Program */ #include<iostream.h> #include<conio.h> class ADD { public: ADD(int i=0) { tot=i; } void addnumber(int num) { tot=tot+num; } int gettotal() { return tot; } private: // hidden from outside the world int tot; }; void main() { clrscr(); ADD aob; int a, b, c; cout<<"Enter any three numbers: "; cin>>a>>b>>c; aob.addnumber(a); aob.addnumber(b); aob.addnumber(c); cout<<"Total = "<<aob.gettotal(); getch(); }
Here is the sample run of the above C++ program:

Here is another example program, also demonstrating the data abstraction in C++
/* C++ Data Abstraction - Example Program */ #include<iostream.h> #include<conio.h> class CALC { public: CALC(int i=0) { res=i; } void addnumber(int num1, int num2) { res=num1+num2; } void subnumber(int num1, int num2) { res=num1-num2; } void mulnumber(int num1, int num2) { res=num1*num2; } void divnumber(int num1, int num2) { res=num1/num2; } int getresult() { return res; } private: int res; }; void main() { clrscr(); CALC cob; int a, b; cout<<"Enter two number: "; cin>>a>>b; cob.addnumber(a, b); cout<<"Sum = "<<cob.getresult()<<"\n"; cob.subnumber(a, b); cout<<"Subtract = "<<cob.getresult()<<"\n"; cob.mulnumber(a, b); cout<<"Multiply = "<<cob.getresult()<<"\n"; cob.divnumber(a, b); cout<<"Divide = "<<cob.getresult()<<"\n"; getch(); }
Below is the sample run of the above C++ program:

« Previous Tutorial Next Tutorial »