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

How will learn of c language?

If lengths of three sides of a tringle are input through the keyboard write a program to find the area of tringle.

The body mas index (BMI) is defined as ratio of the weight of the person (in kelometer) to the square oef height (in meters) . write a program that recieve weight and height calculate the BMI and report the BMI category as per the following table .