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