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