Data Abstraction,ADT and Information Hiding
Q22. What is Data abstraction? Explain.
Answer:
Abstraction
An abstraction is a process of showing relevant details and hiding irrelevant details from the user i.e., the implementation details are completely hidden from the user.
It gives the representation of real-world entities thereby showing only important attributes from the set of attributes.
To form groups from the set of attributes by using abstraction, then while forming the groups, the common attributes have been neglected hence, abstraction reduces the group complexity by simplifying its elements.
There are two types of abstraction. They are,
(i) Process abstraction
(ii) Data abstraction
(i) Process Abstraction
It refers to the way in which the programs must specify some computational process has to be done. without providing the details of computation. ‘
All function/subprograms and exceptional handlers are the examples of process abstraction.
(ii) Data Abstraction
It refer to the way of isolating the data implementation methods from its usage. All the data members of an ADT are related to.data abstraction and the member functions to process abstraction. These two abstraction types are related. to each other.
Program
#include<iostream.h>
#include<conio.h>
class Sub
{
private:
int x,y,z;
public:
void subtraction()
{
cout<<"Enter two
numbers:";
cin>>x>>y;
z = x-y;
cout<<"Subtraction
is:"<<z;
}
};
void main()
{
Sub s;
clrscr();
s.subtraction();
getch();
}
Output:
In the above program, ‘x’,‘y’ and ‘z’ are the private data-members and the function is the public member function. An object 's’ of type class is created in the main( ) function and then the member function subtraction( ) is called by using the dot operator.