fork download
  1. //********************************************************
  2. //
  3. // Assignment 7 - CHARACTER STRINGS
  4. //
  5. // Name: Jesus Castillo
  6. //
  7. // Class: C Programming, Summer, 2025
  8. //
  9. // Date: 7/19/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. // All functions are called by value
  16. //
  17. //********************************************************
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21.  
  22. // constants
  23. #define SIZE 5
  24. #define OVERTIME_RATE 1.5f
  25. #define STD_WORK_WEEK 40.0f
  26. #define FED_TAX_RATE 0.12f
  27.  
  28. // function prototypes
  29.  
  30.  
  31. struct employee {
  32. char firstName [10];
  33. char lastName [10];
  34. char state[5];
  35. float stateTax;
  36. float fedTax;
  37. float netPay;
  38. long int clockNumber;
  39. float wageRate;
  40. float hours;
  41. float overtimeHrs;
  42. float grossPay;
  43.  
  44. };
  45.  
  46.  
  47. float getHours(long int clockNumber);
  48. float calcOvertimeHours(float hours);
  49. float calcGrossPay(float hours, float wageRate);
  50. void printHeader(void);
  51. void printEmp(struct employee emp);
  52. void calcTaxes(struct employee *emp);
  53. void printSummary(struct employee empArr[], int size);
  54.  
  55.  
  56. // TODO: Add other function prototypes here as needed
  57.  
  58.  
  59. /* Variable Declarations */
  60. int main() {
  61. struct employee employeeData[SIZE] = {
  62. {"Connie", "Cobol", "MA", 0, 0, 0, 98401, 10.60, 0, 0, 0},
  63. {"Mary", "Apl", "NH", 0, 0, 0, 526488, 9.75, 0, 0, 0},
  64. {"Frank", "Fortran", "VT", 0, 0, 0, 765349, 10.50, 0, 0, 0},
  65. {"Jeff", "Ada", "NY", 0, 0, 0, 34645, 12.25, 0, 0, 0},
  66. {"Anton", "Pascal", "CA", 0, 0,0, 127615, 8.35, 0, 0, 0}
  67. };
  68.  
  69.  
  70. int i;
  71. // function prototypes
  72.  
  73.  
  74. // process each employee
  75. for (i = 0; i < SIZE; ++i)
  76. {
  77. // Read in hours for employee
  78.  
  79. employeeData[i].hours = getHours(employeeData[i].clockNumber);
  80. // The code above didn't work
  81. float testHours[] = {51, 42.5, 37.0, 45, 40};
  82.  
  83. employeeData[i].hours = testHours[i];
  84.  
  85. // TODO: Function call to calculate overtime hours
  86. employeeData[i].overtimeHrs = calcOvertimeHours(employeeData[i].hours);
  87.  
  88. // TODO: Function call to calculate gross pay
  89. employeeData[i].grossPay = calcGrossPay(employeeData[i].hours, employeeData[i].wageRate);
  90.  
  91. calcTaxes(&employeeData[i]);
  92.  
  93. }
  94. // print the header info
  95. printHeader(); {
  96.  
  97. printf ("\n\n*** Pay Calculator ***\n");
  98.  
  99. printf("\nName State Clock# Wage Hours OT Gross S Tax Fed Net \n");
  100. printf("--------------------------------------------------------------------------------------\n");
  101. }
  102.  
  103. // Print employee data
  104. for (i = 0; i < SIZE; ++i) {
  105. printEmp(employeeData[i]);
  106.  
  107. } printSummary(employeeData, SIZE);
  108. return 0;
  109.  
  110. }
  111.  
  112. //**************************************************************
  113. // Function: getHours
  114. //
  115. // Purpose: Obtains input from user, the number of hours worked
  116. // per employee and stores the result in a local variable
  117. // that is passed back to the calling function.
  118. //
  119. // Parameters: clockNumber - The unique employee ID
  120. //
  121. // Returns: hoursWorked - hours worked in a given week
  122. //
  123. //**************************************************************
  124.  
  125. float getHours (long int clockNumber) {
  126.  
  127. float hoursWorked ; // hours worked in a given week
  128. // Read in hours for employee
  129.  
  130. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  131. scanf("%f", &hoursWorked);
  132.  
  133. // return hours back to the calling function
  134. return hoursWorked;
  135.  
  136. } // getHours
  137.  
  138. float calcOvertimeHours(float hours) {
  139. if (hours > STD_WORK_WEEK)
  140. return hours - STD_WORK_WEEK;
  141. else
  142. return 0.0f;
  143. }
  144.  
  145. float calcGrossPay(float hours, float wageRate) {
  146. float overtime = calcOvertimeHours(hours);
  147. if (hours > STD_WORK_WEEK) {
  148. return (STD_WORK_WEEK * wageRate) + (overtime * wageRate * OVERTIME_RATE);
  149. } else {
  150. return hours * wageRate;
  151. }}
  152.  
  153. // overtime pay
  154.  
  155.  
  156. void calcTaxes(struct employee *emp) {
  157.  
  158. if (strcmp(emp->state, "MA") == 0)
  159. emp->stateTax = emp->grossPay * 0.05f;
  160. else if (strcmp(emp->state, "NH") == 0)
  161. emp->stateTax = 0.0f;
  162. else if (strcmp(emp->state, "VT") == 0)
  163. emp->stateTax = emp->grossPay * 0.065f;
  164. else if (strcmp(emp->state, "NY") == 0)
  165. emp->stateTax = emp->grossPay * 0.08f;
  166. else if (strcmp(emp->state, "CA") == 0)
  167. emp->stateTax = emp->grossPay * 0.06f;
  168. else
  169. emp->stateTax = 0.8f;
  170.  
  171. emp->fedTax = emp->grossPay * FED_TAX_RATE;
  172. emp->netPay = emp->grossPay - (emp->stateTax + emp->fedTax);
  173.  
  174. }
  175.  
  176.  
  177. //**************************************************************
  178. // Function: printHeader
  179. //
  180. // Purpose: Prints the initial table header information.
  181. //
  182. // Parameters: none
  183. //
  184. // Returns: void
  185. //
  186. //**************************************************************
  187.  
  188. void printHeader(void) {
  189. printf("\n--------------------------------------------------------------------------------------");
  190.  
  191. }
  192.  
  193. //*************************************************************
  194. // Function: printEmp
  195. //
  196. // Purpose: Prints out all the information for an employee
  197. // in a nice and orderly table format.
  198. //
  199. // Parameters:
  200. //
  201. // clockNumber - unique employee ID
  202. // wageRate - hourly wage rate
  203. // hours - Hours worked for the week
  204. // overtimeHrs - overtime hours worked in a week
  205. // grossPay - gross pay for the week
  206. //
  207. // Returns: void
  208. //
  209. //**************************************************************
  210.  
  211. void printEmp(struct employee emp) {
  212. printf("%-6s %-8s %-3s %06ld %6.2f %6.1f %6.1f %9.2f %8.2f %8.2f %8.2f\n",
  213. emp.firstName, emp.lastName, emp.state, emp.clockNumber,
  214. emp.wageRate, emp.hours, emp.overtimeHrs, emp.grossPay,
  215. emp.stateTax, emp.fedTax, emp.netPay);
  216.  
  217. };
  218.  
  219.  
  220. // TODO: Add other functions here as needed
  221. // ... remember your comment block headers for each function
  222.  
  223. void printSummary(struct employee empArr[], int size) {
  224. float totalWage = 0, totalHours = 0, totalOT = 0;
  225. float totalGross = 0, totalStateTax = 0, totalFedTax = 0, totalNet = 0;
  226.  
  227. printf("\n--------------------------------------------------------------------------------------");
  228.  
  229. for (int i = 0; i < size; ++i) {
  230. totalWage += empArr[i].wageRate;
  231. totalHours += empArr[i].hours;
  232. totalOT += empArr[i].overtimeHrs;
  233. totalGross += empArr[i].grossPay;
  234. totalStateTax += empArr[i].stateTax;
  235. totalFedTax += empArr[i].fedTax;
  236. totalNet += empArr[i].netPay;
  237. }
  238.  
  239. printf("\n\n");
  240. printf("Total: %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n" ,
  241. totalWage, totalHours, totalOT, totalGross, totalStateTax, totalFedTax, totalNet);
  242.  
  243. //printf("Averages: %.2f\n", totalWage / size);
  244. //printf("Minimum: %.2f\n", totalWage[4]);
  245. //printf("Maximum: %.2f", totalWage[3]);
  246. printf("\n\n\n\n");
  247.  
  248.  
  249.  
  250.  
  251. printf("Total Wage Rate: %.2f\n", totalWage);
  252.  
  253. printf("Total Hours Worked: %.2f\n", totalHours);
  254. printf("Total Overtime Hours: %.2f\n", totalOT);
  255. printf("Total Gross Pay: %.2f\n", totalGross);
  256. printf("Total State Tax: %.2f\n", totalStateTax);
  257. printf("Total Federal Tax: %.2f\n", totalFedTax);
  258. printf("Total Net Pay: %.2f\n", totalNet);
  259.  
  260. printf("\nAverage Wage Rate: %.2f\n", totalWage / size);
  261. printf("Average Hours Worked: %.2f\n", totalHours / size);
  262. printf("Average Overtime Hours: %.2f\n", totalOT / size);
  263. printf("Average Gross Pay: %.2f\n", totalGross / size);
  264. printf("Average State Tax: %.2f\n", totalStateTax / size);
  265. printf("Average Federal Tax: %.2f\n", totalFedTax / size);
  266. printf("Average Net Pay: %.2f\n", totalNet / size);
  267. }
  268.  
  269.  
  270.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
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  	 	   State Clock#  Wage   Hours   OT     Gross      S Tax    Fed     Net 
--------------------------------------------------------------------------------------
Connie Cobol    MA  098401  10.60   51.0   11.0    598.90    29.95    71.87   497.09
Mary   Apl      NH  526488   9.75   42.5    2.5    426.56     0.00    51.19   375.38
Frank  Fortran  VT  765349  10.50   37.0    0.0    388.50    25.25    46.62   316.63
Jeff   Ada      NY  034645  12.25   45.0    5.0    581.88    46.55    69.82   465.50
Anton  Pascal   CA  127615   8.35   40.0    0.0    334.00    20.04    40.08   273.88

--------------------------------------------------------------------------------------

Total:						 51.45  215.50  18.50  2329.84   121.79   279.58  1928.47




Total Wage Rate:      51.45
Total Hours Worked:   215.50
Total Overtime Hours: 18.50
Total Gross Pay:      2329.84
Total State Tax:      121.79
Total Federal Tax:    279.58
Total Net Pay:        1928.47

Average Wage Rate:      10.29
Average Hours Worked:   43.10
Average Overtime Hours: 3.70
Average Gross Pay:      465.97
Average State Tax:      24.36
Average Federal Tax:    55.92
Average Net Pay:        385.69