Advertisement
Guest User

Untitled

a guest
Mar 19th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.46 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. //declare function prototypes
  9. void displayWelcomeMessage();
  10. void getInput(double *EmployeeID, double *hoursWorked, double *payRate, char *unionCode, char A, char B, char C, double *regularPay, double *overtimePay);
  11. double calculateGrossPay(double *grossPay, double regularPay, double overtimePay);
  12. void calculateFederalTax(double grossPay, double *federalTax, double *paidTax);
  13. void calculateUnionDues(char unionCode, double *unionDues);
  14. double calculateNetPay(double *netPay, double grossPay, double paidTax, double unionDues);
  15. void displayEmployeeInputInfo(double employeeID, double hoursWorked, double payRate, char unionCode);
  16. void displayEmployeeCalculationResults(double regularPay, double overtimePay, double grossPay, double federalTax, double unionDues, double netPay);
  17. void displayPayrollSummaryInfo(int numEmployees, double totalGrossPay, double highestGrossPayEmployeeID, double highestGrossPay, double lowestGrossPayEmployeeID, double lowestGrossPay, double lowAverageID, double averageGrossPay);
  18. void displayTerminationMessage();
  19.  
  20. //initialize the program
  21. int main()
  22. {
  23.            displayWelcomeMessage();
  24.            // local variable declarations
  25.            int numEmployees = 0; //number of employees processed
  26.            double totalGrossPay = 0; //total gross pay
  27.            double highestGrossPay = 0; //highest gross pay
  28.            double highestGrossPayEmployeeID = 0; //counter to identify employeeID with highest gross pay
  29.            double lowestGrossPay = std::numeric_limits<double>::infinity(); //lowest gross pay
  30.            double lowestGrossPayEmployeeID = 0; //counter to identify employeeID with lowest gross pay
  31.            double averageGrossPay;//average gross pay is totalgrosspay / numemployees
  32.            double lowAverageID[5]; //Employees whose gross pay is less than average
  33.            double employeeID[5]; // employee's ID number
  34.            double hoursWorked[5]; // number of hours employee worked
  35.            double payRate[5]; // employee's pay rate
  36.            char unionCode[5]; // employee's one character union code
  37.            char A = 'A'; // unionCode A
  38.            char B = 'B'; //unionCode B
  39.            char C = 'C'; //unionCode C
  40.            double regularPay[5]; // if hoursWorked <=40 then regular pay = hoursWorked * payRate
  41.            double overtimePay[5]; // if hoursWorked >40 then over times pay = 1.5 * (hoursWorked - 40) * payRate
  42.            double grossPay[5]; // gross pay is hoursWorked times payRate
  43.            double federalTax[5]; // amount of tax employee pays based on grossPay
  44.            double paidTax[5]; // paidTax is grossPay - netPay
  45.            double unionDues[5]; // dues paid based on unionCode
  46.            double netPay[5]; // netPay is grossPay - (grossPay * federalTax)
  47.            
  48.            for (int x = 1; x <=2; x++) // loop program 5 times
  49.            {
  50.            //functions
  51.            getInput(&employeeID[x], &hoursWorked[x], &payRate[x], &unionCode[x], A, B, C, &regularPay[x], &overtimePay[x]);
  52.            calculateGrossPay(&grossPay[x], regularPay[x], overtimePay[x]);
  53.            calculateFederalTax(grossPay[x], &federalTax[x], &paidTax[x]);
  54.            calculateUnionDues(unionCode[x], &unionDues[x]);
  55.            calculateNetPay(&netPay[x], grossPay[x], paidTax[x], unionDues[x]);
  56.            displayEmployeeInputInfo(employeeID[x], hoursWorked[x], payRate[x], unionCode[x]);
  57.            displayEmployeeCalculationResults(regularPay[x], overtimePay[x], grossPay[x], paidTax[x], unionDues[x], netPay[x]);
  58.            
  59.            numEmployees++; //counter for number of employees to process
  60.            totalGrossPay += grossPay[numEmployees]; //counter for total gross pay
  61.            averageGrossPay = totalGrossPay / numEmployees; //calculate average gross pay
  62.            //highest gross pay employee ID
  63.            if( grossPay[x] > highestGrossPay )
  64.                {
  65.                    highestGrossPay = grossPay[x];
  66.                    highestGrossPayEmployeeID = employeeID[x];
  67.                }
  68.            //lowest gross pay employee id    
  69.            if( grossPay[x] < lowestGrossPay )
  70.                {
  71.                    lowestGrossPay = grossPay[x];
  72.                    lowestGrossPayEmployeeID = employeeID[x];
  73.                }
  74.            //employees with lower than average gross pay    
  75.            if( grossPay[x] < averageGrossPay )
  76.                {
  77.                    lowAverageID[x] = employeeID[x];
  78.                }
  79.            }
  80.            //display summary of results    
  81.            displayPayrollSummaryInfo(numEmployees, totalGrossPay, highestGrossPayEmployeeID, highestGrossPay, lowestGrossPayEmployeeID, lowestGrossPay, lowAverageID[5], averageGrossPay);
  82.            //display termination message
  83.            displayTerminationMessage();
  84.                
  85.            system("PAUSE");
  86.            return 0;
  87. }
  88.     //function definitions
  89.     // Welcome message
  90.     void displayWelcomeMessage()
  91.         {
  92.             std::cout << "My Payroll Calculator\n\n\n";
  93.         }
  94.     //get inputs from user    
  95.     void getInput(double *EmployeeID, double *hoursWorked, double *payRate, char *unionCode, char A, char B, char C, double *regularPay, double *overtimePay)
  96.         {
  97.             std::cout << "EmployeeID: "; //request user input for EmployeeID    
  98.             std::cin >> *EmployeeID;   // read input from user into employeeID
  99.             std::cout << "Hours worked: "; // request user input for hoursWorked
  100.             std::cin >> *hoursWorked; // read input from user into hoursWorked
  101.             while (*hoursWorked <0 || *hoursWorked > 60) // only allow input from 0-60
  102.                 {
  103.                     std::cout << "Error! You must enter a value between 0 and 60\n";
  104.                     std::cout << "Hours worked: ";
  105.                     std::cin >> *hoursWorked;
  106.                 }
  107.             std::cout << "Pay rate: "; // request user input for payRate
  108.             std::cin >> *payRate; // read input from user into payrate
  109.             while (*payRate <7.50 || *payRate > 45.00) //only allow input from 7.50 - 45.00
  110.                 {
  111.                     std::cout << "Error! You must enter a value between 7.50 and 45.00\n";
  112.                     std::cout << "Pay rate: ";
  113.                     std::cin >> *payRate;
  114.                 }
  115.             std::cout << "Union code A, B, or C? "; // request user input for unionCode
  116.             std::cin >> *unionCode; // read input from user into unionCode
  117.             while (*unionCode !=A && *unionCode !=B && *unionCode !=C) //only allow input A, B, or C
  118.                 {
  119.                     std::cout << "Error! Your code must be A, B, or C\n";
  120.                     std::cout << "Union code: ";
  121.                     std::cin >> *unionCode;
  122.                 }
  123.             *regularPay = *hoursWorked * *payRate; // calculate regularPay
  124.             *overtimePay = 1.5 * ( *hoursWorked - 40 ) * *payRate; // calculate overtimePay
  125.             if ( *hoursWorked <= 40) *overtimePay = 0;//determine if there is overtime pay or not
  126.             if ( *hoursWorked > 40) *regularPay = *payRate * 40;
  127.         }
  128.     // calculate grossPay
  129.     double calculateGrossPay(double *grossPay, double regularPay, double overtimePay)
  130.         {
  131.             *grossPay = regularPay + overtimePay;                        
  132.             return *grossPay;
  133.         }
  134.     // calculate paidTax
  135.     void calculateFederalTax(double grossPay, double *federalTax, double *paidTax)
  136.         {
  137.             if ( grossPay > 2000 ) *federalTax = .25; // determine federal tax rate
  138.             else if ( grossPay >= 1000 ) *federalTax = .15;
  139.             else *federalTax = .1;
  140.             *paidTax = grossPay * *federalTax;
  141.         }
  142.         // calculate unionDues
  143.     void calculateUnionDues(char unionCode, double *unionDues)
  144.         {
  145.             switch (unionCode)
  146.                 {
  147.                     case 'A': *unionDues = 25;
  148.                     break;
  149.                     case 'B': *unionDues = 50;
  150.                     break;
  151.                     case 'C': *unionDues = 75;
  152.                     break;
  153.                 }
  154.         }
  155.     // calculate netPay
  156.     double calculateNetPay(double *netPay, double grossPay, double paidTax, double unionDues)
  157.         {
  158.             *netPay = grossPay - paidTax - unionDues;
  159.             return *netPay;
  160.         }
  161.     //display employee input info
  162.     void displayEmployeeInputInfo(double employeeID, double hoursWorked, double payRate, char unionCode)
  163.         {    
  164.             std::cout << "\nIdentification Number: " << employeeID; //display employeeID
  165.             std::cout << "\nHours Worked: " << hoursWorked; //display hoursWorked
  166.             std::cout << "\nPay Rate: " << payRate; //display payRate
  167.             std::cout << "\nUnion Code: " << unionCode; //display unionCode
  168.         }
  169.     //display employee calculation results
  170.     void displayEmployeeCalculationResults(double regularPay, double overtimePay, double grossPay, double federalTax, double unionDues, double netPay)
  171.         {
  172.             std::cout << fixed << setprecision(2); //format output to 2 decimal places
  173.             std::cout << "\nRegular Pay: " << regularPay; //display regularPay
  174.             std::cout << "\nOvertime Pay: " << overtimePay; // display overtimePay
  175.             std::cout << "\nGross Pay: " << grossPay; // display grossPay
  176.             std::cout << "\nFederal Tax: " << federalTax; // display federalTax
  177.             std::cout << "\nUnion Dues: " << unionDues; // display unionDues
  178.             std::cout << "\nNet Pay: " << netPay; // display netPay
  179.             std::cout << fixed << setprecision(0); //format output to 0 decimal places
  180.             std::cout << "\n\n";
  181.         }
  182.     //display payroll summary info
  183.     void displayPayrollSummaryInfo(int numEmployees, double totalGrossPay, double highestGrossPayEmployeeID, double highestGrossPay, double lowestGrossPayEmployeeID, double lowestGrossPay, double lowAverageID, double averageGrossPay)
  184.         {
  185.             std::cout << "\nEmployees Processed: " << numEmployees; //display number of employees processed
  186.             std::cout << fixed << setprecision(2); //format output to 2 decimal places
  187.             std::cout << "\nTotal Gross Pay: " << totalGrossPay; //display total gross pay
  188.             std::cout << fixed << setprecision(0); //format output to 0 decimal places
  189.             std::cout << "\nEmployee With Highest Gross Pay: " << highestGrossPayEmployeeID; //display ID of employee with highest gross pay
  190.             std::cout << fixed << setprecision(2); //format output to 2 decimal places
  191.             std::cout << "\nHighest Gross Pay: " << highestGrossPay; //display highest gross pay
  192.             std::cout << fixed << setprecision(0); //format output to 0 decimal places
  193.             std::cout << "\nEmployee With Lowest Gross Pay: " << lowestGrossPayEmployeeID; //display ID of employee with lowest gross pay
  194.             std::cout << fixed << setprecision(2); //format output to 2 decimal places
  195.             std::cout << "\nLowest Gross Pay: " << lowestGrossPay; //display lowest gross pay
  196.             std::cout << "\nAverage Gross Pay: " << averageGrossPay; //display average gross pay
  197.             std::cout << "\nEmployees With Below Average Gross Pay: " << lowAverageID;
  198.             std::cout << "\n";
  199.         }  
  200.     //display termination message
  201.     void displayTerminationMessage()
  202.         {
  203.             std::cout << "\nBest payroll calculator in the whole world\n\n"; // Termination message
  204.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement