Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ Create an Employee class for a basic payroll program to compute the net p

ID: 665435 • Letter: I

Question

In C++

Create an Employee class for a basic payroll program to compute the net pay salary of hourly based employees. Your program should also find the average net pay for a small company. To define the class, include the appropriate data members, member functions, and access modifiers. For simplicity, use a constant tax rate of 30% to compute the tax amount. Employees that work over 40 hours will receive overtime pay of one and a half of their hourly rate for overtime hours worked. The output should display the name of each employee, hours worked, hourly rate, overtime pay, regular (gross) pay, tax amount, and net pay. The average net pay of all employees should also be displayed.

Explanation / Answer


#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;

int main()
{

//*Declaration of identifier*//
double Gross_sal;
float Benefits, con_bution, cont_percent, net_sal, tax, hour_2, pay_rate, over_pay, Gross_sal_retire;
string Ful_name, fin, fout;
float total_gross, total_benefit, total_cont, total_tax, total_netsal;//Total Identifier series.
int skill_lvl, ben_code, Hour_work;
long ssn;

//*Open File*//
ifstream fin_input;
ofstream fout_output, fout_excredit;


cout<<" "<<setw(60)<<"Welcome to Davis's Assignment 3! Please Enjoy!."<<endl;
cout<<setw(60)<<"Just made the name of Output text files."<<endl;
cout<<setw(60)<<"It will be automatically created."<<" "<<endl;

cout<<left<<setprecision(2);
//* fin open status *//
cout<<setw(57)<<"Enter the name of the input text file : ";
cin>>fin;
fin_input.open(fin.c_str());
if(fin_input.fail())
{
  cout<<setw(57)<<"Textfile cannot be found, please try it again"<<endl;
  return 0;
}

cout<<setw(57)<<"Enter the name of the output text file : ";
cin>>fout;
fout_output.open(fout.c_str());
if(fout_output.fail())
{
  cout<<setw(57)<<"Textfile cannot be found, please try it again"<<endl;
  return 0;
}

cout<<setw(57)<<"Enter the name of the extra-credit output text file : ";
cin>>fout;
fout_excredit.open(fout.c_str());
if(fout_excredit.fail())
{
  cout<<setw(57)<<"Textfile cannot be found, please try it again"<<endl;
  return 0;
}
  
//*Output description*//
cout<<endl;
cout<<endl;
cout<<endl;
cout<<left<<setprecision(2)<<fixed;
fout_output<<left<<setprecision(2)<<fixed;
fout_output<<setw(15)<<"Name"<<setw(13)<<"Gross Salary"<<setw(12)<<"Benefits"<<setw(15)<<"Contribution"<<setw(10)<<"Tax"<<setw(12)<<"Net Salary"<<endl;
cout<<setw(15)<<"Name"<<setw(13)<<"Gross Salary"<<setw(12)<<"Benefits"<<setw(15)<<"Contribution"<<setw(10)<<"Tax"<<setw(12)<<"Net Salary"<<endl;
fout_excredit<<" "<<setw(60)<<"**********Bad Data will be Automatically Skip. Please fix your Bad datas.**********"<<" "<<endl;


total_gross=0;
total_benefit=0;
total_cont=0;
total_tax=0;
total_netsal=0;
con_bution=0;

//*Looping*//
fin_input>>skill_lvl;
while(!fin_input.eof())
{
  cont_percent = 0.0;
  ben_code = 0;
  con_bution = 0;
  fin_input>>ben_code>>cont_percent>>Hour_work>>ssn;
  fin_input.ignore(10,' ');
  getline(fin_input,Ful_name);
  
  //*Bad Data*//
  if(skill_lvl > 4 || skill_lvl < 1 || Hour_work > 60 || Hour_work < 0
   || ben_code > 3 || ben_code < 0 || cont_percent > 5.0 || cont_percent < 0.0)
  {
   cout<<setw(15)<<Ful_name<<setw(15)<<"Bad Data"<<endl;
   fout_output<<setw(15)<<Ful_name<<setw(15)<<"Bad Data"<<endl;
  }
  else
  {
   // FUNCTION FOR CALCULATION FROM ASSIGNMENT 2

   //*Benefit Declaration*//
   switch(ben_code)
   {
    case 0:
     Benefits = 0;
     break;
    case 1:
     Benefits = 32.50;
     break;
    case 2:
     Benefits = 52.50;
     break;
    case 3:
     Benefits = 62.50;
     break;
   }

   switch(skill_lvl)
   {
    case 1:
     pay_rate = 15.00;
     break;
    case 2:
     pay_rate = 25.00;
     break;
    case 3:
     pay_rate = 72.00;
     break;
    case 4:
     pay_rate = 125.00;
     break;
   }

   //*Overpay*//
   if (Hour_work > 40)
   {
    hour_2 = Hour_work - 40;
    if (hour_2 <= 10)
    {
     over_pay = (1.5 * pay_rate) * hour_2;
    }
    else if(hour_2 <= 20)
    {
     over_pay = (1.5 * pay_rate) * 10;
     over_pay = over_pay + ((hour_2 - 10) * (pay_rate*2));
    }
   }

   //*Gross Payment*//
   if(Hour_work > 40)
   {
    Gross_sal = (40 * pay_rate) + over_pay;
   }
   else
   {
    Gross_sal = (Hour_work * pay_rate);
   }
  

   if(skill_lvl == 4)
   {
    Gross_sal_retire = Gross_sal;
    cont_percent = cont_percent / 100;
    con_bution = Gross_sal_retire * cont_percent;

    //*gross salary*//
    Gross_sal = Gross_sal - con_bution;
   }
   if(skill_lvl == 0)
   {
    Benefits = 0;
   }
    Gross_sal = Gross_sal - Benefits;
   
    //*Tax Calculation*//
   if(Gross_sal >= 0 && Gross_sal <= 2000)
   {
    tax = 0;
   }
   else if(Gross_sal >= 2000.01 && Gross_sal <= 3000.00)
   {
    tax = .03 * Gross_sal;
   }
   else if(Gross_sal >= 3000.01 && Gross_sal <= 4000.00)
   {
    tax = (.01 * 3000) + (.05 * (Gross_sal - 3000));
   }
   else if(Gross_sal >= 4000.01 && Gross_sal <= 5000.00)
   {
    tax = (.01 * 3000) + (.05 * 1000) + (.07 * (Gross_sal - 4000));
   }
   else if(Gross_sal >= 5000.01)
   {
    tax= (.01*3000)+(.05*1000)+(.07*1000)+(.01*(1000*static_cast<int>((Gross_sal-5000)/1000)));
   }

   net_sal = Gross_sal - tax;

   //******************************************funtion for calculation*******************************************************//

   //*Total Calculation looping*//
   total_gross += Gross_sal;
   total_benefit += Benefits;
   total_cont += con_bution;
   total_tax += tax;

   total_netsal += net_sal;
   //*end of Total calculation*//

   //*output& Warning*//
   if(skill_lvl == 4)
   {
    fout_output<<setw(15)<<Ful_name<<"$"<<setw(12)<<Gross_sal_retire<<"$"<<setw(11)<<Benefits<<"$"<<setw(14)<<con_bution<<"$"<<setw(9)<<tax<<"$"<<setw(11)<<net_sal<<endl;
    cout<<setw(15)<<Ful_name<<"$"<<setw(12)<<Gross_sal_retire<<"$"<<setw(11)<<Benefits<<"$"<<setw(14)<<con_bution<<"$"<<setw(9)<<tax<<"$"<<setw(11)<<net_sal<<endl;
   }
   else if(skill_lvl <= 3 && skill_lvl >= 1)
   {
    fout_output<<setw(15)<<Ful_name<<"$"<<setw(12)<<Gross_sal<<"$"<<setw(11)<<Benefits<<setw(15)<<"N/A"<<"$"<<setw(9)<<tax<<"$"<<setw(11)<<net_sal<<endl;
    cout<<setw(15)<<Ful_name<<"$"<<setw(12)<<Gross_sal<<"$"<<setw(11)<<Benefits<<setw(15)<<"N/A"<<"$"<<setw(9)<<tax<<"$"<<setw(11)<<net_sal<<endl;
   }
   //*warning*//
   
   //*extra-credit part*//
   fout_excredit<<left<<setprecision(2)<<fixed;
   fout_excredit<<setw(50)<<"**************************************************"<<endl;
   fout_excredit<<setw(30)<<"Name:"<<setw(15)<<Ful_name<<endl;
   fout_excredit<<setw(30)<<"Gross Salary:"<<"$"<<setw(15)<<Gross_sal<<endl;
   fout_excredit<<setw(30)<<"Medical Benefits:"<<"$"<<setw(15)<<Benefits<<endl;

   if(skill_lvl == 4)
   {
    fout_excredit<<setw(30)<<"Retirement Contribution: "<<(cont_percent*100)<<"%"<<endl;
    fout_excredit<<setw(10)<<""<<setw(15)<<"Company:"<<"$"<<setw(10)<<con_bution<<endl;
    fout_excredit<<setw(10)<<""<<setw(15)<<"Employee:"<<"$"<<setw(10)<<con_bution<<endl;
    fout_excredit<<setw(10)<<""<<setw(15)<<"Total:"<<"$"<<setw(10)<<(con_bution*2)<<endl;
   }
   else if(skill_lvl < 4)
   {
    fout_excredit<<setw(30)<<"Retirement Contribution:"<<setw(15)<<"N/A"<<endl;
    fout_excredit<<setw(10)<<""<<setw(15)<<"Company:"<<setw(10)<<"N/A"<<endl;
    fout_excredit<<setw(10)<<""<<setw(15)<<"Employee:"<<setw(10)<<"N/A"<<endl;
    fout_excredit<<setw(10)<<""<<setw(15)<<"Total:"<<setw(10)<<"N/A"<<endl;
   }

   fout_excredit<<setw(30)<<"Tax Owed:"<<"$"<<setw(15)<<tax<<endl;
   fout_excredit<<setw(30)<<"Net Salary:"<<"$"<<setw(15)<<net_sal<<endl;
   fout_excredit<<setw(50)<<"**************************************************"<<" "<<endl;
   //*extra-credit part*//

  } //*If not bad data end*//
  
  fin_input>>skill_lvl;
}

//*total output*//
cout<<endl;
fout_output<<endl;
fout_output<<setw(70)<<"**********************************************************************"<<endl;
cout<<setw(70)<<"**********************************************************************"<<endl;
cout<<setw(50)<<"Total Gross Salaries:"<<"$"<<setw(15)<<total_gross<<endl;
cout<<setw(50)<<"Total Benefits collected:"<<"$"<<setw(15)<<total_benefit<<endl;
cout<<setw(50)<<"Total Contribution to retirement Fund:"<<"$"<<setw(15)<<total_cont<<endl;
cout<<setw(50)<<"Total Taxes Collected:"<<"$"<<setw(15)<<total_tax<<endl;
cout<<setw(50)<<"Total Net Salaries Paid:"<<"$"<<setw(15)<<total_netsal<<endl;//end of total output
fout_output<<setw(50)<<"Total Gross Salaries:"<<"$"<<setw(15)<<total_gross<<endl;
fout_output<<setw(50)<<"Total Benefits collected:"<<"$"<<setw(15)<<total_benefit<<endl;
fout_output<<setw(50)<<"Total Contribution to retirement Fund:"<<"$"<<setw(15)<<total_cont<<endl;
fout_output<<setw(50)<<"Total Taxes Collected:"<<"$"<<setw(15)<<total_tax<<endl;
fout_output<<setw(50)<<"Total Net Salaries Paid:"<<"$"<<setw(15)<<total_netsal<<endl;
fout_output<<setw(70)<<"**********************************************************************"<<endl;
cout<<setw(70)<<"**********************************************************************"<<" "<<endl;//end of total output
fout_excredit.close();
fout_output.close();
fin_input.close();
return 0;
}