Using this code #include<fstream> #include<iostream> #include<iomanip> using nam
ID: 3850192 • Letter: U
Question
Using this code
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll
{
public:
double salary, hourlyrate, taxrate, taxamount, grosspay, netpay, overtimepay;
int hours, overtimehours;
int paystatus;
int employeeID;
string FirstName;
string LastName;
public:
void setVariables( int empID, string FirstName, string LastName, int status, int rate, int hrs )
{
employeeID = empID;
FirstName = FirstName;
LastName = LastName;
paystatus = status;
if( paystatus == 1 )
{
hourlyrate = rate;
}
else
{
salary = rate;
}
hours = hrs;
}
public:
virtual double calculateGrossPay() = 0;
double calculatetaxamount()
{
taxrate = .30;
taxamount = grosspay*taxrate;
return taxamount;
}
double calculateNetPay()
{
netpay = grosspay - taxamount;
return netpay;
}
void printData()
{
cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint);
cout << FirstName << " " << LastName << " " << employeeID << " " << hours << " "
<< overtimehours << " " << grosspay << " " << netpay << " " << overtimepay << endl;
}
};
class employeeSalary : public payroll
{
public:
double calculateGrossPay()
{
double regpay = salary/52;
double hourlyrate = regpay/40;
if (hours > 40)
{
overtimehours = (hours - 40);
overtimepay = (overtimehours * hourlyrate);
grosspay = (regpay + overtimepay);
}
else if (hours <= 40)
{
overtimehours = 0; overtimepay = 0; grosspay = regpay;
}
return grosspay;
}
};
class employeeHourly : public payroll
{
public:
double calculateGrossPay()
{
const double regpay = (40 * hourlyrate);
if ( hours > 40 )
{
overtimehours = (hours - 40);
overtimepay = (overtimehours * hourlyrate * 1.5);
grosspay = (regpay + overtimepay);
}
else
{
overtimehours = 0;
overtimepay = 0;
grosspay = regpay;
}
return grosspay;
}
};
int main()
{
int employeeCounter = 0;
int totalEmployeeCount = 0;
string FirstName, LastName;
int empID = 0, status = 0, rate = 0, hrs = 0;
cout << "enter # of employees you want to process: ";
cin >> totalEmployeeCount;
payroll* employee[100];
while( employeeCounter < totalEmployeeCount )
{
cout<<"Is employee "<< employeeCounter+1 << " hourly or salary? (enter 1 for hourly / 2 for salary):";
cin>>status;
if (status == 1)
{
cout << "Instantiating and HOURLY employee object inherited from base class employee" << endl << endl;
cout<<"ENTER EMPLOYEEID: ";
cin>>empID;
cout<<"ENTER FIRST NAME: ";
cin>>FirstName;
cout<<"ENTER LAST NAME: ";
cin>>LastName;
cout<<"ENTER HOURLY RATE: ";
cin>>rate;
cout<<"ENTER HOURS WORKED: ";
cin>>hrs;
employee[employeeCounter] = new employeeHourly();
employee[employeeCounter]->setVariables( empID, FirstName, LastName, status, rate, hrs );
employee[employeeCounter]->calculateGrossPay();
employee[employeeCounter]->calculatetaxamount();
employee[employeeCounter]->calculateNetPay();
cout<<endl<<endl;
employeeCounter++;
}
else
{
cout<<"instantialting a SALARY employee object in herited from base class employee"<<endl<<endl;
cout<<"ENTER EMPLOYEEID: ";
cin>>empID;
cout<<"ENTER FIRST NAME: ";
cin>>FirstName;
cout<<"ENTER LAST NAME: ";
cin>>LastName;
cout<<"ENTER ANNUAL SALARY: ";
cin>>rate;
cout<<"ENTER HOURS WORKED: ";
cin>>hrs;
employee[employeeCounter] = new employeeSalary();
employee[employeeCounter]->setVariables(empID, FirstName, LastName, status,
rate, hrs);
employee[employeeCounter]->calculateGrossPay();
employee[employeeCounter]->calculatetaxamount();
employee[employeeCounter]->calculateNetPay();
cout<<endl<<endl;
employeeCounter++;
}
}
cout << "----------------------------------------- ";
cout << "Name ID Hrs OT Gross Net OTPay " << endl;
for ( int i = 0; i < employeeCounter; ++i )
employee[ i ]->printData();
cout << "----------------------------------------- ";
return 0;
}
I need use a bubble sort and then print out the max and mins by accessing the the first employee objects net pay and the last employee objects net pay in a cout statement
I was trying to use this sort fromy my previous assignment as an example
Explanation / Answer
//Hi you can use the below sample code for writing bubble //sort.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.