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

//Can anyone help me to solve this problem? I want to Initialize the first 3 Emp

ID: 3707498 • Letter: #

Question

//Can anyone help me to solve this problem? I want to Initialize the first 3 Employee array locations for each Employee Type...but It seems like over something? Also plz help me to detect errors in my code. code below....

#include <conio.h>

#include <iostream>

#include <stdlib.h>

#include <math.h>

#include <string.h>

using namespace std;

class employee

{

protected:

string employeeid;

float hours;

float pay;

float taxrate;

float overtime;

string empstatus;

public:

void setID(string id)

{

employeeid=id;

}

void sethours(float hrs)

{

hours=hrs;

}

void setpay(float payRate)

{

pay=payRate;

}

void settaxrate(float tax)

{

taxrate=tax;

}

void setstatus(string status)

{

empstatus=status;

}

string getid() {return employeeid;}

float gethours() {return hours;}

float getpay() {return pay;}

string getstatus() {return empstatus;}

employee()

{

employeeid = "N/A";

hours = 0;

pay = 0;

taxrate = 0;

overtime = 0;

empstatus = "N/A";

}

virtual void terminate(){}

virtual void calculatepay(){}

virtual void setovertime(){}

};

class Hourly : public employee

{

public:

void calculatepay()

{

cout << "Employee ID: " << employeeid;

cout << " Pay Rate: " << pay;

cout << " Regular Hours: " << hours;

cout << " Regular Pay: " << pay*hours;

cout << " Overtime Pay (if any): " << overtime*pay*1.5;

cout << " Overtime Hours (if any): " << overtime;

cout << " Gross Pay: " << (pay*hours + overtime*pay*1.5);

cout << " Taxes Withheld: " << ((pay*hours + overtime*pay*1.5)*taxrate);

cout << " Net Pay: " << (pay*hours + overtime*pay*1.5) - ((pay*hours + overtime*pay*1.5)*taxrate);

}

void Overtime()

{

if (hours <= 40)

overtime = 0;

else

overtime = hours - 40;

hours = 40;

}

void terminate()

{

pay=0;

hours=0;

taxrate=0;

overtime=0;

empstatus="Hourly - Terminated";

}

};

class Salaried : public employee

{

public:

void calculatepay()

{

cout << "Employee ID: " << employeeid;

cout << " Gross Pay: " << pay; //Annual Salary

cout << " Taxes Withheld: " << pay*taxrate;

cout << " Net Pay: " << pay - (pay*taxrate);

}

void terminate()

{

pay=0;

taxrate=0;

empstatus="Salaried - Terminated";

}

};

class Contractor : public employee

{

public:

void calculatepay()

{

cout << "Employee ID: " << employeeid;

cout << "Gross Pay: " << pay; //contractor fee

cout << "No income taxes withheld";

}

void terminate()

{

pay=0;

empstatus="Contract Ended";

}

};

int main ()

{

int option, option1, option2, option3, numb4, numb5, numb6;

string employeeid;

float hours;

float pay;

float taxrate;

string empstatus;

int numHourly = 0;

int numSalaried = 0;

int numContractor = 0;

int const size = 10;

Hourly hourly[size];

Salaried salaried[size];

Contractor contractor[size];

employee hourly[size] = {{"AS101", 32.34, 28.50, 0.055},{"GH199", 44.5, 39.22, 0.04},{"UY189", 47.22, 45.60, 0.016},};

employee salaried[size] = {{"VE320", 45,750.34, 0.07},{"BR003", 65,740.88, 0.065},{"AA891", 50,900.71, 0.12},};

employee contractor[size] = {{"BV111", 55,473.56},{"NB290", 65,540.87},{"VC100", 45,679.25},};

employee *emp;

char ans = 'y';

while (ans == 'y')

{

system("cls");

cout << " Menu";

cout << " 1 - Enter Data for Hourly Employees";

cout << " 2 - Enter Data for Salaried Employees";

cout << " 3 - Enter Data for Contractor Personnel";

cout << " 4 - Display Data for Hourly Employees";

cout << " 5 - Display Data for Salaried Employees";

cout << " 6 - Display Data for Contractor Personnel";

cout << " 7 - Terminate a Hourly Employee";

cout << " 8 - Terminate a Salaried Employee";

cout << " 9 - Terminate a Contractor";

cout << " 10 - Quit";

cout << " Enter Option(1 - 10): ";

cin >> option;

switch(option)

{

case 1:

{

system("cls");

if (numHourly >= size)

{

cout << "Over Maximum";

system("pause");

break;

}

emp = &hourly[numHourly];

while (option1!=5)

{

cout << "Hourly #" << numHourly;

cout << " 1 of 5 Enter Employee ID";

cout << " 2 of 5 Enter Total Hours Worked";

cout << " 3 of 5 Enter Pay Rate";

cout << " 4 of 5 Enter Income Tax Rate";

cout << " 5 of 5 Quit";

cout << " Enter Option(1 - 5): ";

cin >> option1;

switch (option1)

{

case 1:

cout << " Enter Employee ID: ";

getline(cin, employeeid);

emp->setID(employeeid);

break;

case 2:

cout << " Enter Total Hours Worked: ";

cin >> hours;

emp->sethours(hours);

break;

case 3:

cout << " Enter Pay Rate: ";

cin >> pay;

emp->setpay(pay);

break;

case 4:

cout << " Enter Income Tax Rate: ";

cin >> taxrate;

emp->settaxrate(taxrate);

break;

case 5:

break;

}

}

numHourly++;

break;

}

case 2:

{

system("cls");

if (numSalaried >= size)

{

cout << "Over Maximum";

system("pause");

break;

}

emp = &salaried[numSalaried];

while (option2!=4)

{

cout << "Salaried #" << numSalaried;

cout << " 1 of 4 Enter Employee ID";

cout << " 2 of 4 Enter Annal salary represented by Pay Rate";

cout << " 3 of 4 Enter Income Tax Rate";

cout << " 4 of 4 Quit";

cout << " Enter Option(1 - 4): ";

cin >> option2;

switch (option2)

{

case 1:

cout << " Enter Employee ID: ";

getline(cin, employeeid);

emp->setID(employeeid);

break;

case 2:

cout << " Enter Annal salary represented by Pay Rate: ";

cin >> pay;

emp->setpay(pay);

break;

case 3:

cout << " Enter Income Tax Rate: ";

cin >> taxrate;

emp->settaxrate(taxrate);

break;

case 4:

break;

}

}

numSalaried++;

break;

}

case 3:

{

system("cls");

if (numContractor >= size)

{

cout << "Over Maximum";

system("pause");

break;

}

emp = &contractor[numContractor];

while (option3!=4)

{

cout << "Contractor #" << numContractor;

cout << " 1 of 3 Enter Employee ID";

cout << " 2 of 3 Enter Contractor Fee represented by Pay Rate";

cout << " 3 of 3 Quit";

cout << " Enter Option(1 - 3): ";

cin >> option3;

switch (option3)

{

case 1:

cout << " Enter Employee ID: ";

getline(cin, employeeid);

emp->setID(employeeid);

break;

case 2:

cout << " Enter Annal salary represented by Pay Rate: ";

cin >> pay;

emp->setpay(pay);

break;

case 3:

break;

}

}

numContractor++;

break;

}

case 4:

{

system("cls");

cout << "Display Data for Hourly Employees";

cout << " There are " << numHourly << " in hourly class";

cout << " Enter an number from 0 to " << numHourly - 1 << ": ";

cin >> numb4;

emp = &hourly[numb4];

emp->calculatepay();

getch;

break;

}

case 5:

{

system("cls");

cout << "Display Data for Salaried Employees";

cout << " There are " << numSalaried << " in salaried class";

cout << " Enter an number from 0 to " << numSalaried - 1 << ": ";

cin >> numb5;

emp = &salaried[numb5];

emp->calculatepay();

getch;

break;

}

case 6:

{

system("cls");

cout << "Display Data for Contractor Employees";

cout << " There are " << numContractor << " in contractor class";

cout << " Enter an number from 0 to " << numContractor - 1 << ": ";

cin >> numb6;

emp = &contractor[numb6];

emp->calculatepay();

getch;

break;

}

case 7:

{

system("cls");

cout<<"Enter the Employee ID to Terminate";

cin>>employeeid;

int i=0;

for(i=0;i<numHourly;i++)

{

if(hourly[i].getid()==employeeid)

hourly[i].terminate();

}

if(i==numHourly)

cout<<"Employee Not found";

else

cout<<"Employee Terminated";

break;

}

case 8:

{

system("cls");

cout<<"Enter the Employee ID to Terminate";

cin>>employeeid;

int i=0;

for(i=0;i<numSalaried;i++)

{

if(salaried[i].getid()==employeeid)

salaried[i].terminate();

}

if(i==numSalaried)

cout<<"Employee Not found";

else

cout<<"Employee Terminated";

break;

}

case 9:

{

system("cls");

cout<<"Enter the Employee ID to Terminate";

cin>>employeeid;

int i=0;

for(i=0;i<numContractor;i++)

{

if(contractor[i].getid()==employeeid)

contractor[i].terminate();

}

if(i==numContractor)

cout<<"Employee Not found";

else

cout<<"Employee Terminated";

break;

}

case 10:

{

system("cls");

cout << "Hit Any Key to Quit...";

getch();

exit(0);

break;

}

default:

{

cout << " Input invaild...input vaild number (1 to 10)...";

cout << " Hit Any Key to continue...";

getch();

break;

}

}

}

}

The base class, Employee, has the following class member values 1. Employee ID (string such as AF201) 2. Hours (float) 3. Pay Per Hour (float) 4. Income Tax Rate (float such as 0.014, 0.022, 0.1) 5. Over time hours (float) 6. Employee Status (string such as Hourly, Salaried, Contractor) 7. Initialize (overloaded) functions for the Hourly, Salaried, Contractor Member functions include 1. SetID (pass a string to set the Employee ID for this class member) 2. SetHours (pass a float to set the Hours) 3. SetPa? (pass a float to set the Pay Rate) 4. SetTaxRate (pass a float and set the Income Tax Rate for this class member) 5. SetStatus (pass a string to set the Employee Status) 6. getID (return Employee ID) 7. getHours (return Hours) getPaV (retum Pav Per Hour 9. getStatus (return Employee Status) 10. Employee Constructor (EmpID- "N/A", numeric values -0, Employee Status - "N/A") 11. Virtual abstract function terminate 12. Virtual abstract function calculatepay 13. Virtual abstract function setovertime Derived classes 1. Hourly Class which its version of calculatepay: a. Regular Pay (hours 40) X Pay Rate X 1.5 c. Gross Pay-Regular Pay Overtime Pay Taxes - Gross Pay X Tax Rate e. Net Pay-Gross Taxes f. Display Regular Hours, Overtime Hours (if any), Pay Rate g. Display Regular Pay, Overtime Pay (if any) h. Gross Pay, Taxes Withheld, Net Pay Hourly has another function, "Overtime" i. j. k. Determines Regular Hours and any Overtime Hours based on what the Hours were If Hours 40 then Overtime Hours-0 If Hours > 40 then Regular Hours = 40 and Overtime Hours-Hours-40 Reset Hours 40 2. Salaried Class a. b. c. d. Gross Pay Pay Rate (represents "Annual Salary'" Taxes Withheld Gross Pay X Tax Rate Net Pay -Gross Pay - Taxes Withheld Display Gross, Taxes and Net Pay 3. Contractor Class

Explanation / Answer

#include <conio.h>

#include <iostream>

#include <stdlib.h>

#include <math.h>

#include <string.h>

using namespace std;

class employee

{

protected:

string employeeid;

float hours;

float pay;

float taxrate;

float overtime;

string empstatus;

public:

void setID(string id)

{

employeeid=id;

}

void sethours(float hrs)

{

hours=hrs;

}

void setpay(float payRate)

{

pay=payRate;

}

void settaxrate(float tax)

{

taxrate=tax;

}

void setstatus(string status)

{

empstatus=status;

}

string getid() {return employeeid;}

float gethours() {return hours;}

float getpay() {return pay;}

string getstatus() {return empstatus;}

employee()

{

employeeid = "N/A";

hours = 0;

pay = 0;

taxrate = 0;

overtime = 0;

empstatus = "N/A";

}

// Overload the employee constructor for hourly

employee(string eid,float h,float pr,float tr )

{

employeeid = eid;

hours = h;

pay = pr;

taxrate = tr;

overtime = 0;

empstatus = "Hourly";

}

// Overload the employee constructor for salaried

employee(string eid,float pr,float tr )

{

employeeid = eid;

hours = 0;

pay = pr;

taxrate = tr;

overtime = 0;

empstatus = "Salaried";

}

// Overload the employee constructor for contractor

employee(string eid,float pr)

{

employeeid = eid;

hours = 0;

pay = pr;

taxrate = 0;

overtime = 0;

empstatus = "Contractor";

}

virtual void terminate(){}

virtual void calculatepay(){}

virtual void setovertime(){}

};

class Hourly : public employee

{

public:

// constructor for Hourly which pass the parameter to employee constructor

// default value is given in parameter list because we passed only for 3 employes and size of array in main() function is 10

// so for rest of 7 location of hourly array it will store default value to avoid error

Hourly(string eid="",float h=0,float p=0,float tr=0):employee(eid,h,p,tr)

{}

void calculatepay()

{

cout << "Employee ID: " << employeeid;

cout << " Pay Rate: " << pay;

cout << " Regular Hours: " << hours;

cout << " Regular Pay: " << pay*hours;

cout << " Overtime Pay (if any): " << overtime*pay*1.5;

cout << " Overtime Hours (if any): " << overtime;

cout << " Gross Pay: " << (pay*hours + overtime*pay*1.5);

cout << " Taxes Withheld: " << ((pay*hours + overtime*pay*1.5)*taxrate);

cout << " Net Pay: " << (pay*hours + overtime*pay*1.5) - ((pay*hours +

overtime*pay*1.5)*taxrate);

}

void Overtime()

{

if (hours <= 40)

overtime = 0;

else

overtime = hours - 40;

hours = 40;

}

void terminate()

{

pay=0;

hours=0;

taxrate=0;

overtime=0;

empstatus="Hourly - Terminated";

}

};

class Salaried : public employee

{

public:

// constructor for Salaried which pass the parameter to employee constructor

// default value is given in parameter list because we passed only for 3 employes and size of array in main() function is 10

// so for rest of 7 location of salaried array it will store default value to avoid error

Salaried(string eid="",float pr=0,float tr=0):employee(eid,pr,tr)

{}

  

void calculatepay()

{

cout << "Employee ID: " << employeeid;

cout << " Gross Pay: " << pay; //Annual Salary

cout << " Taxes Withheld: " << pay*taxrate;

cout << " Net Pay: " << pay - (pay*taxrate);

}

void terminate()

{

pay=0;

taxrate=0;

empstatus="Salaried - Terminated";

}

};

class Contractor : public employee

{

public:

// constructor for Contractor which pass the parameter to employee constructor

// default value is given in parameter list because we passed only for 3 employes and size of array in main() function is 10

// so for rest of 7 location of contractor array it will store default value to avoid error

Contractor(string eid="",float pr=0):employee(eid,pr){}

void calculatepay()

{

cout << "Employee ID: " << employeeid;

cout << "Gross Pay: " << pay; //contractor fee

cout << "No income taxes withheld";

}

void terminate()

{

pay=0;

empstatus="Contract Ended";

}

};

int main ()

{

int option, option1, option2, option3, numb4, numb5, numb6;

string employeeid;

float hours;

float pay;

float taxrate;

string empstatus;

int numHourly = 0;

int numSalaried = 0;

int numContractor = 0;

int const size = 10;

Hourly hourly[size]={{"AS101", 32.34, 28.50, 0.055},{"GH199", 44.5, 39.22,

0.04},{"UY189", 47.22, 45.60, 0.016}}; // This will call Hourly constructor function through which parameter will be passed to Employee constructor

Salaried salaried[size]={{"VE320", 45750.34, 0.07},{"BR003", 65740.88,

0.065},{"AA891", 50900.71, 0.12}}; // This will call Salaried constructor function through which parameter will be passed to Employee constructor

Contractor contractor[size]={{"BV111", 55473.56},{"NB290", 65540.87}, // This will call Contractor constructor function through which parameter will be passed to Employee constructor

{"VC100", 45679.25}};

employee *emp;

char ans = 'y';

while (ans == 'y')

{

system("cls");

cout << " Menu";

cout << " 1 - Enter Data for Hourly Employees";

cout << " 2 - Enter Data for Salaried Employees";

cout << " 3 - Enter Data for Contractor Personnel";

cout << " 4 - Display Data for Hourly Employees";

cout << " 5 - Display Data for Salaried Employees";

cout << " 6 - Display Data for Contractor Personnel";

cout << " 7 - Terminate a Hourly Employee";

cout << " 8 - Terminate a Salaried Employee";

cout << " 9 - Terminate a Contractor";

cout << " 10 - Quit";

cout << " Enter Option(1 - 10): ";

cin >> option;

switch(option)

{

case 1:

{

system("cls");

if (numHourly >= size)

{

cout << "Over Maximum";

system("pause");

break;

}

emp = &hourly[numHourly];

while (option1!=5)

{

cout << "Hourly #" << numHourly;

cout << " 1 of 5 Enter Employee ID";

cout << " 2 of 5 Enter Total Hours Worked";

cout << " 3 of 5 Enter Pay Rate";

cout << " 4 of 5 Enter Income Tax Rate";

cout << " 5 of 5 Quit";

cout << " Enter Option(1 - 5): ";

cin >> option1;

switch (option1)

{

case 1:

cout << " Enter Employee ID: ";

getline(cin, employeeid);

emp->setID(employeeid);

break;

case 2:

cout << " Enter Total Hours Worked: ";

cin >> hours;

emp->sethours(hours);

break;

case 3:

cout << " Enter Pay Rate: ";

cin >> pay;

emp->setpay(pay);

break;

case 4:

cout << " Enter Income Tax Rate: ";

cin >> taxrate;

emp->settaxrate(taxrate);

break;

case 5:

break;

}

}

numHourly++;

break;

}

case 2:

{

system("cls");

if (numSalaried >= size)

{

cout << "Over Maximum";

system("pause");

break;

}

emp = &salaried[numSalaried];

while (option2!=4)

{

cout << "Salaried #" << numSalaried;

cout << " 1 of 4 Enter Employee ID";

cout << " 2 of 4 Enter Annal salary represented by Pay Rate";

cout << " 3 of 4 Enter Income Tax Rate";

cout << " 4 of 4 Quit";

cout << " Enter Option(1 - 4): ";

cin >> option2;

switch (option2)

{

case 1:

cout << " Enter Employee ID: ";

getline(cin, employeeid);

emp->setID(employeeid);

break;

case 2:

cout << " Enter Annal salary represented by Pay Rate: ";

cin >> pay;

emp->setpay(pay);

break;

case 3:

cout << " Enter Income Tax Rate: ";

cin >> taxrate;

emp->settaxrate(taxrate);

break;

case 4:

break;

}

}

numSalaried++;

break;

}

case 3:

{

system("cls");

if (numContractor >= size)

{

cout << "Over Maximum";

system("pause");

break;

}

emp = &contractor[numContractor];

while (option3!=4)

{

cout << "Contractor #" << numContractor;

cout << " 1 of 3 Enter Employee ID";

cout << " 2 of 3 Enter Contractor Fee represented by Pay Rate";

cout << " 3 of 3 Quit";

cout << " Enter Option(1 - 3): ";

cin >> option3;

switch (option3)

{

case 1:

cout << " Enter Employee ID: ";

getline(cin, employeeid);

emp->setID(employeeid);

break;

case 2:

cout << " Enter Annal salary represented by Pay Rate: ";

cin >> pay;

emp->setpay(pay);

break;

case 3:

break;

}

}

numContractor++;

break;

}

case 4:

{

system("cls");

cout << "Display Data for Hourly Employees";

cout << " There are " << numHourly << " in hourly class";

cout << " Enter an number from 0 to " << numHourly - 1 << ": ";

cin >> numb4;

emp = &hourly[numb4];

emp->calculatepay();

getch;

break;

}

case 5:

{

system("cls");

cout << "Display Data for Salaried Employees";

cout << " There are " << numSalaried << " in salaried class";

cout << " Enter an number from 0 to " << numSalaried - 1 << ": ";

cin >> numb5;

emp = &salaried[numb5];

emp->calculatepay();

getch;

break;

}

case 6:

{

system("cls");

cout << "Display Data for Contractor Employees";

cout << " There are " << numContractor << " in contractor class";

cout << " Enter an number from 0 to " << numContractor - 1 << ": ";

cin >> numb6;

emp = &contractor[numb6];

emp->calculatepay();

getch;

break;

}

case 7:

{

system("cls");

cout<<"Enter the Employee ID to Terminate";

cin>>employeeid;

int i=0;

for(i=0;i<numHourly;i++)

{

if(hourly[i].getid()==employeeid)

hourly[i].terminate();

}

if(i==numHourly)

cout<<"Employee Not found";

else

cout<<"Employee Terminated";

break;

}

case 8:

{

system("cls");

cout<<"Enter the Employee ID to Terminate";

cin>>employeeid;

int i=0;

for(i=0;i<numSalaried;i++)

{

if(salaried[i].getid()==employeeid)

salaried[i].terminate();

}

if(i==numSalaried)

cout<<"Employee Not found";

else

cout<<"Employee Terminated";

break;

}

case 9:

{

system("cls");

cout<<"Enter the Employee ID to Terminate";

cin>>employeeid;

int i=0;

for(i=0;i<numContractor;i++)

{

if(contractor[i].getid()==employeeid)

contractor[i].terminate();

}

if(i==numContractor)

cout<<"Employee Not found";

else

cout<<"Employee Terminated";

break;

}

case 10:

{

system("cls");

cout << "Hit Any Key to Quit...";

getch();

exit(0);

break;

}

default:

{

cout << " Input invaild...input vaild number (1 to 10)...";

cout << " Hit Any Key to continue...";

getch();

break;

}

}

}

}