1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
//#include <stdio.h>
#include <iostream>
//#include <cstdlib>
#include <iomanip>
//#include <string>
//#include <ctime>
//#include <cmath>
//#include <fstream>
using namespace std;
int main(int argc, const char * argv[])
{
int Worker = 5;
//Declare Array Variable
double empID[Worker];
char payrollType[Worker];
double hoursWorked[Worker];
double payRate[Worker];
double unionCode[Worker];
double overtimePay[Worker];
double grossPay[Worker];
double stateTax[Worker];
double federalTax[Worker];
double totalTax[Worker];
double unionDues[Worker];
double netPay[Worker];
double regularPay[Worker];
double totalEmployees[1] = {};
double totalGrossPay[1] = {};
double totalNetPay[1] = {};
double employees[Worker];
double averageGrossPay[Worker];
double averageNetPay[Worker];
double highestGrossPay[Worker];
double lowestGrossPay[Worker];
void getInput (double[], char[], double[], double[], double[], double[], double[], double[], double);
void doCalculations (double [], double[], double[], double[], double[], double[],
double[], double[],double[],double[], double[], double[], double[], double);
void displayEmployeeResults(double empID[], double overtimePay[], double grossPay[], double stateTax[],
double federalTax[], double totalTax[],double unionDues[], double netPay[],
double regularPay[],double hoursWorked[], double payRate[], double unionCode[],
int Worker, char payrollType[]);
void displayPayrollSummaryResults(double empID[], double totalGrossPay[], double totalNetpay[],
double averageGrossPay[], double highestGrossPay[], double lowestGrossPay[],
double averageNetPay[], int Worker);
getInput(empID, payrollType, hoursWorked, payRate, unionDues, unionCode, totalEmployees, employees, Worker);
doCalculations(overtimePay, grossPay, stateTax, federalTax, totalTax, unionDues, netPay, regularPay,
hoursWorked, payRate, unionCode, totalGrossPay, totalNetPay, Worker);
displayEmployeeResults(empID, overtimePay, grossPay, stateTax,
federalTax, totalTax, unionDues, netPay,
regularPay, hoursWorked, payRate, unionCode,
Worker, payrollType);
displayPayrollSummaryResults( empID, totalGrossPay, totalNetPay, averageGrossPay, highestGrossPay,
lowestGrossPay, averageNetPay, Worker);
return 0;
}
void getInput(int empID[], char payrollType[], double hoursWorked[], double payRate[], int unionCode[],
double employees[] )
{
int ID = 0;
int Worker = 0;
cout << "Enter Employee ID number\n";
//emplyees numbers are from 100-800 only.
// must add something to signify that that is all of the employees the user wants to add.
cin >> empID[ID];
while((empID[ID]) < 100 || (empID[ID])> 800)
{ //Validation of employee number. Employee numbers must be between 100-800.
cout << "Invalid Input\n";
cout << "Enter Employee ID number from 100-800\n";
cin >> empID[ID];
}
cout << "Enter Payroll type\n";
cin >> payrollType[ID];
while ((payrollType[ID]) != 'h' && (payrollType[ID]) != 'H') { // Validation of payroll type. Payroll type must be 'H' or 'h'.
// Must add swith statement so 'h' or 'H' can be used as input.
cout << "Invalid Input\n";
cout << "Enter employee's payroll type";
cin >> payrollType[ID];
}
cout << "Enter the number of hours the emplyee has worked\n";
cin >> hoursWorked[ID];
while ((hoursWorked[ID]) < 0 || (hoursWorked[ID]) > 60.0 ) { // Validation of hours worked. They must be between 0-60.0.
cout << "Invalid Input\n";
cout << "Enter the number of hours worked by employee\n";
cin >> hoursWorked[ID];
}
cout << "What is the employees pay rate? \n";
cin >> payRate[ID];
while ((payRate[ID]) < 8.50 || ( payRate[ID] )> 45.00 ) { // Validation of employee's pay rate.
cout << "Invalid Input\n";
cout << "Enter the employee's correct pay rate\n";
cin >> payRate[ID];
}
cout << "What is the employee's union code?\n";
cin >> unionCode[ID];
while (unionCode[ID] != 1 && unionCode[ID] != 2 && unionCode[ID] != 3) { // Validation of employee's union code.
cout << "Invalid input\n";
cout << "Enter the employee's correct union code\n";
cin >> unionCode[ID];
}
ID++;
Worker++;
char moreToAdd;
cout << "Are there any more employees you would like to add?\n";
cout << "Press y for yes";
cin >> moreToAdd;
while (moreToAdd != 'y' && moreToAdd != 'Y') {
cout << "\nAre there any more employees you would like to add?\n";
employees[0] = Worker++;
}
cout << "Total Employees Entered: " << Worker << endl;
cout << "Employee ID: " << empID << endl;
} // End getInput function.
void doCalculations(double overtimePay[], double grossPay[], double stateTax[], double federalTax[],
double totalTax[], double unionDues[], double netPay[], double regularPay[],
double hoursWorked[], double payRate[], double unionCode[], double totalGrossPay[],
double totalNetPay[], int Worker[], double employeeGrossPay[])
{
// initialize Variables
int ID = 0;
double totalGross = 0;
double totalNet = 0;
for(int ID = 0; ID < 5; ID++)
if ((hoursWorked[ID]) > 40) {
regularPay[ID] = payRate[ID] * 40;
overtimePay[ID] = (1.5 * payRate[ID]) * (hoursWorked[ID] - 40.0);
grossPay[ID] = regularPay[ID] + overtimePay[ID];
}
if ((hoursWorked[ID]) < 40) {
regularPay[ID] = payRate[ID] * hoursWorked[ID];
overtimePay[ID] = 0;
grossPay[ID] = regularPay[ID];
}
// State tax
if ((grossPay[ID]) < 500 ) {
stateTax[ID] = 0;
}
if ((grossPay[ID]) > 500 && (grossPay[ID]) < 1000) {
stateTax[ID] = .03;
}
if ((grossPay[ID]) > 1000) {
stateTax[ID] = .05;
}
// Federal Tax
if ((grossPay[ID]) < 500 ) {
federalTax[ID] = 0;
}
if ((grossPay[ID]) > 500 && (grossPay[ID]) < 1000) {
federalTax[ID] = .05;
}
if ((grossPay[ID]) > 1000) {
federalTax[ID] = .07;
}
// Total Tax and Net Pay
for(int ID = 0; ID < 5; ID++)
totalTax[ID] = stateTax[ID] + federalTax[ID];
for(int ID = 0; ID < 5; ID++)
netPay[ID] = grossPay[ID] - stateTax[ID] - federalTax[ID] - unionDues[ID];
|