fork download
  1. //********************************************************
  2. //
  3. // Assignment 7 - Structures and Strings
  4. //
  5. // Name: Anthony Principe
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: 11/2/2025
  10. //
  11. // Description: Program which determines overtime and
  12. // gross pay for a set of employees with outputs sent
  13. // to standard output (the screen).
  14. //
  15. // This assignment also adds the employee name, their tax state,
  16. // and calculates the state tax, federal tax, and net pay. It
  17. // also calculates totals, averages, minimum, and maximum values.
  18. //
  19. // Call by Reference design
  20. //
  21. //********************************************************
  22.  
  23. // necessary header files
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27.  
  28. // define constants
  29. #define SIZE 5
  30. #define STD_HOURS 40.0
  31. #define OT_RATE 1.5
  32. #define MA_TAX_RATE 0.05
  33. #define NH_TAX_RATE 0.0
  34. #define VT_TAX_RATE 0.06
  35. #define CA_TAX_RATE 0.07
  36. #define DEFAULT_TAX_RATE 0.08
  37. #define NAME_SIZE 20
  38. #define TAX_STATE_SIZE 3
  39. #define FED_TAX_RATE 0.25
  40. #define FIRST_NAME_SIZE 10
  41. #define LAST_NAME_SIZE 10
  42.  
  43. // Define a structure type to store an employee name
  44. struct name {
  45. char firstName[FIRST_NAME_SIZE];
  46. char lastName[LAST_NAME_SIZE];
  47. };
  48.  
  49. // Define a structure type to pass employee data between functions
  50. struct employee {
  51. struct name empName;
  52. char taxState[TAX_STATE_SIZE];
  53. long int clockNumber;
  54. float wageRate;
  55. float hours;
  56. float overtimeHrs;
  57. float grossPay;
  58. float stateTax;
  59. float fedTax;
  60. float netPay;
  61. };
  62.  
  63. // totals
  64. struct totals {
  65. float total_wageRate;
  66. float total_hours;
  67. float total_overtimeHrs;
  68. float total_grossPay;
  69. float total_stateTax;
  70. float total_fedTax;
  71. float total_netPay;
  72. };
  73.  
  74. // min/max
  75. struct min_max {
  76. float min_wageRate;
  77. float min_hours;
  78. float min_overtimeHrs;
  79. float min_grossPay;
  80. float min_stateTax;
  81. float min_fedTax;
  82. float min_netPay;
  83. float max_wageRate;
  84. float max_hours;
  85. float max_overtimeHrs;
  86. float max_grossPay;
  87. float max_stateTax;
  88. float max_fedTax;
  89. float max_netPay;
  90. };
  91.  
  92. // Function prototypes
  93. void getHours(struct employee employeeData[], int theSize);
  94. void calcOvertimeHrs(struct employee employeeData[], int theSize);
  95. void calcGrossPay(struct employee employeeData[], int theSize);
  96. void calcStateTax(struct employee employeeData[], int theSize);
  97. void calcFedTax(struct employee employeeData[], int theSize);
  98. void calcNetPay(struct employee employeeData[], int theSize);
  99. struct totals calcEmployeeTotals(struct employee employeeData[],
  100. struct totals employeeTotals, int theSize);
  101. struct min_max calcEmployeeMinMax(struct employee employeeData[],
  102. struct min_max employeeMinMax, int theSize);
  103. void printHeader(void);
  104. void printEmp(struct employee employeeData[], int theSize);
  105. void printEmpStatistics(struct totals employeeTotals,
  106. struct min_max employeeMinMax, int theSize);
  107.  
  108. //********************************************************
  109.  
  110. // Used the template to fill in tax and totals logic and tested input hours.
  111. int main() {
  112.  
  113. struct employee employeeData[SIZE] = {
  114. { {"Connie", "Cobol"}, "MA", 98401, 10.60},
  115. { {"Mary", "Apl"}, "NH", 526488, 9.75 },
  116. { {"Frank", "Fortran"}, "VT", 765349, 10.50 },
  117. { {"Jeff", "Ada"}, "NY", 34645, 12.25 },
  118. { {"Anton", "Pascal"}, "CA",127615, 8.35 }
  119. };
  120.  
  121. struct totals employeeTotals = {0,0,0,0,0,0,0};
  122. struct min_max employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  123.  
  124. getHours(employeeData, SIZE);
  125. calcOvertimeHrs(employeeData, SIZE);
  126. calcGrossPay(employeeData, SIZE);
  127. calcStateTax(employeeData, SIZE);
  128. calcFedTax(employeeData, SIZE);
  129. calcNetPay(employeeData, SIZE);
  130.  
  131. employeeTotals = calcEmployeeTotals(employeeData, employeeTotals, SIZE);
  132. employeeMinMax = calcEmployeeMinMax(employeeData, employeeMinMax, SIZE);
  133.  
  134. printHeader();
  135. printEmp(employeeData, SIZE);
  136. printEmpStatistics(employeeTotals, employeeMinMax, SIZE);
  137.  
  138. return 0;
  139. }
  140.  
  141. //********************************************************
  142. void getHours(struct employee employeeData[], int theSize) {
  143. int i;
  144. for(i = 0; i < theSize; i++) {
  145. printf("\nEnter hours worked by emp # %06li: ", employeeData[i].clockNumber);
  146. scanf("%f", &employeeData[i].hours);
  147. }
  148. }
  149.  
  150. //********************************************************
  151. void printHeader(void) {
  152. printf("\n\n*** Pay Calculator ***\n");
  153. printf("\n---------------------------------------------------------------------------------");
  154. printf("\nName Tax Clock# Wage Hours OT Gross State Fed Net");
  155. printf("\n State Pay Tax Tax Pay");
  156. printf("\n---------------------------------------------------------------------------------");
  157. }
  158.  
  159. //********************************************************
  160. void printEmp(struct employee employeeData[], int theSize) {
  161. int i;
  162. char name[FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
  163.  
  164. for(i = 0; i < theSize; i++) {
  165. strcpy(name, employeeData[i].empName.firstName);
  166. strcat(name, " ");
  167. strcat(name, employeeData[i].empName.lastName);
  168.  
  169. printf("\n%-19s %-3s %06li %7.2f %5.1f %5.1f %7.2f %7.2f %7.2f %8.2f",
  170. name, employeeData[i].taxState, employeeData[i].clockNumber,
  171. employeeData[i].wageRate, employeeData[i].hours,
  172. employeeData[i].overtimeHrs, employeeData[i].grossPay,
  173. employeeData[i].stateTax, employeeData[i].fedTax,
  174. employeeData[i].netPay);
  175. }
  176. }
  177.  
  178. //********************************************************
  179. void calcOvertimeHrs(struct employee employeeData[], int theSize) {
  180. int i;
  181. for(i = 0; i < theSize; i++) {
  182. if(employeeData[i].hours > STD_HOURS)
  183. employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
  184. else
  185. employeeData[i].overtimeHrs = 0;
  186. }
  187. }
  188.  
  189. //********************************************************
  190. void calcGrossPay(struct employee employeeData[], int theSize) {
  191. int i;
  192. float theNormalPay;
  193. float theOvertimePay;
  194.  
  195. for(i = 0; i < theSize; i++) {
  196. theNormalPay = employeeData[i].wageRate *
  197. (employeeData[i].hours - employeeData[i].overtimeHrs);
  198. theOvertimePay = employeeData[i].overtimeHrs *
  199. (OT_RATE * employeeData[i].wageRate);
  200.  
  201. employeeData[i].grossPay = theNormalPay + theOvertimePay;
  202. }
  203. }
  204.  
  205. //********************************************************
  206. void calcStateTax(struct employee employeeData[], int theSize) {
  207. int i;
  208. for(i = 0; i < theSize; i++) {
  209.  
  210. if(strcmp(employeeData[i].taxState, "MA") == 0)
  211. employeeData[i].stateTax = employeeData[i].grossPay * MA_TAX_RATE;
  212. else if(strcmp(employeeData[i].taxState, "NH") == 0)
  213. employeeData[i].stateTax = employeeData[i].grossPay * NH_TAX_RATE;
  214. else if(strcmp(employeeData[i].taxState, "VT") == 0)
  215. employeeData[i].stateTax = employeeData[i].grossPay * VT_TAX_RATE;
  216. else if(strcmp(employeeData[i].taxState, "CA") == 0)
  217. employeeData[i].stateTax = employeeData[i].grossPay * CA_TAX_RATE;
  218. else
  219. employeeData[i].stateTax = employeeData[i].grossPay * DEFAULT_TAX_RATE;
  220. }
  221. }
  222.  
  223. //********************************************************
  224. void calcFedTax(struct employee employeeData[], int theSize) {
  225. int i;
  226. for(i = 0; i < theSize; i++) {
  227. employeeData[i].fedTax = employeeData[i].grossPay * FED_TAX_RATE;
  228. }
  229. }
  230.  
  231. //********************************************************
  232. void calcNetPay(struct employee employeeData[], int theSize) {
  233. int i;
  234. for(i = 0; i < theSize; i++) {
  235. employeeData[i].netPay =
  236. employeeData[i].grossPay - (employeeData[i].stateTax + employeeData[i].fedTax);
  237. }
  238. }
  239.  
  240. //********************************************************
  241. struct totals calcEmployeeTotals(struct employee employeeData[],
  242. struct totals employeeTotals, int theSize) {
  243. int i;
  244. for(i = 0; i < theSize; i++) {
  245. employeeTotals.total_wageRate += employeeData[i].wageRate;
  246. employeeTotals.total_hours += employeeData[i].hours;
  247. employeeTotals.total_overtimeHrs += employeeData[i].overtimeHrs;
  248. employeeTotals.total_grossPay += employeeData[i].grossPay;
  249. employeeTotals.total_stateTax += employeeData[i].stateTax;
  250. employeeTotals.total_fedTax += employeeData[i].fedTax;
  251. employeeTotals.total_netPay += employeeData[i].netPay;
  252. }
  253. return employeeTotals;
  254. }
  255.  
  256. //********************************************************
  257. struct min_max calcEmployeeMinMax(struct employee employeeData[],
  258. struct min_max employeeMinMax, int theSize) {
  259. int i;
  260.  
  261. employeeMinMax.min_wageRate = employeeData[0].wageRate;
  262. employeeMinMax.min_hours = employeeData[0].hours;
  263. employeeMinMax.min_overtimeHrs = employeeData[0].overtimeHrs;
  264. employeeMinMax.min_grossPay = employeeData[0].grossPay;
  265. employeeMinMax.min_stateTax = employeeData[0].stateTax;
  266. employeeMinMax.min_fedTax = employeeData[0].fedTax;
  267. employeeMinMax.min_netPay = employeeData[0].netPay;
  268.  
  269. employeeMinMax.max_wageRate = employeeData[0].wageRate;
  270. employeeMinMax.max_hours = employeeData[0].hours;
  271. employeeMinMax.max_overtimeHrs = employeeData[0].overtimeHrs;
  272. employeeMinMax.max_grossPay = employeeData[0].grossPay;
  273. employeeMinMax.max_stateTax = employeeData[0].stateTax;
  274. employeeMinMax.max_fedTax = employeeData[0].fedTax;
  275. employeeMinMax.max_netPay = employeeData[0].netPay;
  276.  
  277. for(i = 1; i < theSize; i++) {
  278.  
  279. if(employeeData[i].wageRate < employeeMinMax.min_wageRate)
  280. employeeMinMax.min_wageRate = employeeData[i].wageRate;
  281. if(employeeData[i].wageRate > employeeMinMax.max_wageRate)
  282. employeeMinMax.max_wageRate = employeeData[i].wageRate;
  283.  
  284. if(employeeData[i].hours < employeeMinMax.min_hours)
  285. employeeMinMax.min_hours = employeeData[i].hours;
  286. if(employeeData[i].hours > employeeMinMax.max_hours)
  287. employeeMinMax.max_hours = employeeData[i].hours;
  288.  
  289. if(employeeData[i].overtimeHrs < employeeMinMax.min_overtimeHrs)
  290. employeeMinMax.min_overtimeHrs = employeeData[i].overtimeHrs;
  291. if(employeeData[i].overtimeHrs > employeeMinMax.max_overtimeHrs)
  292. employeeMinMax.max_overtimeHrs = employeeData[i].overtimeHrs;
  293.  
  294. if(employeeData[i].grossPay < employeeMinMax.min_grossPay)
  295. employeeMinMax.min_grossPay = employeeData[i].grossPay;
  296. if(employeeData[i].grossPay > employeeMinMax.max_grossPay)
  297. employeeMinMax.max_grossPay = employeeData[i].grossPay;
  298.  
  299. if(employeeData[i].stateTax < employeeMinMax.min_stateTax)
  300. employeeMinMax.min_stateTax = employeeData[i].stateTax;
  301. if(employeeData[i].stateTax > employeeMinMax.max_stateTax)
  302. employeeMinMax.max_stateTax = employeeData[i].stateTax;
  303.  
  304. if(employeeData[i].fedTax < employeeMinMax.min_fedTax)
  305. employeeMinMax.min_fedTax = employeeData[i].fedTax;
  306. if(employeeData[i].fedTax > employeeMinMax.max_fedTax)
  307. employeeMinMax.max_fedTax = employeeData[i].fedTax;
  308.  
  309. if(employeeData[i].netPay < employeeMinMax.min_netPay)
  310. employeeMinMax.min_netPay = employeeData[i].netPay;
  311. if(employeeData[i].netPay > employeeMinMax.max_netPay)
  312. employeeMinMax.max_netPay = employeeData[i].netPay;
  313. }
  314.  
  315. return employeeMinMax;
  316. }
  317.  
  318. //********************************************************
  319. void printEmpStatistics(struct totals employeeTotals,
  320. struct min_max employeeMinMax, int theSize) {
  321.  
  322. printf("\n---------------------------------------------------------------------------------");
  323.  
  324. printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %7.2f %7.2f %8.2f",
  325. employeeTotals.total_wageRate,
  326. employeeTotals.total_hours,
  327. employeeTotals.total_overtimeHrs,
  328. employeeTotals.total_grossPay,
  329. employeeTotals.total_stateTax,
  330. employeeTotals.total_fedTax,
  331. employeeTotals.total_netPay );
  332.  
  333. printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %7.2f %7.2f %8.2f",
  334. employeeTotals.total_wageRate/theSize,
  335. employeeTotals.total_hours/theSize,
  336. employeeTotals.total_overtimeHrs/theSize,
  337. employeeTotals.total_grossPay/theSize,
  338. employeeTotals.total_stateTax/theSize,
  339. employeeTotals.total_fedTax/theSize,
  340. employeeTotals.total_netPay/theSize );
  341.  
  342. printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %7.2f %7.2f %8.2f",
  343. employeeMinMax.min_wageRate,
  344. employeeMinMax.min_hours,
  345. employeeMinMax.min_overtimeHrs,
  346. employeeMinMax.min_grossPay,
  347. employeeMinMax.min_stateTax,
  348. employeeMinMax.min_fedTax,
  349. employeeMinMax.min_netPay );
  350.  
  351. printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %7.2f %7.2f %8.2f\n",
  352. employeeMinMax.max_wageRate,
  353. employeeMinMax.max_hours,
  354. employeeMinMax.max_overtimeHrs,
  355. employeeMinMax.max_grossPay,
  356. employeeMinMax.max_stateTax,
  357. employeeMinMax.max_fedTax,
  358. employeeMinMax.max_netPay );
  359. }
  360.  
Success #stdin #stdout 0s 5316KB
stdin
51.0
42.5
37.0
45.0
40.0
stdout
Enter hours worked by emp # 098401: 
Enter hours worked by emp # 526488: 
Enter hours worked by emp # 765349: 
Enter hours worked by emp # 034645: 
Enter hours worked by emp # 127615: 

*** Pay Calculator ***

---------------------------------------------------------------------------------
Name                Tax  Clock#  Wage   Hours  OT   Gross   State  Fed      Net
                    State                           Pay     Tax    Tax      Pay
---------------------------------------------------------------------------------
Connie Cobol        MA  098401   10.60  51.0  11.0  598.90   29.95  149.73   419.23
Mary Apl            NH  526488    9.75  42.5   2.5  426.56    0.00  106.64   319.92
Frank Fortran       VT  765349   10.50  37.0   0.0  388.50   23.31   97.12   268.07
Jeff Ada            NY  034645   12.25  45.0   5.0  581.88   46.55  145.47   389.86
Anton Pascal        CA  127615    8.35  40.0   0.0  334.00   23.38   83.50   227.12
---------------------------------------------------------------------------------
Totals:                          51.45 215.5  18.5 2329.84  123.18  582.46  1624.19
Averages:                        10.29  43.1   3.7  465.97   24.64  116.49   324.84
Minimum:                          8.35  37.0   0.0  334.00    0.00   83.50   227.12
Maximum:                         12.25  51.0  11.0  598.90   46.55  149.73   419.23