Data Abstracton
Data Abstracton
o Public specifier: When the members are declared as public, members can
be accessed anywhere from the program.
o Private specifier: When the members are declared as private, members can
only be accessed only by the member functions of the class.
#include <iostream.h>
#include<math.h>
int main()
{
int n = 4;
int power = 3;
int result = pow(n,power);
cout << "Cube of n is : " <<result<<endl;
return 0;
}
Output:
Cube of n is : 64
#include <iostream>
using namespace std;
class Sum
{
private: int x, y, z; // private variables
public:
void add()
{
cout<<"Enter two numbers: ";
cin>>x>>y;
z= x+y;
cout<<"Sum of two number is: "<<z<<endl;
}
};
int main()
{
Sum sm;
sm.add();
return 0;
}
Output: