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

Complete C++ program for Payroll of Employees do the folowing: 1. Print the foll

ID: 3861013 • Letter: C

Question

Complete C++ program for Payroll of Employees do the folowing:

1. Print the following header at the top of the output page:

Hills Corporation Payroll

2. Read an unknown number of employee data records as shown below. Each group of data will contain employee's first and last name, hours worked, rate of pay and age. A typical group of data will be:

O'Doyle Tom

45.00 3.25 51

Print the data as it is read; together with appropiate message (e.g., the name is...., the rate of pay is.....,etc).

3. For each employee, compute and print the employee's base pay, which includes overtime( paid at one and half times the normal rate) for each hour over 40. For example, if an employee earning $20.00 per hour works for 48 hours, then she will be paid for 40 hours at her normal rate plus 8 extra hours at $30.00 (one and a half times $20.00).

4. For each employee compute the tax paid by the employee, accoriding to this formula: If the employee is 55 years old (or older), then the employee pays tax at a rate of 50% of the base pay; if the employee is below 55, then the tax is 10% of the base pay. Print the tax and the net pay after taxes.

5. Repeat this process until you have read the last employee. You must decide how to detect the end of the data(you should explian your method in a comment).

6. Print the age and name of the oldest employee. Do the same for the youngest employee.

7. After all your results have been printed, print a message saying that the payroll program is complete.

The data below should be placed in a text file named hillscorp.txt.

Data:

O'Doyle Tom

45.0 3.50 60

Smith John

35 3.50 55

Johnson Charles

35 3.50 20

Davis William

40 3.50 60

Wilson Robert

45 3.50 20

Garcia David

40 3.50 20

Anderson Richard

45 3.50 55

Taylor Michael

35 3.50 60

Garcia James

40 3.50 55

Lopez Joseph

40 3.50 30

Walker Paul

45 3.50 25

Clark Christopher

35 3.50 20

Lopez Matthew

25 3.50 30

Perez Anthony

35 3.50 25

Jackson Jack

45 3.50 30

Explanation / Answer

/**
C++ program that reads a text file data.txt
and print data to console. The program prints
youngest,oldest employee and most paid employee
and sort the data by net pay to console.
*/
//Main.cpp
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<stdlib.h>
using namespace std;


void printOldestEmp(string firstName[], string lastName[], int age[], int size);
void printYoungesttEmp(string firstName[], string lastName[], int age[], int size);
void mostPaid(string firstName[], string lastName[], float tax[], int size);
void sortedNetPay(string firstName[], string lastName[],int hours[], float pay[],int age[],
   float basePay[], float tax[], float netPay[],int size);
void print(string firstName[], string lastName[],int hours[], float pay[],int age[],
   float basePay[], float tax[], float netPay[],int size);

int main()
{
   const int SIZE=20;
  

   string filename="data.txt";
   string firstName[SIZE];
   string lastName[SIZE];  
   int counter=0;
   int hours[SIZE];
   float pay[SIZE];
   int age[SIZE];
   float basePay[SIZE]   ;
   float tax[SIZE];
   float netPay[SIZE];

   ifstream fin;
   fin.open(filename);

   if(!fin)
   {
       cout<<"FILE NOT EXISTS"<<endl;
       exit(-1);
   }

   cout<<left;
   cout<<setw(20)<<"Name "
           <<setw(8)<<"Hours"
           <<setw(8)<<"Pay"
           <<setw(8)<<"Age"
           <<setw(8)<<"Base"
           <<setw(8)<<"Tax"
           <<setw(8)<<"NetPay"
           <<endl;

   while(!fin.eof())
   {
       fin>>firstName[counter]>>lastName[counter];
      

       int commaPos = firstName[counter].find(",");
       firstName[counter] = firstName[counter].substr(0, commaPos);
       fin>>hours[counter]>>pay[counter]>>age[counter];


       if(hours[counter]>40)
           basePay[counter]=hours[counter]*pay[counter]+(hours[counter]-40)*pay[counter];
       else
           basePay[counter]=hours[counter]*pay[counter];


       if(age[counter]>55)
           tax[counter]=basePay[counter]*0.5;
       else
           tax[counter]=basePay[counter]*0.1;

       netPay[counter]=basePay[counter]-tax[counter];
      
       cout<<setw(10)<<firstName[counter]
           <<setw(10)<<lastName[counter]
           <<setw(8)<<hours[counter]
           <<setw(8)<<pay[counter]
           <<setw(8)<<age[counter]
           <<setw(8)<<basePay[counter]
           <<setw(8)<<tax[counter]
           <<setw(8)<<netPay[counter]
           <<endl;
      
      
       counter++;
   }


   printOldestEmp(firstName, lastName,age,counter);
   printYoungesttEmp(firstName, lastName,age,counter);
   mostPaid(firstName, lastName,tax,counter);
   sortedNetPay(firstName, lastName,hours, pay,age,
   basePay, tax,netPay,counter);

   print(firstName, lastName,hours, pay,age,
   basePay, tax,netPay,counter);

   system("pause");
   return 0;
}

