Example & Tutorial understanding programming in easy ways.

Define abstraction in C++

What is Data abstraction:
-Data abstraction refers to providing only essential information to the outside world and hiding their background details.
-Data abstraction is a programming technique that relies on the separation of interface and implementation.
-In C++, classes provides great level of data abstraction. They provide sufficient public methods to the outside world to play with the functionality of the object and to manipulate object data, i.e., state without actually knowing how class has been implemented internally.

program:

#include < iostream>
using namespace std;
class Myclass{
public:
// constructor
Myclass(int i = 0) {
total = i;
}
// interface to outside world
void addNum(int number) {
total += number;
}
// interface to outside world
int getTotal() {
return total;
};
private:
// hidden data from outside world
int total;
};
int main() {
Myclass obj;
obj.addNum(10);
obj.addNum(20);
obj.addNum(30);
cout << "Total " << a.getTotal() << endl;
return 0;
}


output-

Total 60




Read More →