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

*** Pay Calculator ***

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