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