fork download
  1. //********************************************************
  2. //
  3. // Assignment 10 - Linked Lists, Typedef, and Macros
  4. //
  5. // Name: Heather Grothe
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: April 15, 2026
  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. // Array and Structure references have all been replaced with
  20. // pointer references to speed up the processing of this code.
  21. // A linked list has been created and deployed to dynamically
  22. // allocate and process employees as needed.
  23. //
  24. // It will also take advantage of the C Preprocessor features,
  25. // in particular with using macros, and will replace all
  26. // struct type references in the code with a typedef alias
  27. // reference.
  28. //
  29. // Call by Reference design (using pointers)
  30. //
  31. //********************************************************
  32.  
  33. // necessary header files
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <ctype.h> // for char functions
  37. #include <stdlib.h> // for malloc
  38.  
  39. // define constants
  40. #define STD_HOURS 40.0
  41. #define OT_RATE 1.5
  42. #define MA_TAX_RATE 0.05
  43. #define NH_TAX_RATE 0.0
  44. #define VT_TAX_RATE 0.06
  45. #define CA_TAX_RATE 0.07
  46. #define DEFAULT_STATE_TAX_RATE 0.08
  47. #define NAME_SIZE 20
  48. #define TAX_STATE_SIZE 3
  49. #define FED_TAX_RATE 0.25
  50. #define FIRST_NAME_SIZE 10
  51. #define LAST_NAME_SIZE 10
  52.  
  53. // define macros
  54. #define CALC_OT_HOURS(theHours) ((theHours > STD_HOURS) ? theHours - STD_HOURS : 0)
  55. #define CALC_STATE_TAX(thePay,theStateTaxRate) (thePay * theStateTaxRate)
  56. #define CALC_FED_TAX(thePay) (thePay * FED_TAX_RATE)
  57. #define CALC_NET_PAY(thePay,theStateTax,theFedTax) (thePay - (theStateTax + theFedTax))
  58. #define CALC_NORMAL_PAY(theWageRate,theHours,theOvertimeHrs) \
  59. (theWageRate * (theHours - theOvertimeHrs))
  60. #define CALC_OT_PAY(theWageRate,theOvertimeHrs) (theOvertimeHrs * (OT_RATE * theWageRate))
  61. #define CALC_MIN(theValue, currentMin) ((theValue < currentMin) ? theValue : currentMin)
  62. #define CALC_MAX(theValue, currentMax) ((theValue > currentMax) ? theValue : currentMax)
  63.  
  64. // Define a global structure type to store an employee name
  65. struct name
  66. {
  67. char firstName[FIRST_NAME_SIZE];
  68. char lastName [LAST_NAME_SIZE];
  69. };
  70.  
  71. // Define a global structure type to pass employee data between functions
  72. typedef struct employee
  73. {
  74. struct name empName;
  75. char taxState [TAX_STATE_SIZE];
  76. long int clockNumber;
  77. float wageRate;
  78. float hours;
  79. float overtimeHrs;
  80. float grossPay;
  81. float stateTax;
  82. float fedTax;
  83. float netPay;
  84. struct employee * next;
  85. } EMPLOYEE;
  86.  
  87. // This structure type defines the totals of all floating point items
  88. // so they can be totaled and used also to calculate averages
  89.  
  90. typedef struct totals
  91. {
  92. float total_wageRate;
  93. float total_hours;
  94. float total_overtimeHrs;
  95. float total_grossPay;
  96. float total_stateTax;
  97. float total_fedTax;
  98. float total_netPay;
  99. } TOTALS;
  100.  
  101. // This structure type defines the min and max values of all floating
  102. // point items so they can be display in our final report
  103.  
  104. typedef struct min_max
  105. {
  106. float min_wageRate;
  107. float min_hours;
  108. float min_overtimeHrs;
  109. float min_grossPay;
  110. float min_stateTax;
  111. float min_fedTax;
  112. float min_netPay;
  113. float max_wageRate;
  114. float max_hours;
  115. float max_overtimeHrs;
  116. float max_grossPay;
  117. float max_stateTax;
  118. float max_fedTax;
  119. float max_netPay;
  120. } MIN_MAX;
  121.  
  122. // Define prototypes here for each function except main
  123. EMPLOYEE * getEmpData (void);
  124. int isEmployeeSize (EMPLOYEE * head_ptr);
  125. void calcOvertimeHrs (EMPLOYEE * head_ptr);
  126. void calcGrossPay (EMPLOYEE * head_ptr);
  127. void printHeader (void);
  128. void printEmp (EMPLOYEE * head_ptr);
  129. void calcStateTax (EMPLOYEE * head_ptr);
  130. void calcFedTax (EMPLOYEE * head_ptr);
  131. void calcNetPay (EMPLOYEE * head_ptr);
  132. void calcEmployeeTotals (EMPLOYEE * head_ptr,
  133. TOTALS * emp_totals_ptr);
  134. void calcEmployeeMinMax (EMPLOYEE * head_ptr,
  135. MIN_MAX * emp_minMax_ptr);
  136. void printEmpStatistics (TOTALS * emp_totals_ptr,
  137. MIN_MAX * emp_minMax_ptr,
  138. int size);
  139.  
  140. int main ()
  141. {
  142. EMPLOYEE * head_ptr; // always points to first linked list node
  143.  
  144. int theSize; // number of employees processed
  145.  
  146. // set up structure to store totals and initialize all to zero
  147. TOTALS employeeTotals = {0,0,0,0,0,0,0};
  148.  
  149. // pointer to the employeeTotals structure
  150. TOTALS * emp_totals_ptr = &employeeTotals;
  151.  
  152. // set up structure to store min and max values and initialize all to zero
  153. MIN_MAX employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  154.  
  155. // pointer to the employeeMinMax structure
  156. MIN_MAX * emp_minMax_ptr = &employeeMinMax;
  157.  
  158. head_ptr = getEmpData ();
  159.  
  160. theSize = isEmployeeSize (head_ptr);
  161.  
  162. if (theSize <= 0)
  163. {
  164. printf("\n\n**** There was no employee input to process ***\n");
  165. }//if
  166. else // there are employees to be processed
  167. {
  168. // Calculate the overtime hours
  169. calcOvertimeHrs (head_ptr);
  170.  
  171. // Calculate the weekly gross pay
  172. calcGrossPay (head_ptr);
  173.  
  174. // Calculate the state tax
  175. calcStateTax (head_ptr);
  176.  
  177. // Calculate the federal tax
  178. calcFedTax (head_ptr);
  179.  
  180. // Calculate the net pay after taxes
  181. calcNetPay (head_ptr);
  182.  
  183. // Keep a running sum of the employee totals
  184. calcEmployeeTotals (head_ptr, &employeeTotals);
  185.  
  186. // Keep a running update of the employee minimum and maximum values
  187. calcEmployeeMinMax (head_ptr, &employeeMinMax);
  188.  
  189. // Print the column headers
  190. printHeader();
  191.  
  192. // print out final information on each employee
  193. printEmp (head_ptr);
  194.  
  195. // print the totals and averages for all float items
  196. printEmpStatistics (&employeeTotals, &employeeMinMax, theSize);
  197. }//else
  198.  
  199. printf ("\n\n *** End of Program *** \n");
  200.  
  201. return (0); // success
  202.  
  203. } // main
  204.  
  205. //**************************************************************
  206. // Function: getEmpData
  207. //
  208. // Purpose: Obtains input from user: employee name (first an last),
  209. // tax state, clock number, hourly wage, and hours worked
  210. // in a given week.
  211. //
  212. // Information in stored in a dynamically created linked
  213. // list for all employees.
  214. //
  215. // Parameters: void
  216. //
  217. // Returns:
  218. //
  219. // head_ptr - a pointer to the beginning of the dynamically
  220. // created linked list that contains the initial
  221. // input for each employee.
  222. //
  223. //**************************************************************
  224. EMPLOYEE * getEmpData (void)
  225. {
  226. char answer[80];
  227. int more_data = 1;
  228. char value;
  229.  
  230. EMPLOYEE *current_ptr,
  231. *head_ptr;
  232.  
  233. // Set up storage for first node
  234. head_ptr = (EMPLOYEE *) malloc (sizeof(EMPLOYEE));
  235. current_ptr = head_ptr;
  236.  
  237. // process while there is still input
  238. while (more_data)
  239. {
  240. // read in employee first and last name
  241. printf ("\nEnter employee first name: ");
  242. scanf ("%s", current_ptr->empName.firstName);
  243. printf ("\nEnter employee last name: ");
  244. scanf ("%s", current_ptr->empName.lastName);
  245.  
  246. // read in employee tax state
  247. printf ("\nEnter employee two character tax state: ");
  248. scanf ("%s", current_ptr->taxState);
  249.  
  250. // read in employee clock number
  251. printf("\nEnter employee clock number: ");
  252. scanf("%li", &current_ptr->clockNumber);
  253.  
  254. // read in employee wage rate
  255. printf("\nEnter employee hourly wage: ");
  256. scanf("%f", &current_ptr->wageRate);
  257.  
  258. // read in employee hours worked
  259. printf("\nEnter hours worked this week: ");
  260. scanf("%f", &current_ptr->hours);
  261.  
  262. // ask user if they would like to add another employee
  263. printf("\nWould you like to add another employee? (y/n): ");
  264. scanf("%s", answer);
  265.  
  266. // check first character for a 'Y' for yes
  267. // Ask user if they want to add another employee
  268. if ((value = toupper(answer[0])) != 'Y')
  269. {
  270. // no more employees to process
  271. current_ptr->next = (EMPLOYEE *) NULL;
  272. more_data = 0;
  273. }//if
  274. else // Yes, another employee
  275. {
  276. // set the next pointer of the current node to point to the new node
  277. current_ptr->next = (EMPLOYEE *) malloc (sizeof(EMPLOYEE));
  278. // move the current node pointer to the new node
  279. current_ptr = current_ptr->next;
  280. }//else
  281.  
  282. } // while
  283.  
  284. return(head_ptr);
  285.  
  286. } // getEmpData
  287.  
  288. //**************************************************************
  289. // Function: isEmployeeSize
  290. //
  291. // Purpose: Traverses the linked list and keeps a running count
  292. // on how many employees are currently in our list.
  293. //
  294. // Parameters:
  295. //
  296. // head_ptr - pointer to the initial node in our linked list
  297. //
  298. // Returns:
  299. //
  300. // theSize - the number of employees in our linked list
  301. //
  302. //**************************************************************
  303.  
  304. int isEmployeeSize (EMPLOYEE * head_ptr)
  305. {
  306. EMPLOYEE * current_ptr; // pointer to current node
  307. int theSize; // number of link list nodes
  308. // (i.e., employees)
  309.  
  310. theSize = 0; // initialize
  311.  
  312. // assume there is no data if the first node does
  313. // not have an employee name
  314. if (head_ptr->empName.firstName[0] != '\0')
  315. {
  316. // traverse through the linked list, keep a running count of nodes
  317. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
  318. {
  319. ++theSize; // employee node found, increment
  320. }//for
  321. }//if
  322.  
  323. return (theSize); // number of nodes (i.e., employees)
  324.  
  325. } // isEmployeeSize
  326.  
  327. //**************************************************************
  328. // Function: printHeader
  329. //
  330. // Purpose: Prints the initial table header information.
  331. //
  332. // Parameters: none
  333. //
  334. // Returns: void
  335. //
  336. //**************************************************************
  337.  
  338. void printHeader (void)
  339. {
  340. printf ("\n\n*** Pay Calculator ***\n");
  341.  
  342. printf("\n--------------------------------------------------------------");
  343. printf("-------------------");
  344. printf("\nName Tax Clock# Wage Hours OT Gross ");
  345. printf(" State Fed Net");
  346. printf("\n State Pay ");
  347. printf(" Tax Tax Pay");
  348. printf("\n--------------------------------------------------------------");
  349. printf("-------------------");
  350.  
  351. } // printHeader
  352.  
  353. //**************************************************************
  354. // Function: printEmp
  355. //
  356. // Purpose: Prints out all the information for each employee
  357. // in a nice and orderly table format.
  358. //
  359. // Parameters:
  360. //
  361. // head_ptr - pointer to the beginning of our linked list
  362. //
  363. // Returns: void
  364. //
  365. //**************************************************************
  366.  
  367. void printEmp (EMPLOYEE * head_ptr)
  368. {
  369.  
  370. // Used to format the employee name
  371. char name [FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
  372.  
  373. EMPLOYEE * current_ptr; // pointer to current node
  374.  
  375.  
  376. // traverse through the linked list to process each employee
  377. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
  378. {
  379. //format employee name
  380. strcpy (name, current_ptr->empName.firstName);
  381. strcat (name, " "); // add a space between first and last names
  382. strcat (name, current_ptr->empName.lastName);
  383.  
  384. // Print out current employee in the current linked list node
  385. printf("\n%-20.20s %-2.2s %06li %5.2f %4.1f %4.1f %7.2f %6.2f %7.2f %8.2f",
  386. name, current_ptr->taxState, current_ptr->clockNumber,
  387. current_ptr->wageRate, current_ptr->hours,
  388. current_ptr->overtimeHrs, current_ptr->grossPay,
  389. current_ptr->stateTax, current_ptr->fedTax,
  390. current_ptr->netPay);
  391. }//for
  392.  
  393. } // printEmp
  394.  
  395. //**************************************************************
  396. // Function: printEmpStatistics
  397. //
  398. // Purpose: Prints out the summary totals and averages of all
  399. // floating point value items for all employees
  400. // that have been processed. It also prints
  401. // out the min and max values.
  402. //
  403. // Parameters:
  404. //
  405. // emp_totals_ptr - pointer to a structure containing a running total
  406. // of all employee floating point items
  407. //
  408. // emp_minMax_ptr - pointer to a structure containing
  409. // the minimum and maximum values of all
  410. // employee floating point items
  411. //
  412. // tjeSize - the total number of employees processed, used
  413. // to check for zero or negative divide condition.
  414. //
  415. // Returns: void
  416. //
  417. //**************************************************************
  418.  
  419. void printEmpStatistics (TOTALS * emp_totals_ptr,
  420. MIN_MAX * emp_minMax_ptr,
  421. int theSize)
  422. {
  423.  
  424. // print a separator line
  425. printf("\n--------------------------------------------------------------");
  426. printf("-------------------");
  427.  
  428. // print the totals for all the floating point items
  429. printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  430. emp_totals_ptr->total_wageRate,
  431. emp_totals_ptr->total_hours,
  432. emp_totals_ptr->total_overtimeHrs,
  433. emp_totals_ptr->total_grossPay,
  434. emp_totals_ptr->total_stateTax,
  435. emp_totals_ptr->total_fedTax,
  436. emp_totals_ptr->total_netPay);
  437.  
  438. // make sure you don't divide by zero or a negative number
  439. if (theSize > 0)
  440. {
  441. // print the averages for all the floating point items
  442. printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  443. emp_totals_ptr->total_wageRate/theSize,
  444. emp_totals_ptr->total_hours/theSize,
  445. emp_totals_ptr->total_overtimeHrs/theSize,
  446. emp_totals_ptr->total_grossPay/theSize,
  447. emp_totals_ptr->total_stateTax/theSize,
  448. emp_totals_ptr->total_fedTax/theSize,
  449. emp_totals_ptr->total_netPay/theSize);
  450. }//if
  451.  
  452. // print the min and max values for each item
  453.  
  454. printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  455. emp_minMax_ptr->min_wageRate,
  456. emp_minMax_ptr->min_hours,
  457. emp_minMax_ptr->min_overtimeHrs,
  458. emp_minMax_ptr->min_grossPay,
  459. emp_minMax_ptr->min_stateTax,
  460. emp_minMax_ptr->min_fedTax,
  461. emp_minMax_ptr->min_netPay);
  462.  
  463. printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  464. emp_minMax_ptr->max_wageRate,
  465. emp_minMax_ptr->max_hours,
  466. emp_minMax_ptr->max_overtimeHrs,
  467. emp_minMax_ptr->max_grossPay,
  468. emp_minMax_ptr->max_stateTax,
  469. emp_minMax_ptr->max_fedTax,
  470. emp_minMax_ptr->max_netPay);
  471.  
  472. // print out the total employees process
  473. printf ("\n\nThe total employees processed was: %i\n", theSize);
  474.  
  475. } // printEmpStatistics
  476.  
  477. //**************************************************************
  478. // Function: calcOvertimeHrs
  479. //
  480. // Purpose: Calculates the overtime hours worked by an employee
  481. // in a given week for each employee.
  482. //
  483. // Parameters:
  484. //
  485. // head_ptr - pointer to the beginning of our linked list
  486. //
  487. // Returns: void (the overtime hours gets updated by reference)
  488. //
  489. //**************************************************************
  490.  
  491. void calcOvertimeHrs (EMPLOYEE * head_ptr)
  492. {
  493. EMPLOYEE * current_ptr; // pointer to current node
  494.  
  495. // traverse through the linked list to calculate overtime hours
  496. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
  497. {
  498. current_ptr->overtimeHrs = CALC_OT_HOURS(current_ptr->hours);
  499. }//for
  500.  
  501. } // calcOvertimeHrs
  502.  
  503. //**************************************************************
  504. // Function: calcGrossPay
  505. //
  506. // Purpose: Calculates the gross pay based on the the normal pay
  507. // and any overtime pay for a given week for each
  508. // employee.
  509. //
  510. // Parameters:
  511. //
  512. // head_ptr - pointer to the beginning of our linked list
  513. //
  514. // Returns: void (the gross pay gets updated by reference)
  515. //
  516. //**************************************************************
  517.  
  518. void calcGrossPay (EMPLOYEE * head_ptr)
  519. {
  520. float theNormalPay; // normal pay without any overtime hours
  521. float theOvertimePay; // overtime pay
  522.  
  523. EMPLOYEE * current_ptr; // pointer to current node
  524.  
  525. // traverse through the linked list to calculate gross pay
  526. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
  527. {
  528. // calculate normal pay and any overtime pay
  529. theNormalPay = CALC_NORMAL_PAY(current_ptr->wageRate,
  530. current_ptr->hours,
  531. current_ptr->overtimeHrs);
  532.  
  533. theOvertimePay = CALC_OT_PAY(current_ptr->wageRate,
  534. current_ptr->overtimeHrs);
  535.  
  536. // calculate gross pay for employee as normalPay + any overtime pay
  537. current_ptr->grossPay = theNormalPay + theOvertimePay;
  538. }//for
  539.  
  540. } // calcGrossPay
  541.  
  542. //**************************************************************
  543. // Function: calcStateTax
  544. //
  545. // Purpose: Calculates the State Tax owed based on gross pay
  546. // for each employee. State tax rate is based on the
  547. // the designated tax state based on where the
  548. // employee is actually performing the work. Each
  549. // state decides their tax rate.
  550. //
  551. // Parameters:
  552. //
  553. // head_ptr - pointer to the beginning of our linked list
  554. //
  555. // Returns: void (the state tax gets updated by reference)
  556. //
  557. //**************************************************************
  558.  
  559. void calcStateTax (EMPLOYEE * head_ptr)
  560. {
  561. EMPLOYEE * current_ptr; // pointer to current node
  562.  
  563. // traverse through the linked list to calculate the state tax
  564. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
  565. {
  566. // Make sure tax state is all uppercase
  567. if (islower(current_ptr->taxState[0]))
  568. {
  569. current_ptr->taxState[0] = toupper(current_ptr->taxState[0]);
  570. }//if
  571.  
  572. if (islower(current_ptr->taxState[1]))
  573. {
  574. current_ptr->taxState[1] = toupper(current_ptr->taxState[1]);
  575. }//if
  576.  
  577. // calculate state tax based on where employee resides
  578. if (strcmp(current_ptr->taxState, "MA") == 0)
  579. {
  580. current_ptr->stateTax = CALC_STATE_TAX(current_ptr->grossPay,
  581. MA_TAX_RATE);
  582.  
  583. }//if
  584. else if (strcmp(current_ptr->taxState, "VT") == 0)
  585. {
  586. current_ptr->stateTax = CALC_STATE_TAX(current_ptr->grossPay,
  587. VT_TAX_RATE);
  588.  
  589. }//else if
  590. else if (strcmp(current_ptr->taxState, "NH") == 0)
  591. {
  592. current_ptr->stateTax = CALC_STATE_TAX(current_ptr->grossPay,
  593. NH_TAX_RATE);
  594.  
  595. }//else if
  596. else if (strcmp(current_ptr->taxState, "CA") == 0)
  597. {
  598. current_ptr->stateTax = CALC_STATE_TAX(current_ptr->grossPay,
  599. CA_TAX_RATE);
  600. }//else if
  601. else
  602. {
  603. current_ptr->stateTax = CALC_STATE_TAX(current_ptr->grossPay,
  604. DEFAULT_STATE_TAX_RATE);
  605. }//else
  606. }//for
  607.  
  608. } // calcStateTax
  609.  
  610. //**************************************************************
  611. // Function: calcFedTax
  612. //
  613. // Purpose: Calculates the Federal Tax owed based on the gross
  614. // pay for each employee
  615. //
  616. // Parameters:
  617. //
  618. // head_ptr - pointer to the beginning of our linked list
  619. //
  620. // Returns: void (the federal tax gets updated by reference)
  621. //
  622. //**************************************************************
  623.  
  624. void calcFedTax (EMPLOYEE * head_ptr)
  625. {
  626. EMPLOYEE * current_ptr; // pointer to current node
  627.  
  628. // traverse through the linked list to calculate the federal tax
  629. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
  630. {
  631. current_ptr->fedTax = CALC_FED_TAX(current_ptr->grossPay);
  632. }//for
  633.  
  634. } // calcFedTax
  635.  
  636. //**************************************************************
  637. // Function: calcNetPay
  638. //
  639. // Purpose: Calculates the net pay as the gross pay minus any
  640. // state and federal taxes owed for each employee.
  641. // Essentially, their "take home" pay.
  642. //
  643. // Parameters:
  644. //
  645. // head_ptr - pointer to the beginning of our linked list
  646. //
  647. // Returns: void (the net pay gets updated by reference)
  648. //
  649. //**************************************************************
  650.  
  651. void calcNetPay (EMPLOYEE * head_ptr)
  652. {
  653. EMPLOYEE * current_ptr; // pointer to current node
  654.  
  655. // traverse through the linked list to calculate the net pay
  656. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
  657. {
  658. // calculate the net pay
  659. current_ptr->netPay = CALC_NET_PAY(current_ptr->grossPay,
  660. current_ptr->stateTax,
  661. current_ptr->fedTax);
  662. } //for
  663.  
  664. } // calcNetPay
  665.  
  666. //**************************************************************
  667. // Function: calcEmployeeTotals
  668. //
  669. // Purpose: Performs a running total (sum) of each employee
  670. // floating point member item stored in our linked list
  671. //
  672. // Parameters:
  673. //
  674. // head_ptr - pointer to the beginning of our linked list
  675. // emp_totals_ptr - pointer to a structure containing the
  676. // running totals of each floating point
  677. // member for all employees in our linked
  678. // list
  679. //
  680. // Returns:
  681. //
  682. // void (the employeeTotals structure gets updated by reference)
  683. //
  684. //**************************************************************
  685.  
  686. void calcEmployeeTotals (EMPLOYEE * head_ptr,
  687. TOTALS * emp_totals_ptr)
  688. {
  689. EMPLOYEE * current_ptr; // pointer to current node
  690.  
  691. // traverse through the linked list to calculate a running
  692. // sum of each employee floating point member item
  693. for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
  694. {
  695. // add current employee data to our running totals
  696. emp_totals_ptr->total_wageRate += current_ptr->wageRate;
  697. emp_totals_ptr->total_hours += current_ptr->hours;
  698. emp_totals_ptr->total_overtimeHrs += current_ptr->overtimeHrs;
  699. emp_totals_ptr->total_grossPay += current_ptr->grossPay;
  700. emp_totals_ptr->total_stateTax += current_ptr->stateTax;
  701. emp_totals_ptr->total_fedTax += current_ptr->fedTax;
  702. emp_totals_ptr->total_netPay += current_ptr->netPay;
  703. }//for
  704.  
  705. } // calcEmployeeTotals
  706.  
  707. //**************************************************************
  708. // Function: calcEmployeeMinMax
  709. //
  710. // Purpose: Accepts various floating point values from an
  711. // employee and adds to a running update of min
  712. // and max values
  713. //
  714. // Parameters:
  715. //
  716. // head_ptr - pointer to the beginning of our linked list
  717. // emp_minMax_ptr - pointer to the min/max structure
  718. //
  719. // Returns:
  720. //
  721. // void (employeeMinMax structure updated by reference)
  722. //
  723. //**************************************************************
  724.  
  725. void calcEmployeeMinMax (EMPLOYEE * head_ptr,
  726. MIN_MAX * emp_minMax_ptr)
  727. {
  728. EMPLOYEE * current_ptr; // pointer to current node
  729.  
  730. current_ptr = head_ptr; // set to first employee, our initial linked list node
  731.  
  732. // set the min to the first employee members
  733. emp_minMax_ptr->min_wageRate = current_ptr->wageRate;
  734. emp_minMax_ptr->min_hours = current_ptr->hours;
  735. emp_minMax_ptr->min_overtimeHrs = current_ptr->overtimeHrs;
  736. emp_minMax_ptr->min_grossPay = current_ptr->grossPay;
  737. emp_minMax_ptr->min_stateTax = current_ptr->stateTax;
  738. emp_minMax_ptr->min_fedTax = current_ptr->fedTax;
  739. emp_minMax_ptr->min_netPay = current_ptr->netPay;
  740.  
  741. // set the max to the first employee members
  742. emp_minMax_ptr->max_wageRate = current_ptr->wageRate;
  743. emp_minMax_ptr->max_hours = current_ptr->hours;
  744. emp_minMax_ptr->max_overtimeHrs = current_ptr->overtimeHrs;
  745. emp_minMax_ptr->max_grossPay = current_ptr->grossPay;
  746. emp_minMax_ptr->max_stateTax = current_ptr->stateTax;
  747. emp_minMax_ptr->max_fedTax = current_ptr->fedTax;
  748. emp_minMax_ptr->max_netPay = current_ptr->netPay;
  749.  
  750. // ******************************************************
  751. // move to the next employee
  752. //
  753. // if this the only employee in our linked list
  754. // current_ptr will be NULL and will drop out the
  755. // the for loop below, otherwise, the second employee
  756. // and rest of the employees (if any) will be processed
  757. // ******************************************************
  758. current_ptr = current_ptr->next;
  759.  
  760. // traverse the linked list
  761. // compare the rest of the employees to each other for min and max
  762. for (; current_ptr; current_ptr = current_ptr->next)
  763. {
  764. // check if current Wage Rate is the new min and/or max
  765. emp_minMax_ptr->min_wageRate =
  766. CALC_MIN(current_ptr->wageRate, emp_minMax_ptr->min_wageRate);
  767. emp_minMax_ptr->max_wageRate =
  768. CALC_MAX(current_ptr->wageRate, emp_minMax_ptr->max_wageRate);
  769.  
  770. // check if current Hours is the new min and/or max
  771. emp_minMax_ptr->min_hours =
  772. CALC_MIN(current_ptr->hours, emp_minMax_ptr->min_hours);
  773. emp_minMax_ptr->max_hours =
  774. CALC_MAX(current_ptr->hours, emp_minMax_ptr->max_hours);
  775.  
  776. // check if current Overtime Hours is the new min and/or max
  777. emp_minMax_ptr->min_overtimeHrs =
  778. CALC_MIN(current_ptr->overtimeHrs, emp_minMax_ptr->min_overtimeHrs);
  779. emp_minMax_ptr->max_overtimeHrs =
  780. CALC_MAX(current_ptr->overtimeHrs, emp_minMax_ptr->max_overtimeHrs);
  781.  
  782. // check if current Gross Pay is the new min and/or max
  783. emp_minMax_ptr->min_grossPay =
  784. CALC_MIN(current_ptr->grossPay, emp_minMax_ptr->min_grossPay);
  785. emp_minMax_ptr->max_grossPay =
  786. CALC_MAX(current_ptr->grossPay, emp_minMax_ptr->max_grossPay);
  787.  
  788. // check if current State Tax is the new min and/or max
  789. emp_minMax_ptr->min_stateTax =
  790. CALC_MIN(current_ptr->stateTax, emp_minMax_ptr->min_stateTax);
  791. emp_minMax_ptr->max_stateTax =
  792. CALC_MAX(current_ptr->stateTax, emp_minMax_ptr->max_stateTax);
  793.  
  794. // check if current Federal Tax is the new min and/or max
  795. emp_minMax_ptr->min_fedTax =
  796. CALC_MIN(current_ptr->fedTax, emp_minMax_ptr->min_fedTax);
  797. emp_minMax_ptr->max_fedTax =
  798. CALC_MAX(current_ptr->fedTax, emp_minMax_ptr->max_fedTax);
  799.  
  800. // check if current Net Pay is the new min and/or max
  801. emp_minMax_ptr->min_netPay =
  802. CALC_MIN(current_ptr->netPay, emp_minMax_ptr->min_netPay);
  803. emp_minMax_ptr->max_netPay =
  804. CALC_MAX(current_ptr->netPay, emp_minMax_ptr->max_netPay);
  805. }//for
  806.  
  807. } // calcEmployeeMinMax
