Saturday, 18 February 2017

Class of employee entering data in functions of class

In this program we will create a class of employee, create its setter and getter functions and call them in main().

//Code Starts
#include<iostream>
#include<conio.h>

using namespace std;

class emp{
         
          private : int salary;
                    char name[20],desig[50],resp[50];
                   
                    public:
                             
              void setsalary();
              void setname();
               void setdesig();
               void setresp();
                                                 
                 int getsalary();
                 int getname();
                 int getdesig();
                 int getresp();
                                                 
               void display();                                             
};
 void emp::setsalary()  {
                                                                               
 cout<<"Enter Salary of Employee: ";
 cin>>salary;
           }
                                                                     
void emp::setname() {
                                                                               
cout<<"Enter name of employee : ";
 cin>>name;
                \   }
                                                                     
void emp::setdesig()
 {
 cout<<"Enter designation of employee : ";
 cin>>desig;
           }
                                                                     
 void emp::setresp()
  {
  cout<<"Enter Resposibility of "<<name<<" : ";
  cin>>resp;
             }
                                                           
 int emp::getsalary()
  {
         return salary;
   }
  
void emp::display()
{
 cout<<name<<" works in company as "<<desig<<" "<<resp<<" on salary of RS."<<salary;
 if(salary<=20000)
  {
     cout<<"Salary is average";
          }
else{
   cout<<"Above average salary";
       }
                 }

int main()
{
          emp e1;
         
          for(int i=1;i<=2;i++)
          {
         
          e1.setname();
         
          e1.setdesig();
         
          e1.setresp();
         
          e1.setsalary();
         
          e1.display();
         
          cout<<endl;
         
          }
          getch();

}

//Code ends


Share:

0 comments:

Post a Comment