access the private and public in c++.

 access the private and public in c++.
 

#include<iostream>
using namespace std;
class Employee
{
    private:
    int  a,b,c;
public:
    int d,e,f;
    void setData(int a1,int b1,int c1);
    void getData(){
    cout<<"The value of a is= "<<a<<"\n";
    cout<<"The value of b is= "<<b<<"\n";
    cout<<"The value of c is= "<<c<<"\n";
    cout<<"The value of d is= "<<d<<"\n";
    cout<<"The value of e is= "<<e<<"\n";        
    cout<<"The value of f is= "<<f<<"\n";
            }
};
   void Employee::setData(int a1 ,int b1, int c1){

    a=a1;
    b=b1;
    c=c1;
}
    int main()
{
Employee rajukumar;
//rajukumar.a=134; this is private
  rajukumar.d=55;
  rajukumar.e=878;
  rajukumar.f=54;
  rajukumar.setData(3,4,66);
  rajukumar.getData();
  return 0;    
}

output ----



 

Comments

Popular posts from this blog

class with array in c++ (memory allocatin & using array in classes)

constructor with default arguments

constructor overloading in c++ programming