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

Payroll Program Write a Payroll Program in C++ that will perform the functions s

ID: 3811616 • Letter: P

Question

 Payroll Program   Write a Payroll Program in C++ that will perform the functions specified below.  1.  Print the heading      NAME                    RATE  HOURS      INS    SOC    STATE    FED    NET                                                     SEC     TAX     TAX  2.  For each employee do the following,      A.  Read a line of data from a file (or from STDIN)      B.  Compute the gross-pay as rate times hours, if the hours is <=40.         Pay double time for overtime (over 40 hours).      C.  Compute dollar amount of Insurance withholding as:           0.00 if status is None          9.50 if status is Single         24.75 if status is Family      D.  Compute social security withheld as 7% of gross pay      E.  Compute state tax as 3% of gross pay      F.  Compute PYE (Projected Yearly earnings) as gross-pay times 52.      G.  Compute the federal-tax based on PYE from the following table.              0%  if PYE < 8000            15%  if 8000 <= PYE < 20000            28%  if PYE >= 20000           Using the above tax brackets, compute Federal-Tax withheld as the          above percents times PYE occurring in each tax bracket.          Example:            if PYE is 21000            then yearly federal-tax = (20000-8000)*.15 + (21000-20000)*.28                                   =  1800            +  280                                   =  2080      H.  Compute Net pay as gross-pay  minus  insurance  minus  soc-sec         minus state-tax minus fed-tax      I.  Print a detail line with the above items   Input File:           11111111112222222222333 12345678901234567890123456789012 Tom Anderson          7.52  45 N Bob Conerley         17.50  40 S John H. Potter        9.30  35 S Terrance Appleby     31.00  42 F Joseph Rinker        17.00  35 F Todd Russell          5.00  30 S Bill Ryan            18.25  45 N  Your output should look similar to the following:   NAME                    RATE  HOURS     INS     SOC    STATE    FED    NET                                                 SEC     TAX     TAX  Tom Anderson            7.52  45.00    0.00   26.32   11.28    33.32   305.08 Bob Conerley           17.50  40.00    9.50   49.00   21.00   122.92   497.58 John H. Potter          9.30  35.00    9.50   22.78    9.76    25.74   257.71 Terrance Appleby       31.00  42.00   24.75   95.48   40.92   308.84   894.01 Joseph Rinker          17.00  35.00   24.75   41.65   17.85    93.52   417.23 Todd Russell            5.00  30.00    9.50   10.50    4.50     0.00   125.50 Bill Ryan              18.25  45.00    0.00   63.87   27.37   182.42   638.83  -- use  setprecision(2), fixed and setw() to line up the decimals.     The following code can be used to read in the data   #include <iostream> #include <iomanip> #include <string> using namespace std;  int main ()   {     char cname[20];     double rate, hours;     char inscode;      while (cin.get(cname,21))  // read in 20 chars       {         string name = cname;         cin >> rate >> hours >> ws >> inscode >> ws;          cout << "|" << name;         cout << "|" << rate;         cout << "|" << hours;         cout << "|" << inscode;         cout << "|" << endl;       }      return 0;   }    Additional requirements for the assignment:     Steps B, C and G must be EXTERNAL functions and must be in separate files.     Use the pre-processor directive   #if __INCLUDE_LEVEL__ < 1    to facilitate debugging the functions.      Use a consistent set of rules for indention - ie those covered in class.  Turn in:    The main payroll program with the output    The 3 test programs for steps B, C and G 

Explanation / Answer

The code for given problem is organized into four files.

a) Main payroll program (Payroll.cpp)

b) External functions (FederalTax.cpp, GrossPay.cpp, InsWithholding.cpp)

The code can be compiled using following command.

g++ Payroll.cpp FederalTax.cpp GrossPay.cpp InsWithholding.cpp

The executable is run as follows.

./a.out <filename>

File: FederalTax.cpp

#include <algorithm>

using namespace std;

double getFederalTax(double pye)
{
double federalTax = 0;

if (pye > 8000) {
federalTax += min(12000.0, pye - 8000) * 0.15;
}

if (pye > 20000) {
federalTax += (pye - 20000) * 0.28;
}

return federalTax;
}

File: GrossPay.cpp

double getGrossPay(double rate, double hours)
{
double grossPay = rate * hours;

if (hours > 40) {
grossPay += (hours - 40) * rate;
}

return grossPay;
}

File: InsWithholding.cpp

double getInsuranceWithholding(char insCode)
{
switch(insCode) {
case 'S':
return 9.5;
case 'F':
return 24.75;
case 'N':
return 0;
}
}

File: Payroll.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>

using namespace std;

extern double getInsuranceWithholding(char insCode);
extern double getGrossPay(double rate, double hours);
extern double getFederalTax(double pye);

int main ( int argc, char *argv[] )
{
if (argc < 2) {
cout << "usage: " << argv[0] << " <filename>" << endl;
return -1;
}

ifstream inFile;
inFile.open(argv[1]);

char cname[20];
double rate, hours, insurance, grossPay, socSec, stateTax, pye, fedTax, net;
char insCode;

string line;

cout << left << setw(21) << "NAME";
cout << right << setw(6) << "RATE";
cout << right << setw(6) << "HOURS";
cout << right << setw(6) << "INS";
cout << right << setw(6) << "SOC";
cout << right << setw(6) << "STATE";
cout << right << setw(7) << "FED";
cout << right << setw(7) << "NET";
cout << endl;

cout << left << setw(21) << "";
cout << right << setw(6) << "";
cout << right << setw(6) << "";
cout << right << setw(6) << "";
cout << right << setw(6) << "SEC";
cout << right << setw(6) << "TAX";
cout << right << setw(7) << "TAX";
cout << endl << endl;


while (getline(inFile, line))
{
istringstream inSS(line);
inSS.get(cname, 21);
inSS >> rate >> hours >> insCode;
  
cout << left << setw(21) << cname;
cout << right << fixed << setprecision(2) << setw(6) << rate;
cout << right << fixed << setprecision(2) << setw(6) << hours;

insurance = getInsuranceWithholding(insCode);
grossPay = getGrossPay(rate, hours);
socSec = grossPay * 0.07;
stateTax = grossPay * 0.03;
pye = grossPay * 52;
fedTax = getFederalTax(pye) / 52;
net = grossPay - insurance - socSec - stateTax - fedTax;

cout << right << fixed << setprecision(2) << setw(6) << insurance;
cout << right << fixed << setprecision(2) << setw(6) << socSec;
cout << right << fixed << setprecision(2) << setw(6) << stateTax;
cout << right << fixed << setprecision(2) << setw(7) << fedTax;
cout << right << fixed << setprecision(2) << setw(7) << net;

cout << endl;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote