Sunday, 7 December 2014

C++ program to print salary details of an employee

#include<iostream.h>
#include<conio.h>
class emp
{
 private:
  int sno,gross,ta,da,pf,dec,hra,b_sal,n_sal;

  char name[20];
 public:
  void getdata();
  void putdata();
};
void emp::getdata()
{
 cout<<"\nenter sno,name,b_sal:\n";
 cin>>sno>>name>>b_sal;
}
void emp::putdata()
{
 ta=0.008*b_sal;
 da=0.001*b_sal;
 hra=0.004*b_sal;
 pf=0.02*b_sal;
 dec=0.02*b_sal;
 gross=b_sal+ta+da+hra+pf;
 n_sal=gross+dec;
 cout<<sno;
 cout.width(10);
 cout<<name;
 cout.width(10);
 cout<<hra;
 cout.width(10);
 cout<<da;
 cout.width(10);
 cout<<gross;
 cout.width(10);
 cout<<dec;
 cout.width(10);
 cout<<n_sal;
}
void main()
{
 clrscr();
 emp s[5];
 int i,n;
 cout<<"\nenter no of employees:";
 cin>>n;
 for(i=1;i<n;i++)
 {
  s[i].getdata();
 }
 cout<<"\n******************************************************************\n";
 cout<<"sno";
 cout.width(10);
 cout<<"name";
 cout.width(10);
 cout<<"hra";
 cout.width(10);
 cout<<"da";
 cout.width(10);
 cout<<"gross";
 cout.width(10);
 cout<<"dec";
 cout.width(10);
 cout<<"n_sal";
 cout<<"\n******************************************************************\n";
 for(i=1;i<n;i++)
 {
  s[i].putdata();
  cout<<"\n";
 }
 cout<<"\n******************************************************************\n";
 getch();
}