Success #stdin #stdout 0s 5312KB
stdin
Connie
Cobol
MA
98401
10.60
51.0
Y
Mary
Apl
NH
526488
9.75
42.5
Y
Frank
Fortran
VT
765349
10.50
37.0
Y
Jeff
Ada
NY
34645
12.25
45
Y
Anton
Pascal
CA
127615
8.35
40.0
N
stdout
Enter employee first name: 
Enter employee last name: 
Enter employee two character tax state: 
Enter employee clock number: 
Enter employee hourly wage: 
Enter hours worked this week: 
Would you like to add another employee? (y/n): 
Enter employee first name: 
Enter employee last name: 
Enter employee two character tax state: 
Enter employee clock number: 
Enter employee hourly wage: 
Enter hours worked this week: 
Would you like to add another employee? (y/n): 
Enter employee first name: 
Enter employee last name: 
Enter employee two character tax state: 
Enter employee clock number: 
Enter employee hourly wage: 
Enter hours worked this week: 
Would you like to add another employee? (y/n): 
Enter employee first name: 
Enter employee last name: 
Enter employee two character tax state: 
Enter employee clock number: 
Enter employee hourly wage: 
Enter hours worked this week: 
Would you like to add another employee? (y/n): 
Enter employee first name: 
Enter employee last name: 
Enter employee two character tax state: 
Enter employee clock number: 
Enter employee hourly wage: 
Enter hours worked this week: 
Would you like to add another employee? (y/n): 

*** 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

The total employees processed was: 5


 *** End of Program ***