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

4. An employee is paid at a rate of $16.78 per hour for regular hours worked in

ID: 3875675 • Letter: 4

Question

4. An employee is paid at a rate of $16.78 per hour for regular hours worked in a week. Any hours over that are paid at the overtime rate of one and one-half times that. From the worker’s gross pay, 6% is withheld for Social Security tax, 14% is withheld for federal income tax, 5% is withheld for state income tax, and $10 per week is withheld for union dues. If the worker has three or more dependents, then an additional $35 is withheld to cover the extra cost of health insurance beyond what the employer pays. Write a program that will read in the number of hours worked in a week and the number of dependents as input and that will then output the worker’s gross pay, each withholding amount, and the net take-home pay for the week.

Explanation / Answer

// CODE IN C++

#include<iostream>
using namespace std;

int main ( ) {

float regular_hours = 0.0, overtime_hours = 0.0;
float total_hours = 0.0,net_pay = 0.0, gross_pay = 0.0;
float social_security_tax = 0.0, federal_tax = 0.0, state_tax = 0.0;
int num_dependents;

//social security tax = 6%
const double SOCIAL_SECURITY_TAX= 0.06;

//fed income tax =14%
const double FEDERAL_TAX = 0.14;

//state tax = 5%
const double STATE_TAX = 0.05;
const double UNION_DUE = 10.00;
const double ADDITIONAL_DEPENDENT_CHARGES = 35.00;
const double PAY_RATE = 16.78;
const double OVERTIME_RATE = 1.5;
const int MAX_REG_HOURS = 40;

//get input fromuser
cout << "Please enter the total number of hours worked: ";
cin >> total_hours;

cout << "Please enter the number of dependents: ";
cin >> num_dependents;
cout << endl << endl;

//calculate numberof ot hours
//if total hours > 40 ot hours = total - 40
if(total_hours >MAX_REG_HOURS) {
overtime_hours = total_hours - MAX_REG_HOURS;
regular_hours = MAX_REG_HOURS;
} else {
regular_hours = total_hours;
}

//calculate grosspay
gross_pay = regular_hours * PAY_RATE + (overtime_hours * (PAY_RATE *OVERTIME_RATE));

//calculate soc tax
social_security_tax = gross_pay * SOCIAL_SECURITY_TAX;

//calculate fed tax
federal_tax = gross_pay * FEDERAL_TAX;

//calc state tax
state_tax = gross_pay * STATE_TAX;

//calculate netpay
net_pay = gross_pay - social_security_tax - federal_tax - state_tax - UNION_DUE;

if(num_dependents>= 3){
net_pay = net_pay - ADDITIONAL_DEPENDENT_CHARGES;
}

//Set precision
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << "EMPLOYEE SALARY DETAILS: " << endl;
cout << "Gross pay = $" << gross_pay << endl;
cout << "Social Security Tax = $" << social_security_tax << endl;
cout << "Federal Tax = $" << federal_tax << endl;
cout << "State Tax = $" << state_tax << endl;
cout << "Union Dues = $" << UNION_DUE << endl;

if(num_dependents >= 3){
cout << "Depend health = $" << ADDITIONAL_DEPENDENT_CHARGES << endl;
}

cout << "Net pay = $" << net_pay << endl;

return 0;
}

=========================================================
// SAMPLE OUTPUT
Please enter the total number of hours worked: 8
Please enter the number of dependents: 2


EMPLOYEE SALARY DETAILS:
Gross pay = $134.24
Social Security Tax = $8.05
Federal Tax = $18.79
State Tax = $6.71
Union Dues = $10.00
Net pay = $90.68

Process returned 0 (0x0) execution time : 5.277 s
Press any key to continue.

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