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