SHOW:
|
|
- or go back to the newest paste.
1 | #include <cstdlib> | |
2 | #include <iostream> | |
3 | #include <iomanip> | |
4 | #include <cmath> | |
5 | ||
6 | using namespace std; | |
7 | ||
8 | //declare function prototypes | |
9 | void displayWelcomeMessage(); | |
10 | void getInput(double *EmployeeID, double *hoursWorked, double *payRate, char *unionCode, char A, char B, char C, double *regularPay, double *overtimePay); | |
11 | double calculateGrossPay(double *grossPay, double regularPay, double overtimePay); | |
12 | void calculateFederalTax(double grossPay, double *federalTax, double *paidTax); | |
13 | void calculateUnionDues(char unionCode, double *unionDues); | |
14 | double calculateNetPay(double *netPay, double grossPay, double paidTax, double unionDues); | |
15 | void displayEmployeeInputInfo(double employeeID, double hoursWorked, double payRate, char unionCode); | |
16 | void displayEmployeeCalculationResults(double regularPay, double overtimePay, double grossPay, double federalTax, double unionDues, double netPay); | |
17 | void displayPayrollSummaryInfo(int numEmployees, double totalGrossPay, double highestGrossPayEmployeeID, double highestGrossPay, double lowestGrossPayEmployeeID, double lowestGrossPay, double averageGrossPay); | |
18 | - | void displaylowGrossID(double lowAverageID[]); |
18 | + | void displaylowGrossID(double lowAverageID[], double grossPay[]); |
19 | void displayTerminationMessage(); | |
20 | ||
21 | //initialize the program | |
22 | int main() | |
23 | { | |
24 | displayWelcomeMessage(); | |
25 | // local variable declarations | |
26 | int numEmployees = 0; //number of employees processed | |
27 | double totalGrossPay = 0; //total gross pay | |
28 | double highestGrossPay = 0; //highest gross pay | |
29 | double highestGrossPayEmployeeID = 0; //counter to identify employeeID with highest gross pay | |
30 | double lowestGrossPay = std::numeric_limits<double>::infinity(); //lowest gross pay | |
31 | double lowestGrossPayEmployeeID = 0; //counter to identify employeeID with lowest gross pay | |
32 | double averageGrossPay;//average gross pay is totalgrosspay / numemployees | |
33 | double lowAverageID[4]; //Employees whose gross pay is less than average | |
34 | double employeeID[5]; // employee's ID number | |
35 | double hoursWorked[5]; // number of hours employee worked | |
36 | double payRate[5]; // employee's pay rate | |
37 | char unionCode[5]; // employee's one character union code | |
38 | char A = 'A'; // unionCode A | |
39 | char B = 'B'; //unionCode B | |
40 | char C = 'C'; //unionCode C | |
41 | double regularPay[5]; // if hoursWorked <=40 then regular pay = hoursWorked * payRate | |
42 | double overtimePay[5]; // if hoursWorked >40 then over times pay = 1.5 * (hoursWorked - 40) * payRate | |
43 | double grossPay[5]; // gross pay is hoursWorked times payRate | |
44 | double federalTax[5]; // amount of tax employee pays based on grossPay | |
45 | double paidTax[5]; // paidTax is grossPay - netPay | |
46 | double unionDues[5]; // dues paid based on unionCode | |
47 | double netPay[5]; // netPay is grossPay - (grossPay * federalTax) | |
48 | ||
49 | - | for (int x = 1; x <=2; x++) // loop program 2 times |
49 | + | for (int x = 0; x < 5; x++) // loop program 2 times |
50 | { | |
51 | //functions | |
52 | getInput(&employeeID[x], &hoursWorked[x], &payRate[x], &unionCode[x], A, B, C, ®ularPay[x], &overtimePay[x]); | |
53 | calculateGrossPay(&grossPay[x], regularPay[x], overtimePay[x]); | |
54 | calculateFederalTax(grossPay[x], &federalTax[x], &paidTax[x]); | |
55 | calculateUnionDues(unionCode[x], &unionDues[x]); | |
56 | calculateNetPay(&netPay[x], grossPay[x], paidTax[x], unionDues[x]); | |
57 | displayEmployeeInputInfo(employeeID[x], hoursWorked[x], payRate[x], unionCode[x]); | |
58 | displayEmployeeCalculationResults(regularPay[x], overtimePay[x], grossPay[x], paidTax[x], unionDues[x], netPay[x]); | |
59 | ||
60 | numEmployees++; //counter for number of employees to process | |
61 | - | totalGrossPay += grossPay[numEmployees]; //counter for total gross pay |
61 | + | totalGrossPay += grossPay[x]; //counter for total gross pay |
62 | averageGrossPay = totalGrossPay / numEmployees; | |
63 | //highest gross pay employee ID | |
64 | if( grossPay[x] > highestGrossPay ) | |
65 | { | |
66 | highestGrossPay = grossPay[x]; | |
67 | highestGrossPayEmployeeID = employeeID[x]; | |
68 | } | |
69 | //lowest gross pay employee id | |
70 | if( grossPay[x] < lowestGrossPay ) | |
71 | { | |
72 | lowestGrossPay = grossPay[x]; | |
73 | lowestGrossPayEmployeeID = employeeID[x]; | |
74 | } | |
75 | - | //employees with lower than average gross pay |
75 | + | |
76 | } | |
77 | //employees with lower than average gross pay | |
78 | for (int x = 0; x < 5; x++){ | |
79 | - | } |
79 | + | |
80 | { | |
81 | lowAverageID[x] = employeeID[x]; | |
82 | } | |
83 | } | |
84 | - | displaylowGrossID(lowAverageID); |
84 | + | |
85 | displayPayrollSummaryInfo(numEmployees, totalGrossPay, highestGrossPayEmployeeID, highestGrossPay, lowestGrossPayEmployeeID, lowestGrossPay, averageGrossPay); | |
86 | //display employees with below average gross pay | |
87 | displaylowGrossID(lowAverageID, grossPay); | |
88 | //display termination message | |
89 | displayTerminationMessage(); | |
90 | ||
91 | system("PAUSE"); | |
92 | return 0; | |
93 | } | |
94 | //function definitions | |
95 | // Welcome message | |
96 | void displayWelcomeMessage() | |
97 | { | |
98 | std::cout << "My Payroll Calculator\n\n\n"; | |
99 | } | |
100 | //get inputs from user | |
101 | void getInput(double *EmployeeID, double *hoursWorked, double *payRate, char *unionCode, char A, char B, char C, double *regularPay, double *overtimePay) | |
102 | { | |
103 | std::cout << "EmployeeID: "; //request user input for EmployeeID | |
104 | std::cin >> *EmployeeID; // read input from user into employeeID | |
105 | std::cout << "Hours worked: "; // request user input for hoursWorked | |
106 | std::cin >> *hoursWorked; // read input from user into hoursWorked | |
107 | while (*hoursWorked <0 || *hoursWorked > 60) // only allow input from 0-60 | |
108 | { | |
109 | std::cout << "Error! You must enter a value between 0 and 60\n"; | |
110 | std::cout << "Hours worked: "; | |
111 | std::cin >> *hoursWorked; | |
112 | } | |
113 | std::cout << "Pay rate: "; // request user input for payRate | |
114 | std::cin >> *payRate; // read input from user into payrate | |
115 | while (*payRate <7.50 || *payRate > 45.00) //only allow input from 7.50 - 45.00 | |
116 | { | |
117 | std::cout << "Error! You must enter a value between 7.50 and 45.00\n"; | |
118 | std::cout << "Pay rate: "; | |
119 | std::cin >> *payRate; | |
120 | } | |
121 | std::cout << "Union code A, B, or C? "; // request user input for unionCode | |
122 | std::cin >> *unionCode; // read input from user into unionCode | |
123 | while (*unionCode !=A && *unionCode !=B && *unionCode !=C) //only allow input A, B, or C | |
124 | { | |
125 | std::cout << "Error! Your code must be A, B, or C\n"; | |
126 | std::cout << "Union code: "; | |
127 | std::cin >> *unionCode; | |
128 | } | |
129 | *regularPay = *hoursWorked * *payRate; // calculate regularPay | |
130 | *overtimePay = 1.5 * ( *hoursWorked - 40 ) * *payRate; // calculate overtimePay | |
131 | if ( *hoursWorked <= 40) *overtimePay = 0;//determine if there is overtime pay or not | |
132 | if ( *hoursWorked > 40) *regularPay = *payRate * 40; | |
133 | } | |
134 | // calculate grossPay | |
135 | double calculateGrossPay(double *grossPay, double regularPay, double overtimePay) | |
136 | { | |
137 | *grossPay = regularPay + overtimePay; | |
138 | return *grossPay; | |
139 | } | |
140 | // calculate paidTax | |
141 | void calculateFederalTax(double grossPay, double *federalTax, double *paidTax) | |
142 | { | |
143 | if ( grossPay > 2000 ) *federalTax = .25; // determine federal tax rate | |
144 | else if ( grossPay >= 1000 ) *federalTax = .15; | |
145 | else *federalTax = .1; | |
146 | *paidTax = grossPay * *federalTax; | |
147 | } | |
148 | // calculate unionDues | |
149 | void calculateUnionDues(char unionCode, double *unionDues) | |
150 | { | |
151 | switch (unionCode) | |
152 | { | |
153 | case 'A': *unionDues = 25; | |
154 | break; | |
155 | case 'B': *unionDues = 50; | |
156 | break; | |
157 | case 'C': *unionDues = 75; | |
158 | break; | |
159 | } | |
160 | } | |
161 | // calculate netPay | |
162 | double calculateNetPay(double *netPay, double grossPay, double paidTax, double unionDues) | |
163 | { | |
164 | *netPay = grossPay - paidTax - unionDues; | |
165 | return *netPay; | |
166 | } | |
167 | //display employee input info | |
168 | void displayEmployeeInputInfo(double employeeID, double hoursWorked, double payRate, char unionCode) | |
169 | { | |
170 | std::cout << "\nIdentification Number: " << employeeID; //display employeeID | |
171 | std::cout << "\nHours Worked: " << hoursWorked; //display hoursWorked | |
172 | std::cout << "\nPay Rate: " << payRate; //display payRate | |
173 | std::cout << "\nUnion Code: " << unionCode; //display unionCode | |
174 | } | |
175 | //display employee calculation results | |
176 | void displayEmployeeCalculationResults(double regularPay, double overtimePay, double grossPay, double federalTax, double unionDues, double netPay) | |
177 | { | |
178 | std::cout << fixed << setprecision(2); //format output to 2 decimal places | |
179 | std::cout << "\nRegular Pay: " << regularPay; //display regularPay | |
180 | std::cout << "\nOvertime Pay: " << overtimePay; // display overtimePay | |
181 | std::cout << "\nGross Pay: " << grossPay; // display grossPay | |
182 | std::cout << "\nFederal Tax: " << federalTax; // display federalTax | |
183 | std::cout << "\nUnion Dues: " << unionDues; // display unionDues | |
184 | std::cout << "\nNet Pay: " << netPay; // display netPay | |
185 | std::cout << fixed << setprecision(0); //format output to 0 decimal places | |
186 | std::cout << "\n\n"; | |
187 | } | |
188 | //display payroll summary info | |
189 | void displayPayrollSummaryInfo(int numEmployees, double totalGrossPay, double highestGrossPayEmployeeID, double highestGrossPay, double lowestGrossPayEmployeeID, double lowestGrossPay, double averageGrossPay) | |
190 | { | |
191 | std::cout << "\nEmployees Processed: " << numEmployees; //display number of employees processed | |
192 | std::cout << fixed << setprecision(2); //format output to 2 decimal places | |
193 | std::cout << "\nTotal Gross Pay: " << totalGrossPay; //display total gross pay | |
194 | std::cout << fixed << setprecision(0); //format output to 0 decimal places | |
195 | std::cout << "\nEmployee With Highest Gross Pay: " << highestGrossPayEmployeeID; //display ID of employee with highest gross pay | |
196 | std::cout << fixed << setprecision(2); //format output to 2 decimal places | |
197 | std::cout << "\nHighest Gross Pay: " << highestGrossPay; //display highest gross pay | |
198 | std::cout << fixed << setprecision(0); //format output to 0 decimal places | |
199 | std::cout << "\nEmployee With Lowest Gross Pay: " << lowestGrossPayEmployeeID; //display ID of employee with lowest gross pay | |
200 | std::cout << fixed << setprecision(2); //format output to 2 decimal places | |
201 | std::cout << "\nLowest Gross Pay: " << lowestGrossPay; //display lowest gross pay | |
202 | std::cout << "\nAverage Gross Pay: " << averageGrossPay; //display average gross pay | |
203 | - | void displaylowGrossID(double lowAverageID[]) |
203 | + | std::cout << fixed << setprecision(0); |
204 | std::cout << "\n"; | |
205 | - | for (int x = 1; x <= 4; x++) |
205 | + | |
206 | //display employess with below average gross pay | |
207 | - | std::cout << "\nEmployees With Below Average Gross Pay: "; |
207 | + | void displaylowGrossID(double lowAverageID[], double grossPay[]) |
208 | - | std::cout << lowAverageID[x] << endl; |
208 | + | |
209 | std::cout << "\nEmployees With Below Average Gross Pay:\n"; | |
210 | for (int x = 0; x < lowAverageID[x]; x++) | |
211 | { | |
212 | cout << lowAverageID[x] << " -- $" << grossPay[x] << endl; | |
213 | } | |
214 | } | |
215 | //display termination message | |
216 | void displayTerminationMessage() | |
217 | { | |
218 | std::cout << "\nBest payroll calculator in the whole world\n\n"; // Termination message | |
219 | } |