Expand the Employee Payroll program to include hourly based and salary based emp
ID: 3850037 • Letter: E
Question
Expand the Employee Payroll program to include hourly based and salary based employees. This phase uses an array of employee objects, inheritance for different classes of employees, and polymorphism for salary computation. The 52 week yearly salary as well as number of overtime hours worked by a salary based employee is given). For salary based employees, to find the regular (gross) pay for a week, divide the salary by 52. To compute the overtime pay for a salary based employee, first find the hourly rate by dividing the gross pay by 40, and then compute overtime pay. For every employee, overtime pay, tax amount, and net pay must also be computed. In addition, the program should find the minimum and maximum net pay of all employees as well as sort the employees based on their net pay (ascending order).
using code I am still getting errors in DEVC++, also what should be in my salraiedemployeed.in file
#include<fstream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class payroll{
ifstream fin;
public: string employeename;
char paystat;
int n;
float taxrate;
double hoursworked, overtimehours, regularhours;
double hourlyrate,regularpay,totalnetpay,minnp,maxnp;
double avgnetpay,taxamount,netpay,grosspay,overtimepay;
virtual double findgrosspay();
void setvariables(char[],int,char,char,char,double,double);
virtual double findtaxamount();
virtual double findnetpay();
virtual double findavgnetpay();
void printheaders();
void printdata();
double minnet(double, int);
double maxnet(double, int);
void printminmax(double, double);
void printreport();
void sortbypointers();
payroll();
~payroll();
};
class hourly: public payroll{
public: double findgrosspay(){
if(hoursworked > 40){
overtimehours=hoursworked-40;
regularpay=hoursworked*hourlyrate;
overtimepay=overtimehours*(hourlyrate*1.5);
grosspay=regularpay+overtimepay;}
else{
grosspay=hoursworked*hourlyrate;
regularpay=grosspay;
return grosspay;
}//IF
};//findgrosspay
};
class salaried:public payroll{
public: double findgrosspay(){
if(hoursworked>0){
overtimepay=hoursworked*(regularpay/52/40);
regularpay=hourlyrate/52;
grosspay=regularpay+overtimepay;
return grosspay;
}//If
};//findgrosspay
};
payroll::payroll(){
fin.open("salariedemployees.in"); }
payroll::~payroll() {
fin.close();}
double payroll::findtaxamount(){
taxrate=.30;
taxamount=grosspay*taxrate;
return taxamount;
}//findtaxamount
double payroll::findnetpay(){
netpay=grosspay-taxamount;
totalnetpay=totalnetpay+netpay;
return netpay;
}//findnetpay
double payroll::findavgnetpay(){
avgnetpay=totalnetpay/n;
cout<<endl<<"The average net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
return avgnetpay;
}//findavgnetpay
double payroll::minnet(double minnp, int n){
if(n==0) {
minnp=1000000;
}
if(netpay<minnp) {minnp=netpay;}
cout<<endl<<"The minimum net pay for "<<n<<" employees is"
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
return minnp;
}//minnet
double payroll::maxnet(double maxnp, int n){
if(n==0) {maxnp=3000000;}
if(netpay<maxnp) {maxnp=netpay;}
cout<<endl<<"The maximum net pay for "<<n<<"employees is"
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
return maxnp;
}//maxnp
void payroll:: sortbypointers(){
cout << "Before sorting by pointer:" << endl;
double p[100];
int i,j;
double temp;
int sortedflag=0;
for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
for(i=0;i<n;i++)cout<< "$" << p[i]<<" ";
while (!sortedflag){
sortedflag=1;
for(j=0;j<n-1;j++ ){
if (p[j]>p[j+1]){
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
sortedflag=0; }//SWAP
}//J
}//I
cout<<endl<<"SORTED ARRAY:";
for(i=0;i<100;i++)cout<<p[i]<<" ";
}//sortfunction
void payroll::printheaders(){
cout<<setw(40)<<"-PAYROLL REPORT-"<<endl;
cout<<"-----------------------------------------------------------"<<endl;
cout<<" NAME STAT HW HR REGP OT-PAY GROSS TAX NETPAY"<<endl;
cout<<"-----------------------------------------------------------"<<endl;
}//PRINTHEADINGS
void payroll::printdata(){
cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
cout<<setw(6)<<employeename<<setw(6)<<paystat<<
setw(2)<<hoursworked<<setw(8)<<
hourlyrate<<setw(8)<<regularpay<<setw(8)<<overtimepay<<setw(8)<<grosspay<<
setw(8)<<taxamount<<setw(8)<<netpay<<endl;
}//PRINTDATA
void payroll::printreport(){
n=0,totalnetpay=0;
printheaders();
while(fin>>employeename>>paystat>>hoursworked>>hourlyrate){
findgrosspay();
findtaxamount();
findnetpay();
printdata();
sortbypointers();
n++; }//WHILE
findavgnetpay();
cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<endl;
}//PRINTREPORT
int main(){
int n=0;
payroll employee[6],report;
employee[0].printreport();
string aemployeename;
char apaystat;
double ahoursworked, ahourlyrate;
ifstream fin("salariedemployees.in");
while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate){
if(apaystat=='s'){
employee[n]=new salaried();
employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
employee[n]->findgrosspay(); }//if s
if(apaystat=='h'){
employee[n]=new hourly();
employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
employee[n]->findgrosspay(); }//if h
n++;
}//WHILE
sortnetpays(netpay,n);
fin.close();
system ("pause");
}//MAIN
Explanation / Answer
import java.util.Scanner;
class payroll {
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter employee's name:");
String employee = input.next();
System.out.println("Enter number of hours worked:");
double hours = input.nextDouble();
System.out.println("Enter hourly pay rate:");
double pay = input.nextDouble();
double gross_pay = pay * hours;
System.out.println("Enter federal tax withholding rate:");
double fedtax = input.nextDouble();
double fedtaxr = fedtax * 0.20;
System.out.println("Enter state tax withholding rate:");
double statetax = input.nextDouble();
double statetaxr = statetax * 0.20;
double deductions = fedtaxr + statetaxr;
double total_pay = gross_pay - deductions;
System.out.println("Employee name: " + employee);
System.out.println("Hours worked: " + hours);
System.out.println(" Enter payrate: " + pay);
System.out.println(" Enter gross pay: " + gross_pay);
System.out.println(" Deductions: ");
System.out.println(" Federdal Withholding (20.0%): " + fedtaxr);
System.out.println(" State Withholding (9.0%)" + statetaxr);
System.out.println(" Total deductions:" + deductions);
System.out.println("Total pay: " + total_pay);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.