Data abstraction in c++

Data abstraction in c++



  1. #include<bits/stdc++.h>  
  2. using namespace std;  
  3.   
  4. class Shape{ /// Abstract class that contains at least one pure virtual function  
  5. public:  
  6.     virtual void show()=0; ///Pure virtual function  
  7. };  
  8.   
  9. class Circle:public Shape{  
  10. public:  
  11.     void show(){  
  12.         cout<<"Circle"<<endl;  
  13.     }  
  14. };  
  15.   
  16. class Rectangle:public Shape{  
  17. public:  
  18.     void show(){  
  19.         cout<<"Rectangle"<<endl;  
  20.     }  
  21. };  
  22.   
  23. int main()  
  24. {  
  25.     Shape *shape;  
  26.     Circle circle;  
  27.     Rectangle rectangle;  
  28.   
  29.     shape=&circle;  
  30.     shape->show();  
  31.   
  32.     shape=&rectangle;  
  33.     shape->show();  
  34.   
  35.     return 0;  
  36. }  
Share:

0 Comments:

Post a Comment