The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 4 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Looking for help with an assignment. Â Basic C++ Programming, it's imperative it looks basic. Don't make it perfect, small errors are fine as long as it runs and works as it should. Â I attached the code from the last assignment as each assignment is an extension of the previous.
These are the chapters the assignment is based on:Â
Sorting:Â http://drebrahimi.com/chapter11.html
Inheritance: http://drebrahimi.com/chapter16.htmlÂ
Inheritance
Expand the Employee Payroll program to include hourly based and salary based employees. This phase uses an array of employee objects, inheritance for different classes of employees, and polymorphism for salary computation. The 52-week yearly salary, as well as number of overtime hours, worked by a salary based employee, is given). For salary based employees, to find the regular (gross) pay for a week, divide the salary by 52. To compute the overtime pay for a salary based employee, first find the hourly rate by dividing the gross pay by 40, and then compute overtime pay. For every employee, overtime pay, tax amount, and net pay must also be computed. In addition, the program should find the minimum and maximum net pay of all employees as well as sort the employees based on their net pay (ascending order).
Â
Â
#include <iostream>
#include <iomanip>
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;
void calculategrosspay();
void calculatetaxamount();
void calculatenetpay();
void calculateaveragepay();
static int numEmp;//memory needed for the array
public: void printheadings();//public method to be able to called in the main
method
void printdata();
static double averagepay;
static double sum;
public: payroll();
void printreport();
};
double payroll::averagepay = 0.0;
double payroll::sum = 0.0;
int payroll::numEmp = 0;
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 the 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) << "-Amanda's Payroll Report-" << 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() {
numEmp++;
calculategrosspay();
calculatetaxamount();
calculatenetpay();
calculateaveragepay();
printdata();
}
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<numEmp; i++) {
employee[i].printreport();//to print each employee
}
cout << "Average Net Pay of all the Employees : $ " << payroll::averagepay
<< endl;
delete employee; //frees memory used by array
system("PAUSE");
return 0;
}
-----------