Skip to content

Instantly share code, notes, and snippets.

@amjd
Created September 15, 2014 17:35
Show Gist options
  • Save amjd/4b12b5951456a7c33986 to your computer and use it in GitHub Desktop.
Save amjd/4b12b5951456a7c33986 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class Employee
{
private:
int e_no;
char e_name[30];
float basic_sal;
float all_allowances;
float i_tax;
float net_sal;
public:
void read();
void calcNetSalary();
void display();
int getnum();
};
void Employee::read()
{
cout<<"\nEnter employee details:\n";
cout<<"\nEmployee number: ";
cin>>e_no;
cout<<"\nName: ";
cin>>e_name;
cout<<"\nBasic salary: ";
cin>>basic_sal;
}
void Employee::calcNetSalary()
{
all_allowances = 1.23 * basic_sal;
i_tax = 0.30 * (basic_sal + all_allowances);
net_sal = basic_sal + all_allowances - i_tax;
}
void Employee::display()
{
cout.precision(4);
cout.setf(ios::right);
cout<<e_no;
cout.width(15);
cout<<e_name;
cout.width(15);
cout<<basic_sal;
cout.width(15);
cout<<all_allowances;
cout.width(15);
cout<<i_tax;
cout.width(15);
cout<<net_sal<<endl;
}
int Employee::getnum()
{
return e_no;
}
int main()
{
int n;
Employee e[20];
cout<<"\nEnter the number of employees: ";
cin>>n;
for(int i=0; i<n; i++)
{
e[i].read();
for (int j=0; j<i; j++)
{
if(e[i].getnum() == e[j].getnum())
{
cout<<"\nEmployee number already exists! Please enter details again.";
i--;
}
}
}
cout<<"\nEmployee details are:\n";
cout<<"E_NO\t NAME\t\t BASIC\t\t DA\t\t IT\t NET SALARY\n";
for (int i=0; i<n; i++)
{
e[i].calcNetSalary();
e[i].display();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment