Question

Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay.

//I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort.

//My input files:

//My current code with the sel sort. Please help me replace this with an EXSEL sort.

#include <fstream>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <climits>

using namespace std;

class payroll {
public:
ifstream fin;

long int employeeid;
char marital;
string firstname, lastname;
double hourlyrate, grosspay, netpay, taxrate, mtaxrate, taxamount, regpay, otpay;
float sumOfNetPay;
double count;
int hoursworked, othours;

void computetaxrate();
void computemtaxrate();
void computenetpay();

// POLYMORPHISM
virtual void computegp();
virtual void computeotp();
virtual void printheadings();
virtual void printdata();
virtual void printreport();

payroll();
~payroll();
};

payroll::payroll() {
fin.open("hpayroll.dat");
}//CONSTRUCTOR

payroll::~payroll() {
fin.close();
}//DESTRUCTOR

void payroll::computeotp() {
if (hoursworked > 40)
othours = hoursworked - 40;
else
othours = 0;
otpay = othours * (hourlyrate * 1.5);
if (hoursworked < 40)
otpay = 0;
}//COMPUTE ALL OVERTIME HOURS/PAY

void payroll::computegp() {
grosspay = (hoursworked * hourlyrate) + otpay;
regpay = (grosspay - otpay);
}//COMPUTE ALL THE GROSSPAYS

void payroll::computetaxrate() {
if (grosspay > 1000) taxrate = 0.30;
else if ((grosspay > 800) && (grosspay <= 1000)) taxrate = 0.20;
else if ((grosspay > 500) && (grosspay < 800)) taxrate = 0.10;
else if ((grosspay >= 0) && (grosspay <= 500)) taxrate = 0.0;
}//COMPUTE TAX RATES

void payroll::computemtaxrate() {
if (marital == 'S' || marital == 's') mtaxrate += 0.05;
else if (marital == 'H' || marital == 'h') mtaxrate -= 0.05;
else mtaxrate = taxrate;
}//COMPUTE MARTIAL TAX RATES

void payroll::computenetpay() {
taxamount = (grosspay * (taxrate + mtaxrate));
netpay = (grosspay - taxamount);
sumOfNetPay += netpay;
}//COMPUTE NET PAY AS WELL AS SUM OF NETPAYS

void payroll::printheadings() {
cout << setw(45) << "-PAYROLL REPORT-" << endl;
cout << "---------------------------------------------------------------------------------------------------------"
<< endl;
cout << setw(15), setprecision(1), setiosflags(ios::fixed | ios::showpoint | ios::left);
cout << "EMP ID" << setw(14) << "MARTIAL STAT" << setw(12) << "FIRST NAME" << setw(12) << "LAST NAME"
<< setw(6) << "HW" << setw(6) << "HR" << setw(6) << "OTH" << setw(6) << "OTP" << setw(6) << "REGP" << setw(7)
<< "GROSS"
<< setw(6) << "TAX" << setw(6) << "NET" << endl;
cout << "---------------------------------------------------------------------------------------------------------"
<< endl;
}//PRINT HEADINGS

void payroll::printdata() {
cout << setw(15), setprecision(1), setiosflags(ios::fixed | ios::showpoint | ios::left);
cout << employeeid << setw(14) << marital << setw(12) << firstname << setw(12) << lastname
<< setw(6) << hoursworked << setw(6) << hourlyrate << setw(6) << othours << setw(6) << otpay << setw(6)
<< regpay << setw(7) << grosspay
<< setw(6) << taxamount << setw(6) << netpay << endl;
}//PRINT OUTPUTS

void payroll::printreport() {
int i = 0;
printheadings();
while (fin >> employeeid >> marital >> firstname >> lastname >> hoursworked >> hourlyrate) {
count++;
computeotp();
computegp();
computetaxrate();
computemtaxrate();
computenetpay();
printdata();
i++;
}//WHILE
}//PRINT REPORT

class spayroll : public payroll {
public:
double salary52;

spayroll(){};
void update(long int, char, string, string, double, int);
void printreport();
void computegp();
void computeotp();
void printdata();
void printheadings();
double get_netpay();

spayroll& operator = (const spayroll &obj) {
employeeid = obj.employeeid;
marital = obj.marital;
firstname = obj.firstname;
lastname = obj.lastname;
salary52 = obj.salary52;
hoursworked = obj.hoursworked;
netpay = obj.netpay;
othours = obj.othours;
hourlyrate = obj.hourlyrate;
grosspay = obj.grosspay;
netpay = obj.netpay;
taxrate = obj.taxrate;
mtaxrate = obj.mtaxrate;
taxamount = obj.taxamount;
regpay = obj.regpay;
otpay = obj.otpay;
sumOfNetPay = obj.sumOfNetPay;
count = obj.count;
}
};

void spayroll::update(long int eid, char ms, string f, string l, double s52, int h) {
employeeid = eid;
marital = ms;
firstname = f;
lastname = l;
salary52 = s52;
hoursworked = h;
}

// COMPUTE GROSS PAY FOR SALARY EMPLOYEE
void spayroll::computegp(){
  
regpay = salary52/52;
hourlyrate = regpay / 40;
grosspay = regpay + hourlyrate * hoursworked;
}

void spayroll::computeotp() {
otpay = hourlyrate * hoursworked;
}

void spayroll::printheadings() {
cout << setw(45) << "-PAYROLL REPORT-" << endl;
cout << "-----------------------------------------------------------------------------------------------------------------"
<< endl;
cout << setw(15), setprecision(1), setiosflags(ios::fixed | ios::showpoint | ios::left);
cout << "EMP ID" << setw(14) << "MARTIAL STAT" << setw(12) << "FIRST NAME" << setw(12) << "LAST NAME"
<< setw(10) << "HR" << setw(6) << "OTH" << setw(10) << "OTP" << setw(10) << "REGP" << setw(10)
<< "GROSS"
<< setw(10) << "TAX" << setw(10) << "NET" << endl;
cout << "-----------------------------------------------------------------------------------------------------------------"
<< endl;
}//PRINT HEADINGS

void spayroll::printdata() {
cout << setw(15), setprecision(1), setiosflags(ios::fixed | ios::showpoint | ios::left);
cout << employeeid << setw(14) << marital << setw(12) << firstname << setw(12) << lastname
<< setw(10) << hourlyrate << setw(6) << hoursworked << setw(10) << otpay << setw(10)
<< regpay << setw(10) << grosspay
<< setw(10) << taxamount << setw(10) << netpay << endl;
}//PRINT OUTPUTS

void spayroll::printreport() {
computegp();
computeotp();
computetaxrate();
computemtaxrate();
computenetpay();
printdata();
}//PRINT REPORT

double spayroll::get_netpay() {
return netpay;
}

// SELECTION SORT
void selsort(spayroll a[], int n) {
int i,j,loc;
double min;
spayroll temp;
for(i=0;i<n-1;i++) {
min = a[i].get_netpay();
loc = i;
for(j=i+1; j<n; j++) {
if(min > a[j].get_netpay()) {
min = a[j].get_netpay();
loc = j;
}
}
temp = a[i];
a[i] = a[loc];
a[loc] = temp;
}
}

int main() {
payroll employee;
cout << "---------------------------------------FOR HOURLY BASED EMPLOYEES---------------------------------------" << endl;
employee.printreport();
cout<<" "<<endl;
cout<<" "<<endl;
cout<<"Sum of Net Pay: "<<employee.sumOfNetPay<<endl;
cout<<"Average Net Pay: "<<employee.sumOfNetPay/employee.count<<endl;
ifstream fin;
long int employeeid;
char marital;
string firstname, lastname;
double salary52;
int hoursworked;
cout << "---------------------------------------FOR SALARY BASED EMPLOYEES---------------------------------------" << endl;
fin.open("spayroll.dat");
int i=0;
spayroll emp[5];
while (fin >> employeeid >> marital >> firstname >> lastname >> salary52 >> hoursworked) {
emp[i].update(employeeid, marital, firstname, lastname, salary52, hoursworked);
i++;
}
emp[0].printheadings();
for (int i=0;i<5; i++) {
emp[i].printreport();
}
float _min, _max;
_max = _min = emp[0].get_netpay();
// MIN AND MAX NETPAY FOR ALL EMPLOYEES
for (i=1; i<5; i++) {
double cur = emp[i].get_netpay();
if (cur < _min) _min = cur;
if (cur > _max) _max = cur;
}
cout<<" "<<endl;
cout<<" "<<endl;
cout << "Minimum netpay of all employees is: " << _min << endl;
cout << "Maximum netpay of all employees is: " << _max << endl;

cout << "\nSORTED EMPLOYEES BASED ON THEIR NET PAY\n";
// SORT EMPLOYEES BASED ON NETPAY
selsort(emp, 5);

emp[0].printheadings();
for (int i=0;i<5; i++) {
emp[i].printdata();
}
}//MAIN

//Current Output

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Fraction implements FractionInterface, Comparable<Fraction>
{
private int numerator;
private int denominator;

public Fraction()
{
setFraction(0,1);
} #include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

const int ARRAY_SIZE = 4;


void getEmployeeInfo(long [], int [], double [], double [], int);
  
void selectionSort(long empId[],int hours[],double payRate[],double wages[],int size);
void displayWages(long empId[], double wages[], int size);

int main()
{}
long empId[ARRAY_SIZE] = { 5658845, 4520125, 7895122,
8777541};


int hours[ARRAY_SIZE] = {0};


double payRate[ARRAY_SIZE] = {0};

double wages[ARRAY_SIZE] = {0};


getEmployeeInfo(empId, hours, payRate, wages, ARRAY_SIZE);


cout << "This is the unsorted payroll information: " << endl;
displayWages(empId, wages, ARRAY_SIZE);
  
selectionSort(empId, hours, payRate, wages, ARRAY_SIZE);

cout << "This is the sorted payroll information: " << endl;
displayWages (empId, wages, ARRAY_SIZE);

system("PAUSE");

return 0;
}

void getEmployeeInfo(long emp[], int hrs[], double rate[],
double pay[], int size)
{
cout << "Enter the requested information "
<< "for each employee.\n";


for (int count = 0; count < size; count++)
{
cout << "\nEmployee #: " << emp[count] << "\t";

cout << "Hours worked: ";
cin >> hrs[count];

  
{
cout << "\nHours worked must be 0 or more. "
<< "Please re-enter: ";
cin >> hrs[count];
}

  
cout << "\tPay rate: $";
cin >> rate[count];

  
while (rate[count] < 6.00)
{
cout << "\nPay rate must be 6.00 or more. "
<< "Please re-enter: $";
cin >> rate[count];
}


pay[count] = hrs[count]*rate[count];


}
}

void selectionSort(long empId[],int hours[],double payRate[],double wages[],int size)
{
int startScan, minIndex;
double minValue1, minValue2;
int minValue3;
long minValue4;

for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue1 = wages[startScan];
minValue2 = payRate[startScan];
minValue3 = hours[startScan];
minValue4 = empId[startScan];

for (int index = startScan + 1; index < size; index++)
{
if (wages[index] < minValue1)
{
minValue1 = wages[index];
minIndex = index;

minValue2 = payRate[index];
minIndex = index;

minValue3 = hours[index];
minIndex = index;

minValue4 = empId[index];
minIndex = index;
}
}
wages[minIndex] = wages[startScan];
wages[startScan] = minValue1;

payRate[minIndex] = payRate[startScan];
payRate[startScan] = minValue2;

hours[minIndex] = hours[startScan];
hours[startScan] = minValue3;

empId[minIndex] = empId[startScan];
empId[startScan] = minValue4;
}
}

