Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Programming: help calculating average pay So I just need to calculate the average pay for all employees entered. Somehow I keep getting $0 for

C++ Programming: help calculating average pay

So I just need to calculate the average pay for all employees entered. Somehow I keep getting "$0" for average pay

#include #include

using namespace std; class payroll { char employeessn[100]; char firstname[100]; char lastname[100]; int hoursworked, overtime, i; double hourlyrate, overtimepay, overtimepaycalc, taxrate, regpay, grosspay, taxamount, netpay, sum; double averagepay = 0; void calculategrosspay(); void calculatetaxamount(); void calculatenetpay(); void calculateaveragepay(); int numEmp;//memory needed for the array

public: void printheadings();//public method to be able to called in the main method void printdata(); public: payroll(); void printreport(); };

payroll::payroll() { //Gather the employee and payroll data cout << "First name: " << endl; cin >> firstname; cout << "Last name: " << endl; cin >> lastname; cout << "First three numbers of employee's ssn: " << endl; cin >> employeessn; cout << "Please enter the amount of hours worked: " << endl; cin >> hoursworked; cout << "Please enter in your hourly wage: $" << endl; cin >> hourlyrate;

} void payroll::calculategrosspay() { //calculate pay according to type grosspay = hoursworked * hourlyrate; if (hoursworked>40) { overtime = hoursworked - 40; regpay = 40 * hourlyrate; overtimepaycalc = hourlyrate * 1.5; overtimepay = overtime * overtimepaycalc; grosspay = overtimepay + regpay; } else { overtime = 0; regpay = 40 * hourlyrate; overtimepaycalc = hourlyrate * 1.5; overtimepay = overtime * overtimepaycalc; grosspay = overtimepay + regpay; } }; void payroll::calculatetaxamount() { if (grosspay >= 0) taxrate = .30; taxamount = grosspay * taxrate; } void payroll::calculatenetpay() { netpay = grosspay - taxamount; } void payroll::calculateaveragepay() { sum += netpay; averagepay = (sum / numEmp); } void payroll::printheadings() { cout << setw(45) << "-Payroll Report-" << endl; //calculating the average net pay of all the employee in that company. cout << "Average Net Pay of all the Employees : $ " << averagepay << endl; cout << "------------------------------------------------------------------------------------------------------" << endl; cout << "FirstName LastName SSN Hours Rate OThours OTpay REGpay GROSSpay Taxes NETpay" << endl; cout << "======== ========= ==== === ==== === ===== ====== ===== ==== =====" << endl; cout << "--------------------------------------------------------------------------------------------------------" << endl;

}; void payroll::printdata() { cout << setprecision(2) << fixed << left;//setiosflags (ios::fixed | ios::left); cout << setw(9) << firstname << setw(9) << lastname << setw(4) << " " << employeessn << setw(3) << " " << hoursworked << setw(5) << " " << hourlyrate << setw(4) << "" << overtime << setw(3) << "" << overtimepay << setw(4) << " " << regpay << setw(5) << " " << grosspay << setw(5) << "" << taxamount << setw(3) << "" << netpay << endl << endl; }

void payroll::printreport() { int i = 0; calculategrosspay(); calculatetaxamount(); calculatenetpay(); calculateaveragepay(); printdata(); i++; }

int main(void) { int numEmp;//memory needed for the array cout << "Enter the number of Employees: "; cin >> numEmp; payroll *employee = new payroll[numEmp];//pointer used with the array employee[0].printheadings(); for (int i = 0; i

}

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions

Question

Write formal and informal proposals.

Answered: 1 week ago