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