Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using a structure, and creating three structure variables; write a program that

ID: 3765372 • Letter: U

Question

Using a structure, and creating three structure variables; write a program that will calculate the total pay for thirty (30) employees. (Ten for each structured variable.) Sort the list of employees by the employee ID in ascending order and display their respective information. Description Employee IDs Hours Worked Pay Rate Total Pay Structure name administrative office field DataType of INT of DOUBLE of DOUBLE of Double payroll structure variable structure variable structure variable Members employees_jd hrworked_jd payrate_jd total_pay Array Size 10 10 10 Excluding the main function, your program should have five additional functions that will get the hours worked, and payrate, calculate the total pay, sort the data and display your output. Base pay should be calculated by multiplying the regular hours worked by pay rate. If a person has worked over forty (40)hours, total pay is calculated by an adding 10% of base pay for every five (5) hours over forty (40) to base pay. (ie a person working 50 hours with a total pay of $100 would have ((hours-40)/5)*(base pay*.1) + base pay.

** using input file **

Explanation / Answer

    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    using std::cout;
    using std::cin;
    using std::endl;
    int _tmain(int argc, _TCHAR* argv[])
    {
      
       // Declaring Function Prototypes
       void getInput (int [], char[], double[], double[], double[], int[], int[], int);
       void doCalculations (double [], double[], double[], double[], double[], double[],
           double[], double[],double[],double[], int[], double[], double[], int);
       void performSorting (int [], double [], double[], double[], double[], double[], double[],
           double[], double[],double[],double[], int[], int);
       void displayEmployeeResults (int [], char[], double [], double[] , double[], double[], double[], double[],
           double[], double[],double[],double[], int[], double[], double[], int);
        void displayPayrollSummaryResults (int[], double[], double[], int[], double[], int);
       const static int Worker= 10;
       // Declaring Array Variable
           int empID[Worker] = {};
           char payrollType[Worker] = {};
           double hoursWorked[Worker] = {};
           double payRate[Worker] = {};
           int unionCode[Worker] = {};
           double overtimePay[Worker] = {};
           double grossPay[Worker] = {};
           double stateTax[Worker] = {};
           double federalTax[Worker] = {};
           double totalTax[Worker] = {};
           double unionDues[Worker] = {};
           double netPay[Worker] = {};
           double regularPay[Worker] = {};
           int totalEmployees[1] = {};
           double totalGrossPay[1] = {};
           double totalNetPay[1] = {};
       std::cout << " Welcome to the Payroll Program!" << endl;
       //Calling getInput() by passing parameters
       getInput (empID, payrollType, hoursWorked, payRate, unionDues, unionCode, totalEmployees, Worker);
      
       // Calling doCalculations() by passing parameters
       doCalculations (overtimePay, grossPay, stateTax, federalTax, totalTax, unionDues, netPay, regularPay,
                       hoursWorked, payRate, unionCode, totalGrossPay, totalNetPay, Worker);
       // Sorting employee data by Bubble sort function
       performSorting (empID, overtimePay, grossPay, stateTax, federalTax, totalTax, unionDues, netPay, regularPay,
                        hoursWorked, payRate, unionCode, Worker);
       // Passing parameters to call for displayEmployeeResults
       displayEmployeeResults (empID, payrollType,hoursWorked, payRate, regularPay, overtimePay,grossPay, stateTax,
                               federalTax, totalTax, netPay, unionDues, totalEmployees, totalGrossPay, totalNetPay, Worker);
      
       displayPayrollSummaryResults (totalEmployees, totalGrossPay, totalNetPay, empID, grossPay, Worker);
    }
       void getInput (int empID[],char payrollType[], double hoursWorked[],double payRate[],
                      double unionDues[], int unionCode[], int employees[], int Worker)
  
      
       {  
                       int ID = 0;
           int employeeCount = 0;
           std::cout << " Enter your employee ID (100 - 800) #: ";
           std::cin >> empID [ID];
                      
               while (empID [ID] < 100 || empID [ID] > 800)
               {
                   std::cout << " Please enter a correct employee ID!";
                   std::cout << " Enter your employee ID (100 - 800) #: ";
                   std::cin >> empID [ID];
               }
               std::cout << " Enter your payroll type (H or h for hourly employee): ";
               std::cin >> payrollType[ID] ;
          
               while (payrollType [ID] != 'H' && payrollType [ID] != 'h')
               {
                   std::cout << " Please enter a correct payroll type!";
                   std::cout << " Enter your payroll type (H or h for hourly employee): ";
                   std::cin >> payrollType [ID];
               }   std::cout << " Enter your hours worked (0 - 60.0): ";
               std::cin >> hoursWorked [ID];
          
               while (hoursWorked [ID] < 0 || hoursWorked [ID] > 60.00)
               {
                   std::cout << " Please enter a correct number of hours worked!";
                   std::cout << " Enter your hours worked (0 - 60.0): ";
                   std::cin >> hoursWorked [ID];
               }  
              
               std::cout << " Enter your pay rate (8.50 - 45.00): $";
               std::cin >> payRate [ID];
       //Using while loops to validate data inputted by User
               while (payRate [ID] < 8.50 || payRate [ID] > 45.00)
               {
                   std::cout << " Please enter your correct pay rate!";
                   std::cout << " Enter your pay rate (8.50 - 45.00): $";
                   std::cin >> payRate [ID];
               }
               std::cout <<" Enter your union code (1 - 3): ";
               std::cin >> unionCode [ID];
       //Using while loops to validate data inputted by User
               while (unionCode [ID] != 1 && unionCode [ID] != 2 && unionCode [ID] != 3)
               {
                   std::cout << " Please enter a correct union code!";
                   std::cout <<" Enter your union code (1 - 3): ";
                   std::cin >> unionCode [ID];
               }
           // Asking the user if there are more workers to be entered
           char response;
           std::cout << " Would you like to process another employee (Y or y for yes): ";
           std::cin >> response;
          
           // Setting up a counter and declaring variables
               ID++;
               employeeCount++;
           //Using while function to validate data
               while (response != 'Y' && response != 'y')
               {
                   std::cout << " Do you have any other employees to be processed";
                   employees[0] = employeeCount++;
               }
    }//End function
      
       // doCalculation() function declaration
       void doCalculations (double overtimePay[], double grossPay[], double stateTax[], double federalTax[], double totalTax[],    
                            double unionDues[], double netPay[], double regularPay[],double hoursWorked[], double payRate[], int unionCode[],
                            double totalGrossPay[], double totalNetPay[], int Worker)
       {
       // Declaration of Variables
           double totalGross = 0;
           double totalNet = 0;
       for(int ID = 0; ID < 10; ID++)
      
       //Calculation of Overtime Pay and Regular Pay using if/else statement
       {
       if (hoursWorked [ID] > 40)
               {
                   regularPay [ID] = payRate [ID] * 40;
                   overtimePay [ID] = 1.5 * payRate [ID] * (hoursWorked [ID] - 40.0);
                   grossPay [ID] = regularPay [ID] + overtimePay [ID];
               }
       //Calculation of Regular Work Pay
       else if (hoursWorked [ID] <= 40)
           {
               regularPay [ID] = payRate [ID] * hoursWorked [ID];
                overtimePay [ID] = 0;
               grossPay [ID] = regularPay [ID];
           }
      
      
       //Determination of State Tax Rate using if else statement
       {
       if (grossPay [ID] < 500)
           {
               stateTax [ID] = 0;
              
           }
          
           else if ( grossPay [ID] >= 500 && grossPay [ID] <= 1000)
           {
               stateTax [ID]= 0.03 * grossPay [ID];
                  
           }
              
            else if ( grossPay [ID] > 1000)
           {
          
               stateTax [ID] = 0.05 * grossPay [ID];
                      
           }
       }
      
          
           {
           if ( grossPay [ID] < 500)
           {
               federalTax [ID] = 0;
          
           }
              
           else if (grossPay [ID] >= 500 && grossPay [ID] <= 1000)
           {
               federalTax [ID] = 0.05 * grossPay [ID];
          
           }
          
           else if (grossPay [ID] > 1000)
           {
               federalTax [ID] = 0.07 * grossPay [ID];
          
           }
       }
      
       }
           for(int ID = 0; ID < 10; ID++)
           totalTax [ID] = stateTax [ID] + federalTax [ID];
          
           //Calculation of Net Pay
           for(int ID = 0; ID < 10; ID++)
           netPay [ID] = grossPay [ID] - (stateTax [ID] + federalTax [ID] + unionDues [ID]);
          
           totalGrossPay[0] = totalGross;
           totalNetPay[0] = totalNet;
          
           for(int ID = 0; ID < 10; ID++)
           {
               totalGross = totalGross + grossPay[ID];
               totalNet = totalNet + netPay[ID];
           }
                              
       }//end function
      
       void performSorting (int empID[], double overtimePay[], double grossPay[], double stateTax[],
                            double federalTax[], double totalTax[],double unionDues[], double netPay[],
                            double regularPay[],double hoursWorked[], double payRate[], int unionCode[], int Worker)
       {
          
      
              int hold;
       double temp;
       for (int pass = 0; pass < 10-1; pass++)
       {
           for(int j = 0; j < 10-1; j++)
                          
           {
               if(empID[j] > empID[j + 1])
                              
               {
                                  
                   hold = empID[j];
                   empID[j] = empID[j + 1];
                   empID[j + 1] = hold;
                               } }}
      
       for (int pass = 0; pass < 10-1; pass++)
                          
       {
           for(int j= 0; j < 10-1; j++)
          
           {
               if(overtimePay[j] > overtimePay[j + 1])
               temp = overtimePay[j];
               overtimePay[j] = overtimePay[j + 1];
               overtimePay[j + 1] = temp;
           } }      
      
               for (int pass = 0; pass < 10-1; pass++)
       {
           for(int j= 0; j < 10-1; j++)
          
           {
               if(grossPay[j] > grossPay[j + 1])
               {
                   temp = grossPay[j];
                   grossPay[j] = grossPay[j + 1];
                   grossPay[j + 1] = temp;
               }
           }
                                      
       }
       // Bubble Sort function for stateTax
       for(int pass = 0; pass < 10-1; pass++)
       {
          for(int j= 0; j < 10-1; j++)
       {
           if(stateTax[j] > stateTax[j + 1])
       {
               temp = stateTax[j];
               stateTax[j] = stateTax[j + 1];
                stateTax[j + 1] = temp;
       }}}
       for(int pass = 0; pass < 10-1; pass++)
       {
           for(int j= 0; j < 10-1; j++)
       {
           if(federalTax[j] > federalTax[j + 1])
           {
               temp = federalTax[j];
               federalTax[j] = federalTax[j + 1];
               federalTax[j + 1] = temp;
       }}}
       for(int pass = 0; pass < 10-1; pass++)
       {
       for(int j = 0; j < 10-1; j++)
       {
       if(totalTax[j] > totalTax[j + 1])
       {
               temp = totalTax[j];
               totalTax[j] = totalTax[j + 1];
                totalTax[j + 1] = temp;
       }}}
       for(int pass = 0; pass < 10-1; pass++)
    {
       for(int j= 0; j < 10-1; j++)
    {
       if(unionDues[j] > unionDues[j + 1])
    {
           temp = unionDues[j];
           unionDues[j] = unionDues[j + 1];
           unionDues[j + 1] = temp;
       }}}
                                                  
       for(int pass = 0; pass < 10-1; pass++)
                                                      
       {
           for(int j= 0; j < 10-1; j++)
                                                              
           {
           if(netPay[j] > netPay[j + 1])
                                                                      
               {
                                                                          
                   temp = netPay[j];
                   netPay[j] = netPay[j + 1];
                   netPay[j + 1] = temp;
           }}}
                                                  
       for(int pass = 0; pass < 10-1; pass++)
                                                      
       {
       for(int j= 0; j < 10-1; j++)
                                                          
           {
               if(regularPay[j] > regularPay[j + 1])
                                                              
               {
                                                                  
                   temp = regularPay[j];
                   regularPay[j] = regularPay[j + 1];
                   regularPay[j + 1] = temp;
           }}}                      
       for(int pass = 0; pass < 10-1; pass++)
                                                      
       {
           for(int j= 0; j < 10-1; j++)
                                                  
           {
               if(hoursWorked[j] > hoursWorked[j + 1])
                                                              
               {
                                                                  
                   temp = hoursWorked[j];
                   hoursWorked[j] = hoursWorked[j + 1];
                   hoursWorked[j + 1] = temp;
           }}}
                                              
       for(int pass = 0; pass < 10-1; pass++)
                                                      
     
       {
           for(int j= 0; j < 10-1; j++)
                                                          
           {
          
               if(payRate[j] > payRate[j + 1])
           {
                                                                      
               temp = payRate[j];
               payRate[j] = payRate[j + 1];
               payRate[j + 1] = temp;
           }}}
       for(int pass = 0; pass < 10-1; pass++)
              
    {
       for(int j= 0; j < 10-1; j++)
                                                          
       {
                                                          
           if(unionCode[j] > unionCode[j + 1])
                                                              
           {
                                                                  
               hold = unionCode[j];
               unionCode[j] = unionCode[j + 1];
               unionCode[j + 1] = hold;
       }}}
       //Declaration for displaying displayEmployeeResults
      
       void displayEmployeeResult (int empID[], char payrollType[], double hoursWorked[], double payRate[], double regularPay[], double overtimePay[],
                                   double grossPay[], double stateTax[], double federalTax[], double totalTax[],double netPay[], double unionDues[],
                                   int totalEmployees[], double totalGrossPay[], double totalNetPay[], int data [], int UnionCode [], int Worker)
       {
              
                      
                      
              
           //Output from employee
              
           std::cout << " _______________________________" << endl;
          
              for(int ID = 0; ID < Worker; ID++)
              {
           std::cout << "Payroll results for Worker #: " << data[ID];
          
           std::cout << " Your employee ID # is: " << empID [ID];
          
           std::cout << " Your payroll type is: " << payrollType [ID];
          
           std::cout << " Your hours worked: " << hoursWorked [ID];
          
           std::cout << " Your pay rate is: $" << payRate [ID];
          
           std::cout << " Your regular pay is: $" << regularPay [ID];
           std::cout << " Your overtime pay is: $" << overtimePay [ID];
      
           std::cout << " Your gross pay is: $" << grossPay [ID];
          
           std::cout << " Your state tax is: $" << stateTax [ID];
              
           std::cout <<" Your federal tax is: $" << federalTax [ID];
           std::cout << " Your total tax is: $" << totalTax [ID];
           std::cout << " Your net pay is: $" << netPay [ID];
           //Detrmination of Union Due
           switch (unionCode [ID])
           {
      
           case 1:
               unionDues [ID] = 15.00;
               std::cout << " Your union dues is: $" << unionDues [ID] << endl;
               break;
           case 2:
               unionDues [ID] = 25.00;
               std::cout << " Your union dues is: $" << unionDues [ID] << endl;
               break;
           case 3:
               unionDues [ID] = 35.00;
               std::cout << " Your union dues is: $" << unionDues [ID] << endl;
               break;
               default:
               unionDues [ID] = 0.00;
               std::cout << " Your union dues is: $" << unionDues [ID] << endl;
               break;
          
          
           } //end switch
              }
      
      
          
       // Function declaration for displayPayrollSummaryResults
       void displayPayrollSummaryResults (int totalEmployees[], double totalGrossPay[], double totalNetPay[],
                                          int empID[], double grossPay[], int Worker);
       {
                          
       // Display a summary of employee information
           std::cout << "Total number of Employees entered:"<< totalEmployees[0] << endl;
           std::cout << "Total gross pay of Employees:"<< "$"<< totalGrossPay[0] << endl;
                          
           std::cout << "Total Net pay of Employees:"<< "$"<< totalNetPay[0] << endl;
                          
           std::cout << "Average Gross pay of Employees is:"<< "$"<< totalGrossPay[0]/ totalEmployees[0] << endl;
          
           std::cout << "Average Net pay of Employees is:"<< "$"<< totalNetPay[0]/ totalEmployees[0] << endl;
          
      
       // Calculates employee with highest grosspay
           //Declaring Variables for Payroll Summary
              
               int maxEmpID = empID[0];
               double maxGrossPay = grossPay[0];
               int minEmpID = empID[0];
               double minGrossPay = grossPay[0];
               int empIndex = 0;
               int count = 0;
               int count2 = 0;
               int minGrosspay = 0;              
          
           for(count = 1; count < Worker; count++)          
           {
                              
               if(empID[count] > maxEmpID)
                              
               {
                                  
                   maxEmpID = empID[count];
                          
               }
                          
          
           }              
          
           std::cout << "Employee with highest gross pay is employee ID:" << maxEmpID << " ";
                          
           // Calculates employee with highest grosspay
                          
           for(count2 = 1; count2 < Worker; count2++)
                          
           {
                              
               if(grossPay[count2] > maxGrossPay)
                              
               {
                                  
                   maxGrossPay = grossPay[count2];
                          
               }
                           }
                          
           std::cout << "With the gross pay of:" << "$" << maxGrossPay;
          
                          
       // Calculates employee with lowest grosspay
                          
               for(count = 1; count < Worker; count++)
                              
               {
                              
                   if(empID[count] < minEmpID)
                                  
                   {
                                      
                       minEmpID = empID[count];
                                   }
                               }
                          
               std::cout << "Employee with lowest gross pay is employee ID:" << minEmpID << " ";
                          
       // Calculates employee with highest grosspay
                                                  
               for(count2 = 1; count2 < Worker; count2++)
                                                  
               {
                                                      
                   if(grossPay[count2] < minGrossPay)
                                                      
                   {
                                                          
                       minGrossPay = grossPay[count2];
                                                      
                   }
                                                  
               }
                                                  
              
               std::cout << "With the gross pay of:" << "$" << minGrossPay;
                              
               for(count2 = 1; count2 < Worker; count2++)
                              
               {
                                  
                   if(grossPay[count2] > minGrossPay)
                                      
                   {
                                          
                       maxGrossPay = grossPay[count2];
                                          
                       empIndex++;
                                       }
                               }
           std::cout << "Employee with highest gross pay is employee ID:" << empID[empIndex] << " ";
           std::cout << empIndex << endl;
           std::cout << "With the gross pay of:" << "$" << minGrossPay;
           }//End Function
          
          
          
           system("PAUSE"); // system pauses so user can see outcome on the screen
           return 0;
           }
    }
    }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote