fork download
  1. //********************************************************
  2. //
  3. // Assignment 7 - Structures and Strings
  4. //
  5. // Name: Jacquelin saint Lucien
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: <replace with the current date>
  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. #include <stdio.h>
  23. #include <string.h>
  24.  
  25. #define NAME_LEN 10
  26. #define STATE_LEN 3
  27. #define MAX_EMPLOYEES 5
  28.  
  29. // Structure to hold first and last name
  30. struct name {
  31. char firstName[NAME_LEN];
  32. char lastName[NAME_LEN];
  33. };
  34.  
  35. // Structure to hold employee info
  36. struct employee {
  37. struct name empName;
  38. char taxState[STATE_LEN];
  39. long int clockNumber;
  40. float wageRate;
  41. float hours;
  42. float overTimeHrs;
  43. float grossPay;
  44. float stateTax;
  45. float fedTax;
  46. float netPay;
  47. };
  48.  
  49. // Function prototypes
  50. float computeStateTaxRate(char state[]);
  51. float findMin(float values[], int n);
  52. float findMax(float values[], int n);
  53. float findAverage(float values[], int n);
  54. float findTotal(float values[], int n);
  55.  
  56. int main(void)
  57. {
  58. struct employee employees[MAX_EMPLOYEES];
  59. int i, count;
  60.  
  61. printf("Enter number of employees (max %d): ", MAX_EMPLOYEES);
  62. scanf("%d", &count);
  63.  
  64. // Input data
  65. for (i = 0; i < count; i++)
  66. {
  67. printf("\n--- Employee %d ---\n", i + 1);
  68. printf("First Name: ");
  69. scanf("%s", employees[i].empName.firstName);
  70. printf("Last Name: ");
  71. scanf("%s", employees[i].empName.lastName);
  72. printf("Clock Number: ");
  73. scanf("%ld", &employees[i].clockNumber);
  74. printf("State (MA, NH, VT, CA, or other): ");
  75. scanf("%s", employees[i].taxState);
  76. printf("Hourly Wage Rate: ");
  77. scanf("%f", &employees[i].wageRate);
  78. printf("Hours Worked: ");
  79. scanf("%f", &employees[i].hours);
  80. printf("Overtime Hours: ");
  81. scanf("%f", &employees[i].overTimeHrs);
  82.  
  83. // Compute gross pay (normal + overtime)
  84. employees[i].grossPay = (employees[i].wageRate * employees[i].hours) +
  85. (employees[i].wageRate * 1.5 * employees[i].overTimeHrs);
  86.  
  87. // State and federal taxes
  88. float stateRate = computeStateTaxRate(employees[i].taxState);
  89. employees[i].stateTax = employees[i].grossPay * stateRate;
  90. employees[i].fedTax = employees[i].grossPay * 0.25f;
  91.  
  92. // Net pay
  93. employees[i].netPay = employees[i].grossPay - (employees[i].stateTax + employees[i].fedTax);
  94. }
  95.  
  96. // Display report
  97. printf("\n\n------------------------------------------------------------\n");
  98. printf("CLOCK# NAME STATE GROSS STATE TAX FED TAX NET PAY\n");
  99. printf("------------------------------------------------------------\n");
  100. for (i = 0; i < count; i++)
  101. {
  102. printf("%06ld %-10s %-10s %-3s %8.2f %8.2f %8.2f %8.2f\n",
  103. employees[i].clockNumber,
  104. employees[i].empName.firstName,
  105. employees[i].empName.lastName,
  106. employees[i].taxState,
  107. employees[i].grossPay,
  108. employees[i].stateTax,
  109. employees[i].fedTax,
  110. employees[i].netPay);
  111. }
  112. printf("------------------------------------------------------------\n");
  113.  
  114. // Summary statistics arrays
  115. float grossArr[MAX_EMPLOYEES], stateArr[MAX_EMPLOYEES], fedArr[MAX_EMPLOYEES], netArr[MAX_EMPLOYEES];
  116.  
  117. for (i = 0; i < count; i++)
  118. {
  119. grossArr[i] = employees[i].grossPay;
  120. stateArr[i] = employees[i].stateTax;
  121. fedArr[i] = employees[i].fedTax;
  122. netArr[i] = employees[i].netPay;
  123. }
  124.  
  125. // Display summary
  126. printf("\n\n==================== SUMMARY STATISTICS ====================\n");
  127. printf("Category TOTAL AVG MIN MAX\n");
  128. printf("------------------------------------------------------------\n");
  129. printf("Gross Pay %10.2f %8.2f %8.2f %8.2f\n",
  130. findTotal(grossArr, count), findAverage(grossArr, count), findMin(grossArr, count), findMax(grossArr, count));
  131. printf("State Tax %10.2f %8.2f %8.2f %8.2f\n",
  132. findTotal(stateArr, count), findAverage(stateArr, count), findMin(stateArr, count), findMax(stateArr, count));
  133. printf("Fed Tax %10.2f %8.2f %8.2f %8.2f\n",
  134. findTotal(fedArr, count), findAverage(fedArr, count), findMin(fedArr, count), findMax(fedArr, count));
  135. printf("Net Pay %10.2f %8.2f %8.2f %8.2f\n",
  136. findTotal(netArr, count), findAverage(netArr, count), findMin(netArr, count), findMax(netArr, count));
  137. printf("------------------------------------------------------------\n");
  138.  
  139. return 0;
  140. }
  141.  
  142. // Function to compute state tax rate based on code
  143. float computeStateTaxRate(char state[])
  144. {
  145. if (strcmp(state, "MA") == 0) return 0.05f;
  146. else if (strcmp(state, "NH") == 0) return 0.00f;
  147. else if (strcmp(state, "VT") == 0) return 0.06f;
  148. else if (strcmp(state, "CA") == 0) return 0.07f;
  149. else return 0.08f;
  150. }
  151.  
  152. // Summary calculation functions
  153. float findTotal(float values[], int n)
  154. {
  155. float sum = 0.0f;
  156. for (int i = 0; i < n; i++)
  157. sum += values[i];
  158. return sum;
  159. }
  160.  
  161. float findAverage(float values[], int n)
  162. {
  163. return findTotal(values, n) / n;
  164. }
  165.  
  166. float findMin(float values[], int n)
  167. {
  168. float min = values[0];
  169. for (int i = 1; i < n; i++)
  170. if (values[i] < min) min = values[i];
  171. return min;
  172. }
  173.  
  174. float findMax(float values[], int n)
  175. {
  176. float max = values[0];
  177. for (int i = 1; i < n; i++)
  178. if (values[i] > max) max = values[i];
  179. return max;
  180. }
  181.  
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
Enter number of employees (max 5): 

------------------------------------------------------------
CLOCK#   NAME                STATE  GROSS     STATE TAX  FED TAX   NET PAY
------------------------------------------------------------
------------------------------------------------------------


==================== SUMMARY STATISTICS ====================
Category      TOTAL       AVG        MIN        MAX
------------------------------------------------------------
Gross Pay        0.00      -nan      0.00      0.00
State Tax        0.00      -nan  -1161438080.00  -1161438080.00
Fed Tax          0.00      -nan      0.00      0.00
Net Pay          0.00      -nan  122919352902693754223926530115761078272.00  122919352902693754223926530115761078272.00
------------------------------------------------------------