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

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

the length and breadth of a rectangle and radius of a circle are input through the keyboard. write a program to calculate the area and perimeter of the rectangle, and the area and circumference of the circle

paper of size A0 has dimensions 1189 mmx 841 mm .Each subsequent size A(n) is defined as A(n-1) cut in half parallel to its shorter sides .Thus paper of size A1 would have dimensions 841 mm X 594 mm .Write a program to calculate the print paper sizes A0,A1,A2,.........A8.