Thursday, July 23, 2020

Data Abstraction

Friends !  For understanding Data Abstraction first you link our self to real world don't see it technically than you can understand easily.

Data Abstraction Simple Means Data Hiding

Now first we see ,  Is it happen in our real life ? yes so many times. just remember 

some time you ask to your mother to make some testy food , she make and serve you , you eat and say wow what a food it is very testy with out knowing their internal ingredients used  and procedure to make that food. That all thing are hidden for you.

When you are purchase some appliances you just use it without knowing their internal mechanism. All internal mechanism and parts are covered by some substance so we can not see it. It is hidden for us.

Some time when you know any person by name without knowing their inner detail such as family detail , their occupation etc.

So I just try to say it is simple concept of hiding things from end user. Don't take it in complicated way.

Now come in technical terms in C++ how it happen and how it is implemented.

I hope you all know about objects in brief every thing in real world is objects which have some properties.

So we can say that "Data Abstraction is a concept by which we can represent any object by it's important features only without knowing their inner details"

In C++ we can achieve data abstraction using classes , Header files & Predefined functions

➤ Class contain all data member and data function in single unit.

Note: We can only access that data members and functions by using access specifiers in C++. Access specifiers may be private or public. Private means it is accessible inside the block and public means it is accessible from any where inside the program.

#include <iostream>    
 using namespace std;    
 class Add    
{    
   private: int a, b, c; // private variables  
   public:    
   void addition()    
{    
   cout<<"Enter two numbers: ";    
   cin>>a>>a;    
   c= a+a;    
   cout<<"Addition of two number is: "<<c<<endl;    
}    
};    

int main()    
{    
  Add ad;    
  ad.addition();    
  return 0;    
}    


➤ Header files & Predefined functions are also example of data Abstraction because in case we only use function like pow() , abs() , exp() etc. with knowing internal functionality or mechanism or algorithm.

Header Files such as : <cmath> , <cctype> , <cstdlib> , <ctime> , <csignal> etc.

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{    
   int a = 3;  
   int b= 2;  
   int c = pow(a , b);         // pow( a , b ) is the  power function  
   cout << "Square of a is : " <<c<< endl;  
   return 0;  
}  







No comments:

Post a Comment