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

I need help with getting started with this project. I will post my code from pre

ID: 3759426 • Letter: I

Question

I need help with getting started with this project. I will post my code from previous lab below. This is a c++ class.

Modify the payroll program from lab #6 to accept data from a file of employee data instead of the keyboard. The payroll program will read in data from a file "employeeData.txt", and output to a file named "YOURLASTNAME.txt".

Specifications: • The data in the input is not delimited • The number of data sets for employees can vary • The program must handle file failure conditions (Chapter 5) • The program must loop to read in the data, calculate the values for each employee, and output the results to “yourLastName.txt". • The program must cout “Successful Completion” when finished • The input data file ("employeeData.txt“) that your program will read from will be in this order and will include: 1. A 1 or 0 - one indicates that there is a set of employee data following 2. the hourly rate of the employee (double) 3. the number of hours worked by the employee (integer) 4. the number of dependents the employee has claimed (integer) 5. A 1 or 0 – indicating if the employee is full time (1 = fulltime).

Explanation / Answer

#include <iostream>
#include<fstream> // Added since we are reading from and writing to files.

using namespace std;

ifstream in_file;
ofstream out_file;

double tax_withholding (int numDependants, double grossPay);

double ira_function (double grossPay);

double medical_cost_function (double netPay, int employmentStatus);

void get_userinput ();

void calculate_overTimePay (int hoursWorked, double hourlyRate, double &basePay, int &overTimeHours, double &overTimePay,
                            int &doubleTimeHours, double &doubleTimePay, double &grossPay);

void output_payroll (int hoursWorked, double hourlyRate, int overTimeHours, int doubleTimeHours, int numDependants,
                     double basePay, double grossPay, double modifiedgrossPay, double netPay, double overTimePay,
                     double doubleTimePay, double withholding, double iraDeductionAmount, double medicalBenefitCost);

int main ()

{
    int hoursWorked, overTimeHours, doubleTimeHours, numDependants, fullTime;
    double hourlyRate, basePay, overTimePay, doubleTimePay, grossPay, modifiedgrossPay, withholding, iraDeductionAmount,
            medicalBenefitCost, netPay;


    get_userinput();

    calculate_overTimePay (hoursWorked, hourlyRate, basePay, overTimeHours, overTimePay, doubleTimeHours, doubleTimePay, grossPay);

    iraDeductionAmount = ira_function(grossPay);

    modifiedgrossPay = grossPay - iraDeductionAmount;

    withholding = tax_withholding(numDependants, modifiedgrossPay);

    netPay = modifiedgrossPay - withholding;

    medicalBenefitCost = medical_cost_function (netPay, fullTime);

    netPay = netPay - medicalBenefitCost;


    output_payroll (hoursWorked, hourlyRate, overTimeHours, doubleTimeHours, numDependants,
                    basePay, grossPay, modifiedgrossPay, netPay, overTimePay, doubleTimePay, withholding,
                    iraDeductionAmount, medicalBenefitCost);


    return 0;

}

void get_userinput ()

{
    in_file.open ("employeeData.txt");
    if (in_file.fail())
{
      cerr << "unable to open input file" << endl;
      exit(1);
}
while(in_file>>n)
{
  if (n==0)
  {
   exit(0);
  
  }
  else
  {
   fin >> hourlyRate >> hoursWorked >> numDependants >> fullTime;

  }
   }

}


void calculate_overTimePay(int hoursWorked, double hourlyRate, double & basePay, int & overTimeHours, double & overTimePay,
                           int &doubleTimeHours, double &doubleTimePay, double &grossPay)
{
    grossPay = 0.0;
    overTimeHours = 0;
    overTimePay =0;
    doubleTimeHours = 0;
    doubleTimePay = 0;

    if(hoursWorked > 50)        // Test for double time
    {
        basePay = hourlyRate * 40;      // Base is rate * 40
        overTimeHours = 10;             // Time and a half hours =

        overTimePay = hourlyRate * 1.5 * overTimeHours;        //Calculate the Time and a Half
        doubleTimeHours = hoursWorked - 50;                    //Double Time Hours
        doubleTimePay = hourlyRate * 2 * doubleTimeHours;
    }
    else if (hoursWorked > 40)      // Test for time and a half overtime
    {
        basePay = hourlyRate * 40;              // Base is rate * 40
        overTimeHours = hoursWorked - 40;       // Overtime hours
        overTimePay = hourlyRate * 1.5 * overTimeHours;

    }
    else
        basePay = hoursWorked * hourlyRate;

    grossPay = basePay + overTimePay + doubleTimePay;


}

double ira_function (double grossPay) // This function calculates the IRA deduction based on gross pay

{
    double iraDeductionAmount;

    if(grossPay >= 500)
        iraDeductionAmount = grossPay * 0.10;

    else if (grossPay > 400)
        iraDeductionAmount = grossPay * 0.05;

    else
        iraDeductionAmount = 0;

    return(iraDeductionAmount);

}

double tax_withholding (int numDependants, double grossPay)        // This function calculates tax withholding

{
    double withholding;

    if (numDependants == 0)

        withholding = (grossPay * .28);

    else if (numDependants == 1)

        withholding = (grossPay * .2);

    else if (numDependants == 2)

        withholding = (grossPay * .18);

    else if (numDependants > 2)

        withholding = (grossPay * .15);


    return withholding;
}

double medical_cost_function (double netPay, int employmentStatus)

{
    double medicalBenefitCost = 0;

    if (employmentStatus == 1)

        medicalBenefitCost = netPay * .07;

    return (medicalBenefitCost);

}


void output_payroll (int hoursWorked, double hourlyRate, int overTimeHours, int doubleTimeHours, int numDependants,
                     double basePay, double grossPay, double modifiedgrossPay, double netPay, double overTimePay,
                     double doubleTimePay, double withholding, double iraDeductionAmount, double medicalBenefitCost)

{
    cout.setf(ios::fixed);   // use fixed only
    cout.setf(ios::showpoint); // display the decimal
    cout.precision(2); // display two decimal places


    // output section

    cout << "Hours worked =" << hoursWorked << endl;
    cout << "hourlyRate = $" << hourlyRate << endl;
    cout << "Base pay = $" << basePay << endl;
    cout << "Overtime hours =" << overTimeHours << endl;
    cout << "Overtime pay = $" << overTimePay << endl;
    cout << "Overtime hours at double time =" << doubleTimeHours << endl;
    cout << "Overtime pay at double time =" << doubleTimePay << endl;
    cout << "Gross Pay = $" << grossPay << endl;
    cout << "Your IRA deduction = " << iraDeductionAmount << endl;
    cout << "Your modified gross pay =" << modifiedgrossPay << endl;
    cout << "Withholding amount = $" << withholding << endl;
    cout << "Medical Benefits Cost = $" << medicalBenefitCost << endl;
    cout << "Net Pay = $" << netPay << endl;

    return;

}

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