void displayWages(long empId[], double wages[], int size)
{

cout << fixed << showpoint << setprecision(2) << endl;


cout << "----------------------------\n";
cout << "Employee Wages\n";
cout << "----------------------------\n\n";


for (int count = 0; count < ARRAY_SIZE; count++)
{
cout << "Employee #" << empId[count] << " $";
cout << setw(7) << wages[count] << endl << endl;
}

}
public Fraction(int num, int den)
{
  
setFraction(num,den);
}   

public void setFraction(int num, int den)
{
  
if(den==0)
throw new ArithmeticException();
if(den<0){
if(num<0){
den *=-1;
num *=-1;
}
else{
den*=-1;
num*=-1;

}
}
}

public double toDouble()
{
return (double) numerator / denominator;
}   

public FractionInterface add(FractionInterface aFraction)
{

Fraction z = new Fraction((numerator *((Fraction)aFraction).denominator) +
(denominator *((Fraction)aFraction).numerator),
denominator * ((Fraction)aFraction).denominator);
z.reduceFractionToLowestTerms();
return z;
}

public FractionInterface subtract(FractionInterface aFraction)
{

Fraction z = new Fraction((numerator *((Fraction)aFraction).denominator) -
(denominator *((Fraction)aFraction).numerator),
denominator * ((Fraction)aFraction).denominator);
z.reduceFractionToLowestTerms();
return z;
} // end subtract

public FractionInterface multiply(FractionInterface aFraction)
{

Fraction z = new Fraction((numerator *((Fraction)aFraction).denominator) *
(denominator *((Fraction)aFraction).numerator),
denominator * ((Fraction)aFraction).denominator);
z.reduceFractionToLowestTerms();
return z;

}

public FractionInterface divide(FractionInterface aFraction)
{

Fraction z = new Fraction((numerator *((Fraction)aFraction).denominator) /
(denominator *((Fraction)aFraction).numerator),
denominator * ((Fraction)aFraction).denominator);
z.reduceFractionToLowestTerms();
return z;
}   

public FractionInterface getReciprocal()
{

if(numerator ==0)
throw new ArithmeticException();
return new Fraction(denominator, numerator);

}


public boolean equals(Object other)
{
((Fraction)other).reduceFractionToLowestTerms();
return (numerator == ((Fraction)other).numerator) && (denominator == ((Fraction)other).denominator);

}


public int compareTo(Fraction other)
{

if(toDouble() > other.toDouble()){
return 2;
}
else if(toDouble() < other.toDouble()){
return -2;
}
else{
return 0;
} }


public String toString()
{
return numerator + "/" + denominator;
}

Add a comment
Know the answer?
Add Answer to:
Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is C++. The task is to convert the program to make use of fucntions, but...

    This is C++. The task is to convert the program to make use of fucntions, but I am am struggling to figure out how to do so. #include <iostream> #include <iomanip> using namespace std; main(){ char empid[ 100 ][ 12 ];    char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ]; int hw[ 100 ]; double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ]; int counter = 0; int i; cout<<"ENTER EMP ID,...

  • Hello, I am trying to get this Array to show the summary of NETPAY but have...

    Hello, I am trying to get this Array to show the summary of NETPAY but have been failing. What is wrong? #include <iostream> #include <iomanip> using namespace std; main(){ char empid[ 100 ][ 12 ];    char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ];    int sum; int hw[ 100 ]; double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ]; int counter = 0; int i; cout<<"ENTER EMP ID, FNAME, LNAME, HRS...

  • i am having trouble displaying results and displaying them evenly it is suppose to look like...

    i am having trouble displaying results and displaying them evenly it is suppose to look like this Enter the following data for employee 1: Employee ID: 1298 Hours worked: 35.8 Pay rate (per hour): 23.45 Enter the following data for employee 2: Employee ID: 1899 Hours worked: 34.5 Pay rate (per hour): 19.5 Enter the following data for employee 3: Employee ID: 4435 Hours worked: 30.5 Pay rate (per hour): 20.75 Enter the following data for employee 4: Employee ID:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT