Write a program to process weekly employee timecards for all employees of an org
ID: 3635819 • Letter: W
Question
Write a program to process weekly employee timecards for all employees of an organization.Each employee will have three data items: an identification number, the hourly wage rate, and the
number of hours worked during a given week. Each employee is to be paid time and a half for all
hours worked over 40. A tax amount of 3.625 percent of gross salary will be deducted. The
program output should show the employee’s number and net pay. Display the total payroll and the
average amount paid at the end of the run.
Explanation / Answer
#include<iostream>
#include<iomanip>
using namespace std;
class Employee{
int id;
int payRate;
int hoursWorked;
public:
Employee(){}
Employee(int id,int payRate, int hoursWorked)
{
this->id=id;
this->payRate=payRate;
this->hoursWorked=hoursWorked;
}
int getID()
{
return id;
}
void setpayRate(int payRate)
{
this->payRate=payRate;
}
void sethours(int hoursWorked)
{
this->hoursWorked=hoursWorked;
}
float getNetpay()
{
return calculateGross();
}
float calculateGross()
{
if(hoursWorked>40)
return getAmount();
else
return(float) this->payRate*this->hoursWorked ;
}
float getAmount()
{
int remaindHours=hoursWorked-40;
int half=payRate/2;
float netPay;
float tax=3.625;
netPay=(float)tax*(remaindHours*payRate+remaindHours*half);
return netPay;
}
};
int main()
{
Employee e[6];
float totalPayroll=0;
e[0]=Employee(1221,10,20);
e[1]=Employee(1222,20,25);
e[2]=Employee(1223,20,35);
e[3]=Employee(1224,15,20);
e[4]=Employee(1225,16,45);
e[5]=Employee(1226,16,45);
cout<<" Employee Details"<<endl;
cout<<setw(8)<<" ID"<<setw(12)<<"NetPay"<<endl;
for(int i=0;i<6;i++){
totalPayroll+=e[i].calculateGross();
cout<<setw(8)<<" "<<e[i].getID()<<setw(8)<<e[i].calculateGross()<<endl;
}
cout<<endl;
cout<<setw(25)<<"Total payroll:"<<totalPayroll<<endl;
cout<<setw(25)<<"Average Amount paid:"<<setprecision(5)<<totalPayroll/6<<endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.