//print data to console
void print(string firstName[], string lastName[],int hours[], float pay[],int age[],
   float basePay[], float tax[], float netPay[],int size)
{

   cout<<"Sorted By Net pay"<<endl;
   cout<<left;
   cout<<setw(20)<<"Name "
           <<setw(8)<<"Hours"
           <<setw(8)<<"Pay"
           <<setw(8)<<"Age"
           <<setw(8)<<"Base"
           <<setw(8)<<"Tax"
           <<setw(8)<<"NetPay"
           <<endl;

   for(int counter=0;counter<size;counter++)
   cout<<setw(10)<<firstName[counter]
           <<setw(10)<<lastName[counter]
           <<setw(8)<<hours[counter]
           <<setw(8)<<pay[counter]
           <<setw(8)<<age[counter]
           <<setw(8)<<basePay[counter]
           <<setw(8)<<tax[counter]
           <<setw(8)<<netPay[counter]
           <<endl;
}


//sort data by net pay
void sortedNetPay(string firstName[], string lastName[],int hours[], float pay[],int age[],
   float basePay[], float tax[], float netPay[],int size)
{


   for(int i=0;i<size;i++)
   {
       for(int j=0;j<size-1;j++)
       {

           if(netPay[j]>netPay[j+1])
           {

               string tFname=firstName[j];
               firstName[j]=firstName[j+1];
               firstName[j+1]=tFname;

               string lName=lastName[j];
               lastName[j]=lastName[j+1];
               firstName[j+1]=lName;


               int tempHours=hours[j];
               hours[j]=hours[j+1];
               hours[j+1]=tempHours;


               float tempPay=pay[j];
               pay[j]=pay[j+1];
               pay[j+1]=tempPay;


               int tempAge=age[j];
               age[j]=age[j+1];
               age[j+1]=tempAge;

               float tempBase=basePay[j];
               basePay[j]=basePay[j+1];
               basePay[j+1]=tempBase;


               float temptax=tax[j];
               tax[j]=tax[j+1];
               tax[j+1]=temptax;

               float tempnet=netPay[j];
               netPay[j]=netPay[j+1];
               netPay[j+1]=tempnet;
           }


       }
   }


}

//print most paid employee
void mostPaid(string firstName[], string lastName[], float tax[], int size)
{
   string fName=firstName[0];
   string lName=lastName[0];
   float mostPaid=tax[0];

   for(int i=1;i<size;i++)
   {
       if(tax[i]>mostPaid)
       {
           fName=firstName[i];
           lName=lastName[i];
           mostPaid=tax[i];
       }
   }


   cout<<"Most TaxPaid employee"<<endl;
   cout<<"Name : "<<fName<<" "<<lName<<endl;
   cout<<"Tax : "<<mostPaid<<endl<<endl;
}

//print oldest employee
void printOldestEmp(string firstName[], string lastName[], int age[], int size)
{
   string fName=firstName[0];
   string lName=lastName[0];
   int oldestage=age[0];

   for(int i=1;i<size;i++)
   {
       if(age[i]>oldestage)
       {
           fName=firstName[i];
           lName=lastName[i];
           oldestage=age[i];
       }
   }


   cout<<"Oldest employee"<<endl;
   cout<<"Name : "<<fName<<" "<<lName<<endl;
   cout<<"Age : "<<oldestage<<endl<<endl;


}

//print youngest employee
void printYoungesttEmp(string firstName[], string lastName[], int age[], int size)
{
   string fName=firstName[0];
   string lName=lastName[0];
   int youngage=age[0];

   for(int i=1;i<size;i++)
   {
       if(age[i]<youngage)
       {
           fName=firstName[i];
           lName=lastName[i];
           youngage=age[i];
       }
   }


   cout<<"Youngest employee"<<endl;
   cout<<"Name : "<<fName<<" "<<lName<<endl;
   cout<<"Age : "<<youngage<<endl<<endl;
}

----------------------------------------------------------------------------------------------------------------------------------------------------

Input file :data.txt

O'Doyle Tom

45.0 3.50 60

Smith John

35 3.50 55

Johnson Charles

35 3.50 20

Davis William

40 3.50 60

Wilson Robert

45 3.50 20

Garcia David

40 3.50 20

Anderson Richard

45 3.50 55

Taylor Michael

35 3.50 60

Garcia James

40 3.50 55

Lopez Joseph

40 3.50 30

Walker Paul

45 3.50 25

Clark Christopher

35 3.50 20

Lopez Matthew

25 3.50 30

Perez Anthony

35 3.50 25

Jackson Jack

45 3.50 30

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