Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

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