Search Your Topic

config
Saturday, 17 June 2017 07:31

Data Abstraction in C++

Written by
Rate this item
(0 votes)

In C++ program if we implement class with private and public members then it is an example of data abstraction.

Let's see the simple example of data abstraction.

 
  1. #include <iostream>  
  2. using namespace std;  
  3.  class Sum  
  4. {  
  5. privateint x, y, z;  
  6. public:  
  7. void add()  
  8. {  
  9. cout<<"Enter two numbers: ";  
  10. cin>>x>>y;  
  11. z= x+y;  
  12. cout<<"Sum of two number is: "<<z<<endl;  
  13. }  
  14. };  
  15. int main()  
  16. {  
  17. Sum sm;  
  18. sm.add();  
  19. return 0;  
  20. }  

Output:

Enter two numbers:
3
6
Sum of two number is: 9
Read 143 times
Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

toshiyas.in

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.