Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- //declare function prototypes
- void displayWelcomeMessage();
- void getInput(double *EmployeeID, double *hoursWorked, double *payRate, char *unionCode, char A, char B, char C, double *regularPay, double *overtimePay);
- double calculateGrossPay(double *grossPay, double regularPay, double overtimePay);
- void calculateFederalTax(double grossPay, double *federalTax, double *paidTax);
- void calculateUnionDues(char unionCode, double *unionDues);
- double calculateNetPay(double *netPay, double grossPay, double paidTax, double unionDues);
- void displayEmployeeInputInfo(double employeeID, double hoursWorked, double payRate, char unionCode);
- void displayEmployeeCalculationResults(double regularPay, double overtimePay, double grossPay, double federalTax, double unionDues, double netPay);
- void displayPayrollSummaryInfo(int numEmployees, double totalGrossPay, double highestGrossPayEmployeeID, double highestGrossPay, double lowestGrossPayEmployeeID, double lowestGrossPay, double averageGrossPay);
- void displaylowGrossID(double lowAverageID[], double grossPay[]);
- void displayTerminationMessage();
- //initialize the program
- int main()
- {
- displayWelcomeMessage();
- // local variable declarations
- int numEmployees = 0; //number of employees processed
- double totalGrossPay = 0; //total gross pay
- double highestGrossPay = 0; //highest gross pay
- double highestGrossPayEmployeeID = 0; //counter to identify employeeID with highest gross pay
- double lowestGrossPay = std::numeric_limits<double>::infinity(); //lowest gross pay
- double lowestGrossPayEmployeeID = 0; //counter to identify employeeID with lowest gross pay
- double averageGrossPay;//average gross pay is totalgrosspay / numemployees
- double lowAverageID[4]; //Employees whose gross pay is less than average
- double employeeID[5]; // employee's ID number
- double hoursWorked[5]; // number of hours employee worked
- double payRate[5]; // employee's pay rate
- char unionCode[5]; // employee's one character union code
- char A = 'A'; // unionCode A
- char B = 'B'; //unionCode B
- char C = 'C'; //unionCode C
- double regularPay[5]; // if hoursWorked <=40 then regular pay = hoursWorked * payRate
- double overtimePay[5]; // if hoursWorked >40 then over times pay = 1.5 * (hoursWorked - 40) * payRate
- double grossPay[5]; // gross pay is hoursWorked times payRate
- double federalTax[5]; // amount of tax employee pays based on grossPay
- double paidTax[5]; // paidTax is grossPay - netPay
- double unionDues[5]; // dues paid based on unionCode
- double netPay[5]; // netPay is grossPay - (grossPay * federalTax)
- for (int x = 0; x < 5; x++) // loop program 2 times
- {
- //functions
- getInput(&employeeID[x], &hoursWorked[x], &payRate[x], &unionCode[x], A, B, C, ®ularPay[x], &overtimePay[x]);
- calculateGrossPay(&grossPay[x], regularPay[x], overtimePay[x]);
- calculateFederalTax(grossPay[x], &federalTax[x], &paidTax[x]);
- calculateUnionDues(unionCode[x], &unionDues[x]);
- calculateNetPay(&netPay[x], grossPay[x], paidTax[x], unionDues[x]);
- displayEmployeeInputInfo(employeeID[x], hoursWorked[x], payRate[x], unionCode[x]);
- displayEmployeeCalculationResults(regularPay[x], overtimePay[x], grossPay[x], paidTax[x], unionDues[x], netPay[x]);
- numEmployees++; //counter for number of employees to process
- totalGrossPay += grossPay[x]; //counter for total gross pay
- averageGrossPay = totalGrossPay / numEmployees;
- //highest gross pay employee ID
- if( grossPay[x] > highestGrossPay )
- {
- highestGrossPay = grossPay[x];
- highestGrossPayEmployeeID = employeeID[x];
- }
- //lowest gross pay employee id
- if( grossPay[x] < lowestGrossPay )
- {
- lowestGrossPay = grossPay[x];
- lowestGrossPayEmployeeID = employeeID[x];
- }
- }
- //employees with lower than average gross pay
- for (int x = 0; x < 5; x++){
- if( grossPay[x] < averageGrossPay )
- {
- lowAverageID[x] = employeeID[x];
- }
- }
- //display summary of results
- displayPayrollSummaryInfo(numEmployees, totalGrossPay, highestGrossPayEmployeeID, highestGrossPay, lowestGrossPayEmployeeID, lowestGrossPay, averageGrossPay);
- //display employees with below average gross pay
- displaylowGrossID(lowAverageID, grossPay);
- //display termination message
- displayTerminationMessage();
- system("PAUSE");
- return 0;
- }
- //function definitions
- // Welcome message
- void displayWelcomeMessage()
- {
- std::cout << "My Payroll Calculator\n\n\n";
- }
- //get inputs from user
- void getInput(double *EmployeeID, double *hoursWorked, double *payRate, char *unionCode, char A, char B, char C, double *regularPay, double *overtimePay)
- {
- std::cout << "EmployeeID: "; //request user input for EmployeeID
- std::cin >> *EmployeeID; // read input from user into employeeID
- std::cout << "Hours worked: "; // request user input for hoursWorked
- std::cin >> *hoursWorked; // read input from user into hoursWorked
- while (*hoursWorked <0 || *hoursWorked > 60) // only allow input from 0-60
- {
- std::cout << "Error! You must enter a value between 0 and 60\n";
- std::cout << "Hours worked: ";
- std::cin >> *hoursWorked;
- }
- std::cout << "Pay rate: "; // request user input for payRate
- std::cin >> *payRate; // read input from user into payrate
- while (*payRate <7.50 || *payRate > 45.00) //only allow input from 7.50 - 45.00
- {
- std::cout << "Error! You must enter a value between 7.50 and 45.00\n";
- std::cout << "Pay rate: ";
- std::cin >> *payRate;
- }
- std::cout << "Union code A, B, or C? "; // request user input for unionCode
- std::cin >> *unionCode; // read input from user into unionCode
- while (*unionCode !=A && *unionCode !=B && *unionCode !=C) //only allow input A, B, or C
- {
- std::cout << "Error! Your code must be A, B, or C\n";
- std::cout << "Union code: ";
- std::cin >> *unionCode;
- }
- *regularPay = *hoursWorked * *payRate; // calculate regularPay
- *overtimePay = 1.5 * ( *hoursWorked - 40 ) * *payRate; // calculate overtimePay
- if ( *hoursWorked <= 40) *overtimePay = 0;//determine if there is overtime pay or not
- if ( *hoursWorked > 40) *regularPay = *payRate * 40;
- }
- // calculate grossPay
- double calculateGrossPay(double *grossPay, double regularPay, double overtimePay)
- {
- *grossPay = regularPay + overtimePay;
- return *grossPay;
- }
- // calculate paidTax
- void calculateFederalTax(double grossPay, double *federalTax, double *paidTax)
- {
- if ( grossPay > 2000 ) *federalTax = .25; // determine federal tax rate
- else if ( grossPay >= 1000 ) *federalTax = .15;
- else *federalTax = .1;
- *paidTax = grossPay * *federalTax;
- }
- // calculate unionDues
- void calculateUnionDues(char unionCode, double *unionDues)
- {
- switch (unionCode)
- {
- case 'A': *unionDues = 25;
- break;
- case 'B': *unionDues = 50;
- break;
- case 'C': *unionDues = 75;
- break;
- }
- }
- // calculate netPay
- double calculateNetPay(double *netPay, double grossPay, double paidTax, double unionDues)
- {
- *netPay = grossPay - paidTax - unionDues;
- return *netPay;
- }
- //display employee input info
- void displayEmployeeInputInfo(double employeeID, double hoursWorked, double payRate, char unionCode)
- {
- std::cout << "\nIdentification Number: " << employeeID; //display employeeID
- std::cout << "\nHours Worked: " << hoursWorked; //display hoursWorked
- std::cout << "\nPay Rate: " << payRate; //display payRate
- std::cout << "\nUnion Code: " << unionCode; //display unionCode
- }
- //display employee calculation results
- void displayEmployeeCalculationResults(double regularPay, double overtimePay, double grossPay, double federalTax, double unionDues, double netPay)
- {
- std::cout << fixed << setprecision(2); //format output to 2 decimal places
- std::cout << "\nRegular Pay: " << regularPay; //display regularPay
- std::cout << "\nOvertime Pay: " << overtimePay; // display overtimePay
- std::cout << "\nGross Pay: " << grossPay; // display grossPay
- std::cout << "\nFederal Tax: " << federalTax; // display federalTax
- std::cout << "\nUnion Dues: " << unionDues; // display unionDues
- std::cout << "\nNet Pay: " << netPay; // display netPay
- std::cout << fixed << setprecision(0); //format output to 0 decimal places
- std::cout << "\n\n";
- }
- //display payroll summary info
- void displayPayrollSummaryInfo(int numEmployees, double totalGrossPay, double highestGrossPayEmployeeID, double highestGrossPay, double lowestGrossPayEmployeeID, double lowestGrossPay, double averageGrossPay)
- {
- std::cout << "\nEmployees Processed: " << numEmployees; //display number of employees processed
- std::cout << fixed << setprecision(2); //format output to 2 decimal places
- std::cout << "\nTotal Gross Pay: " << totalGrossPay; //display total gross pay
- std::cout << fixed << setprecision(0); //format output to 0 decimal places
- std::cout << "\nEmployee With Highest Gross Pay: " << highestGrossPayEmployeeID; //display ID of employee with highest gross pay
- std::cout << fixed << setprecision(2); //format output to 2 decimal places
- std::cout << "\nHighest Gross Pay: " << highestGrossPay; //display highest gross pay
- std::cout << fixed << setprecision(0); //format output to 0 decimal places
- std::cout << "\nEmployee With Lowest Gross Pay: " << lowestGrossPayEmployeeID; //display ID of employee with lowest gross pay
- std::cout << fixed << setprecision(2); //format output to 2 decimal places
- std::cout << "\nLowest Gross Pay: " << lowestGrossPay; //display lowest gross pay
- std::cout << "\nAverage Gross Pay: " << averageGrossPay; //display average gross pay
- std::cout << fixed << setprecision(0);
- std::cout << "\n";
- }
- //display employess with below average gross pay
- void displaylowGrossID(double lowAverageID[], double grossPay[])
- {
- std::cout << "\nEmployees With Below Average Gross Pay:\n";
- for (int x = 0; x < lowAverageID[x]; x++)
- {
- cout << lowAverageID[x] << " -- $" << grossPay[x] << endl;
- }
- }
- //display termination message
- void displayTerminationMessage()
- {
- std::cout << "\nBest payroll calculator in the whole world\n\n"; // Termination message
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement