Jump to content

Bit of a dump here, but my focus is on the printstub() function in the tester file and the functions that it uses, as for Total Deductions and Net Pay I get inf, and -inf respectively. I believe I am doing something wrong with passing data and not the calculations themselves but clearly I'm missing something so tell me whatever lol

 


// header

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
#include <iostream>
using namespace std;

class Employee
{
    public:
    Employee();
    Employee(string fir, string las, string ID);
    void setRegHoursWorked(double hrs);
    void setHourlyPay(double hrPay);
    void setOTHoursWorked(double hrs);
    void setMaritalStatus(string status);
    double calculateDeductions();
    double fedTax(string maritalStatus);
    double stateTax();
    double HealthIns();
    double SocSec();
    double medicare();
    string getFirstName();
    string getLastName();
    double getHoursWorked();
    double getOTHoursWorked();
    double getHourlyPay();
    string getMaritalStatus();
    string getIDnum();

    private:
    string firstName;
    string lastName;
    string IDnum;
    double hours;
    double OTHour;
    double hourPay;
    string maritalStatus;
    double fed_taxPer;
    double income;
    double state_taxPer;
    int health_money;
    double soc_sec;
    double med_care;
    double pay;
};

#endif // EMPLOYEE_H
 

 


// definitions

#include "Employee.h"

using namespace std;

    Employee::Employee()
    {
        firstName = "John";
        lastName = "Doe";
        IDnum = "000-00-0000";
    }
    Employee::Employee(string fir, string las, string ID)
    {
        firstName = fir;
        lastName = las;
        IDnum = ID;
    }
    void Employee::setRegHoursWorked(double hrs)
    {
        if (hrs > 80)
        {
        setOTHoursWorked(hrs - 80);
        hours = 80;
        }
        else
        {
        hours = hrs;
        }
    }
    void Employee::setHourlyPay(double hrPay)
    {
        hourPay = hrPay;

    }
    void Employee::setOTHoursWorked(double hrs)
    {
        OTHour = hrs;
    }
    void Employee::setMaritalStatus(string status)
    {
        maritalStatus = status;
    }

    double Employee::fedTax(string maritalStatus)
    {
        if (maritalStatus == "single")
        {
            if (income < 1230)
            {
                fed_taxPer = .1;
            }
            else
            {
                fed_taxPer = .35;
            }
        }
        else
        {
            if (income < 2461)
            {
                fed_taxPer = .1;
            }
            else
            {
                fed_taxPer = .35;
            }
        }
        return fed_taxPer;
    }
    double Employee::stateTax()
    {
        state_taxPer = .034;
        return state_taxPer;
    }
    double Employee::HealthIns()
    {
        int health_money;
        if (maritalStatus == "s")
        {
            health_money = 50;
        }
        else
        {
            health_money = 110;
        }
        return health_money;
    }
    double Employee::SocSec()
    {
        double soc_sec;
        soc_sec = .062;
        return soc_sec;
    }
    double Employee::medicare()
    {
        double med_care;
        med_care = .0145;
        return med_care;
    }
    string Employee::getFirstName()
    {
        return firstName;
    }
    string Employee::getLastName()
    {
        return lastName;
    }
    double Employee::getHoursWorked()
    {
        return hours;
    }
    double Employee::getOTHoursWorked()
    {
        return OTHour;
    }
    double Employee::getHourlyPay()
    {
        return hourPay;
    }
    string Employee::getMaritalStatus()
    {
        return maritalStatus;
    }
    string Employee::getIDnum()
    {
        return IDnum;
    }
        double Employee::calculateDeductions()
    {
        double pay_gross = hourPay * hours;
        pay_gross += 1.5 * OTHour * hourPay;
        double deductions = ((pay_gross * fedTax(maritalStatus)) + (pay_gross * state_taxPer) + (pay_gross * soc_sec) + (pay_gross * med_care));
        deductions -= HealthIns();
        return deductions;
    }
 

 


// tester/client

#include <iostream>
#include "Employee.h"
#include <string>
#include <iomanip>
using namespace std;


void printMenu()
{
    cout << "1. Set Marital Status of Employee" << endl << "2. Enter Pay Rate of Employee" << endl;
    cout << "3. Enter Hours Worked of Current Pay Period" << endl << "4. Print Pay Stub" << endl;
}

double grossPay(Employee employee1)
{
    double pay_gross = employee1.getHourlyPay() * employee1.getHoursWorked();
    pay_gross += 1.5 * employee1.getOTHoursWorked() * employee1.getHourlyPay();
    return pay_gross;
}

double total_hours(Employee employee1)
{
    double hours = employee1.getHoursWorked() + employee1.getOTHoursWorked();
    return hours;
}
double netPay(Employee employee1)
{
    double pay_net;
    pay_net = employee1.getHourlyPay() * employee1.getHoursWorked();
    pay_net += 1.5 * employee1.getOTHoursWorked() * employee1.getHourlyPay();
    pay_net -= employee1.calculateDeductions();
    return pay_net;
}

void printStub(Employee employee1)
{
 cout << "Employee Name: " << employee1.getFirstName() << " " << employee1.getLastName() << endl;
 cout << "Employee ID#: " << employee1.getIDnum() << endl << endl;
 cout << "Hours Worked                 Gross Pay      Total Deductions      Net Pay" << endl;
 cout << setw(12) << total_hours(employee1) << "     " << grossPay(employee1) << "     " << employee1.calculateDeductions() << "     " ;
 cout << setw(12) << netPay(employee1) << endl;
}

int main ()
{
int choice;
string firstName;
string lastName;
string IDnum;
string maritalStatus;
double payRate;
double hoursWorked;

cout << "Enter first name of employee: ";
cin >> firstName;
cout << endl << "Enter last name of employee: ";
cin >> lastName;
cout << endl;
cout << "Enter Employee ID Number (ex. 000-00-0000): ";
cin >> IDnum;
cout << endl;

Employee employee1(firstName, lastName, IDnum);

cout << "Enter a choice, or press x to exit." << endl << endl;
printMenu();
while (cin >> choice)
{
 if (choice == 1)
 {
     cout << "Enter marital status: (single or married): " << endl;
     cin >> maritalStatus;
     employee1.setMaritalStatus(maritalStatus);
     printMenu();

 }
 else if (choice == 2)
 {
     cout << "Enter the employee's pay rate: ";
     cin >> payRate;
     employee1.setHourlyPay(payRate);
     printMenu();
 }
 else if (choice == 3)
 {
     cout << "Enter Hours Worked in Current Pay Period: ";
     cin >> hoursWorked;
     employee1.setRegHoursWorked(hoursWorked);
     printMenu();
 }
else
{
    printStub(employee1);
    cout << endl << endl;
    cout << "Press any key to return to menu..." << endl;
    cin >> choice;
    printMenu();
}
}

    return 0;
}
 

rubber dome apologist

Link to comment
https://linustechtips.com/topic/783406-calculating-payment-school-assignment-help/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×