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