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