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