Write a C++ program to create a class Employee which contains data members as Emp_Id, Emp_Name, Basic_Salary, HRA, DA, Gross_Salary. Write member functions to accept Employee information. Calculate and display Gross salary of an employee. (DA=12% of Basic salary and HRA = 30% of Basic salary) (Use appropriate manipulators to display employee information in given format :- Emp_Id and Emp_Name should be left justified and Basic_Salary, HRA, DA, Gross salary Right justified with a precision of two digits)

//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;

#include<conio.h>
#include<iostream.h>
#include<iomanip.h> //manipulator 
class emp
{
public:
   int eid; //eid=employee id
   float bsal,hra,da,gsal; //bsal=basic salary , hra=HRA , da=DA , gsal=Gross salary
   char name[10]; //name=name of employee
   void accept()
   {
    cout<<"Enter employee id: ";
      cin>>eid;
      cout<<"Enter employee name: ";
      cin>>name;
      cout<<"Enter basic salary: ";
      cin>>bsal;
   }
   void disp()
   {
       cout.precision(2);  //manipulator
       cout.left;
       cout<<"employee id: "<<setw(20)<<eid<<endl;
       cout<<"employee name: "<<setw(20)<<name<<endl;
       cout<<"basic salary: "<<bsal<<endl;
       cout<<"HRA: "<<hra<<endl;
       cout<<"DA: "<<da<<endl;
       cout<<"Gross salary: "<<gsal<<endl;
   }
   void cal()  //calculate gross salary
   {
      hra=((30.0/100)*bsal);
      da=((20.0/100)*bsal);
      gsal=bsal+hra+da;
   }
};
int main()
{
   emp e; //creating instance of class emp
   e.accept(); //calling member functions
   e.cal();
   e.disp();
   getch();
   return(0);
}

0 Comments