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