Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help C++. I need this to be a payroll in C++ to look normal. this is what I have so far. use structures and arrays

help C++. I need this to be a payroll in C++ to look normal. this is what I have so far. use structures and arrays only. no functions. help

#include #include #include using namespace std; const double STATE_TAX_RATE = 0.06; const double FED_TAX_RATE = 0.12; const double UNION_FEE_RATE = 0.02;

int main() {

const int n = 2; struct Employees { string firstName[n]; string lastName[n]; char middleInitial[n]; double hoursWorked[n]; double payRate[n]; double grossIncome[n]; double overtime[n]; double stateTax[n]; double fedTax[n]; double unionFees[n]; double netIncome[n]; } worker;

Employees employees [n];

for (int i = 0; i < n; i++) { cout << "Enter information for Employee " << i+1 << ":" << endl; cout << "Enter first name: "; cin >> worker.firstName[i]; cout << "Enter last name: "; cin >> worker.lastName[i]; cout << "Enter middle initial: "; cin >> worker.middleInitial[i]; cout << "Enter hours worked: "; cin >> worker.hoursWorked[i]; if (worker.hoursWorked[i] > 40) { worker.overtime[i] = (worker.hoursWorked[i] - 40) * worker.payRate[i] * 1.5; worker.grossIncome[i] = worker.payRate[i] * 40 + worker.overtime[i]; } else { worker.overtime[i] = 0; worker.grossIncome[i] = worker.payRate[i] * worker.hoursWorked[i]; } cout << "Enter pay rate: "; cin >> worker.payRate[i];

worker.stateTax[i] = worker.grossIncome[i] * STATE_TAX_RATE; worker.fedTax[i] = worker.grossIncome[i] * FED_TAX_RATE; worker.unionFees[i] = worker.grossIncome[i] * UNION_FEE_RATE; worker.netIncome[i] = worker.grossIncome[i] - (worker.stateTax[i] + worker.fedTax[i] + worker.unionFees[i]);

cout << "Company Payroll" << endl; cout << setw(10) << left << "First" << " "; cout << setw(2) << left << "MI" << " "; cout << setw(10) << left << "Last" << " "; cout << setw(6) << right << "Rate/hour" << " "; cout << setw(12) << right << "HoursWorked" << " "; cout << setw(12) << right << "Gross" << " "; cout << setw(12) << right << "Net" << endl; cout << "==============================================================" << endl;

for (int i = 0; i < n; i ++){ cout << setw(10) << left << worker.firstName[i] << " " << setw(2) << left << worker.middleInitial[i] << ". " << setw(10) << left << worker.lastName[i] << " " << setw(6) << right << fixed << setprecision(2) << worker.payRate[i] << " " << setw(12) << right << fixed << setprecision(2) << worker.hoursWorked[i] << " " << setw(12) << right << fixed << setprecision(2) << worker.grossIncome[i] << " " << setw(12) << right << fixed << setprecision(2) << worker.netIncome[i] << endl; }

double totalGross = 0; for (int i = 0; i < n; i++) { totalGross += worker.grossIncome[n]; double averageGross = totalGross / n; } cout << endl; cout << "Total Gross for all employees: $" << fixed << setprecision(2) << totalGross << endl; return 0; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the difference between amplitude and intensity?

Answered: 1 week ago