Data abstraction in c++ example with header file abstraction and specifier abstraction


//Data Abstraction Using Access Specifiers
#include<iostream>
#include<math.h>
using namespace std;
class abstract{//Class Declaration
private://Private Access Specifier
        int num1, num2;//Data Members
public://Public Access Specifier
        void setValue(int a, int b){//Member Function
                num1 = a;
                num2 = b;
        }
        void display()//Member Function
        {
                cout<<num1<<" "<<num2<<endl;
        }
};
int main()//Main Function
{
        abstract obj;//Object creation
        obj.setValue(10, 20);//Function Calling
        obj.display();//Function Calling

        int res = pow(4, 3);
        cout<<res<<endl;
        return 0;
}

No comments:

Post a Comment