Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.70 KB | None | 0 0
  1. // James Gallagher
  2. // Cs 215 Section 010
  3. // Project 2: Payroll
  4. //Description: This program is deisnged to recieve and process information about a companies payroll and print a comprehensive report
  5.  
  6. #include <iostream>
  7. #include <string>
  8. #include <iomanip>
  9. using namespace std;
  10. //-----Print:Logo-----
  11. void PrintLogo()
  12. {
  13. cout << "+---------------------------------+" << "\n"
  14. << "| James Gallagher's Propane |" << "\n"
  15. << "| and Propane accessories |" << "\n"
  16. << "| Kevin Joiner Sec 10 |" << "\n"
  17. << "+---------------------------------+";
  18. }
  19. //-----Ask:Num-----
  20. float asknumemployees(float & num_emplyees)
  21. {
  22. do {
  23. cout << "\n" << "Number of empoyees: ";
  24. cin >> num_emplyees;
  25. if (num_emplyees < 1)
  26. {
  27. cout << "Invalid: Enter a number greater than 1";
  28. }
  29. } while (num_emplyees < 1);
  30. return num_emplyees;
  31. }
  32. //-----Ask:Resident-----
  33. string AskResident(string& employee_resident)
  34. {
  35. do {
  36. cout << " Local Resident (Y/N)?: ";
  37. cin >> employee_resident;
  38. if (employee_resident == "Y" || employee_resident == "y" || employee_resident == "N" || employee_resident == "n")
  39. {
  40. return employee_resident;
  41. }
  42. else
  43. {
  44. cout << "Invalid: Please enter (Y/N)" << "\n";
  45. }
  46. } while (employee_resident != "Y" && employee_resident != "y" && employee_resident != "N" && employee_resident != "n");
  47. }
  48. //-----Ask:type-----
  49. string Askemployee_type(string& employee_type)
  50. {
  51. do {
  52. cout << " Hourly or Salaried (H/S)?: ";
  53. cin >> employee_type;
  54. if (employee_type == "H" || employee_type == "h" || employee_type == "S" || employee_type == "s")
  55. {
  56. return employee_type;
  57. }
  58. else
  59. {
  60. cout << "INVALID: Enter H or S";
  61. }
  62. } while (employee_type != "H" && employee_type != "h" && employee_type != "S" && employee_type != "s");
  63. }
  64. //-----Calc:State-----
  65. float CalcStateTax(float gross_pay)
  66. {
  67. float state_tax_total = 0;
  68. const float state_income_tax = .06;
  69. if (gross_pay > 500)
  70. {
  71. state_tax_total = gross_pay - 500;
  72. state_tax_total = gross_pay * state_income_tax;
  73. }
  74. return state_tax_total;
  75. }
  76. //-----Calc:Local-----
  77. float CalcLocalTax(float gross_pay, string employee_resident)
  78. {
  79. float local_tax_total = 0;
  80. if ((employee_resident == "y") || (employee_resident == "Y"))
  81. {
  82. local_tax_total = gross_pay * 0.015;
  83. }
  84. if ((employee_resident == "n") || (employee_resident == "N"))
  85. {
  86. local_tax_total = gross_pay * 0.01;
  87. }
  88. return local_tax_total;
  89. }
  90. //-----Calc:Fed-----
  91. float calcFedTax(float gross_pay)
  92. {
  93. float fed_tax_total = 0;
  94. if (gross_pay < 600) {
  95. fed_tax_total = 0;
  96. }
  97. else if ((gross_pay <= 799.99) && (gross_pay >= 600)) {
  98. fed_tax_total = gross_pay * 0.04;
  99. }
  100. else if ((gross_pay <= 1099.99) && (gross_pay >= 800)) {
  101. fed_tax_total = gross_pay * 0.08;
  102. }
  103. else {
  104. fed_tax_total = gross_pay * 0.12;
  105. }
  106. return fed_tax_total;
  107. }
  108. //-----Hourly-----
  109. float GetHourlyGross(float hourly_rate, float hours_worked)
  110. {
  111. float overtime = 40;
  112. float hourlyGross = 0;
  113. if (hours_worked <= 40)
  114. {
  115. hourlyGross = hourly_rate * hours_worked;
  116. }
  117. if (hours_worked > 40)
  118. {
  119. hourlyGross = (40 + ((hours_worked - 40) * 1.5)) * hourly_rate;
  120. }
  121. return hourlyGross;
  122. }
  123. //-----Update-----
  124. float updateTotals(float net_total, float fed_tax_total, float state_tax_total, float local_tax_total, float social_sec_tax, float & Final_social_sec, float & Final_fed_tax, float & Final_local_tax, float & Final_state_tax, float & Final_net_due)
  125. {
  126. Final_fed_tax = Final_fed_tax + fed_tax_total;
  127. Final_net_due = Final_net_due + net_total;
  128. Final_state_tax = Final_state_tax + state_tax_total;
  129. Final_local_tax = Final_local_tax + local_tax_total;
  130. Final_social_sec = Final_social_sec + social_sec_tax;
  131. return Final_social_sec;
  132. }
  133. //-----Print:Stub-----
  134. void printstub(string first_name, string last_name, float gross_pay, float fed_tax_total, float state_tax_total, float local_tax_total, float social_sec_tax, float totaltaxes, float net_total)
  135. {
  136. cout << "\n" << "--------James Gallagher's Company Paystub--------" << "\n";
  137. cout << setprecision(2) << "Name: " << first_name << " " << last_name << "\n";
  138. cout << setprecision(2) << fixed << "Gross Pay: $" << gross_pay << "\n";
  139. cout << setprecision(2) << "Federal Tax: $" << fed_tax_total << "\n";
  140. cout << setprecision(2) << "State Tax: $" << state_tax_total << "\n";
  141. cout << setprecision(2) << "Local Tax: $" << local_tax_total << "\n";
  142. cout << setprecision(2) << "Socail Security Tax: $" << social_sec_tax << "\n";
  143. cout << setprecision(2) << "Total Taxes: $" << totaltaxes << "\n";
  144. cout << setprecision(2) << fixed << "Net Total: $" << net_total << "\n";
  145. }
  146. //-----PRint:Report-----
  147. void PrintReport(float Final_social_sec, float Final_fed_tax, float Final_local_tax, float Final_state_tax, float Final_net_due)
  148. {
  149. cout << "--------------PAYROLL REPORT--------------" << "\n";
  150. cout << "Total pay to Employees : " << Final_net_due << "\n";
  151. cout << "Total pay to Federals : " << Final_fed_tax << "\n";
  152. cout << "Total pay to SSI : " << Final_social_sec << "\n";
  153. cout << "Total pay to State : " << Final_state_tax << "\n";
  154. cout << "Total pay to Local : " << Final_local_tax << "\n";
  155. cout << "------------------------------------------" << "\n";
  156. }
  157. //-----PROCESS-----
  158. void ProcessEmployee(int num_employees, float & Final_social_sec, float & Final_fed_tax, float & Final_local_tax, float & Final_state_tax, float & Final_net_due)
  159. {
  160. string first_name, last_name, employee_type, employee_resident;
  161. float counter = 0, hourly_rate = 0, hours_worked = 0, weeklySalary = 0, hourlyGross = 0, gross_pay = 0, fed_tax_total = 0, local_tax_total = 0, state_tax_total = 0, social_sec_tax = 0, totalTaxes = 0, net_total = 0, employeeStateTotal = 0, employee_net_total = 0, employee_fed_total = 0, employee_local_total = 0, employeeSSITotal = 0;
  162. for (counter; counter < num_employees; counter++)
  163. {
  164. cout << "----------------------------" << "\n";
  165. cout << " Enter Data for Employee " << setprecision(0) << counter + 1 << "\n";
  166. cout << " Name (first last): ";
  167. cin >> first_name >> last_name;
  168. Askemployee_type(employee_type);
  169. if (employee_type == "H" || employee_type == "h")
  170. {
  171. cout << " Hourly rate: ";
  172. cin >> hourly_rate;
  173. cout << " Hours worked this period: ";
  174. cin >> hours_worked;
  175. }
  176. if (employee_type == "S" || employee_type == "s")
  177. {
  178. cout << " Weekly Salary: ";
  179. cin >> weeklySalary;
  180. }
  181. AskResident(employee_resident);
  182. if (employee_type == "H" || employee_type == "h")
  183. {
  184. hourlyGross = GetHourlyGross(hourly_rate, hours_worked);
  185. gross_pay = hourlyGross + 0;
  186. }
  187. if (employee_type == "S" || employee_type == "s")
  188. {
  189. gross_pay = weeklySalary + 0;
  190. }
  191. fed_tax_total = calcFedTax(gross_pay);
  192. local_tax_total = CalcLocalTax(gross_pay, employee_resident);
  193. state_tax_total = CalcStateTax(gross_pay);
  194. social_sec_tax = gross_pay * 0.03;
  195. totalTaxes = fed_tax_total + state_tax_total + local_tax_total + social_sec_tax;
  196. net_total = gross_pay - totalTaxes;
  197. printstub(first_name, last_name, gross_pay, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, totalTaxes, net_total);
  198.  
  199.  
  200. Final_social_sec = updateTotals(net_total, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
  201. Final_fed_tax = updateTotals(net_total, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
  202. Final_local_tax = updateTotals(net_total, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
  203. Final_state_tax = updateTotals(net_total, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
  204. Final_net_due = updateTotals(net_total, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
  205. }
  206. cout << "\n";
  207. PrintReport(employeeStateTotal, employee_net_total, employee_fed_total, employee_local_total, employeeSSITotal);
  208. counter = counter + 1;
  209. }
  210. //-----MAIN-----
  211. void main()
  212. {
  213. float num_employees = 0;
  214. const float State_income_tax = .06;
  215. const float social_sec_tax = .03;
  216. float Final_social_sec = 0;
  217. float Final_fed_tax = 0;
  218. float Final_local_tax = 0;
  219. float Final_state_tax = 0;
  220. float Final_net_due = 0;
  221. PrintLogo();
  222. num_employees = asknumemployees(num_employees);
  223. ProcessEmployee(num_employees, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
  224. system("pause");
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement