1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#include<fstream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
const int MAX = 2;
class payroll{
ifstream fin;
char employeeid[12];
char employeename[20];
char maritalstatus;
int hoursworked,overtime;
int numberOfEmployees;
int totalEmployeeCount;
char employee;
int n;
int i, j;
double hourlyrate, overtimepay, regularpay, hourlygrosspay, salarygrosspay, taxrate, taxamount, netpay, averagenetpay;
void calculatehourlygrosspay();
void calculatesalarygrosspay();
void calculatehourlytax();
void calculatesalarytax();
void calculatehourlynetpay();
void calculatesalarynetpay();
void calculateaveragenetpay();
void sortNetPayUsingExselSort();
int printheader();
void printdata();
public: payroll();
~payroll();
void printreport(); };
payroll::payroll(){
fin.open("payroll.txt");}//CONSTRUCTOR
payroll::~payroll(){
fin.close(); }//DESTRUCTOR
void payroll::calculatehourlygrosspay(){
if(hoursworked > 40){
overtime = hoursworked - 40;
regularpay = hoursworked * hourlyrate;
overtimepay = overtime * (hourlyrate * 1.5);
hourlygrosspay = regularpay + overtimepay; }//IF
else hourlygrosspay = hoursworked * hourlyrate; }//CALCULATEGROSSPAY
void payroll ::calculatehourlytax(){
if (hourlygrosspay >= 500) taxrate = .20;
else if(hourlygrosspay > 200.00) taxrate = .20;
else taxrate = .10;
if(maritalstatus == 'S'|| maritalstatus=='s')
taxrate = taxrate + .05;
taxamount = hourlygrosspay * taxrate; }//CALCULATETAX
void payroll :: calculatehourlynetpay(){
netpay = hourlygrosspay - taxamount; }//CALCULATENETPAY
void payroll::calculatesalarygrosspay(){
if(hoursworked>0){
overtimepay=hoursworked*(regularpay/52/40);
regularpay=hourlyrate/52;
salarygrosspay=regularpay+overtimepay; }//If
else salarygrosspay = hoursworked * hourlyrate; }//CALCULATEGROSSPAY
void payroll ::calculatesalarytax(){
if (salarygrosspay >= 500) taxrate = .20;
else if(salarygrosspay > 200.00) taxrate = .20;
else taxrate = .10;
if(maritalstatus == 'S'|| maritalstatus=='s')
taxrate = taxrate + .05;
taxamount = salarygrosspay * taxrate; }//CALCULATETAX
void payroll :: calculatesalarynetpay(){
netpay = salarygrosspay - taxamount; }//CALCULATENETPAY
void payroll :: calculateaveragenetpay(){
averagenetpay=netpay / 2; }//CALCULATEAVERAGENETPAY
//Sort the employee object array in ascending
int printHeader(); //call function to print the header
char employee[0], printData(); //print the first element of employee object array
int i, j;
int totalEmployeeCount;
//initial loop to the netPay array
for ( i = 1; i < totalEmployeeCount; i++ ){
//second loop to actual values
for ( j = 0; j < totalEmployeeCount - i; j++ ){
if ( employee[j]->netPay > employee[j+1]->netPay )
payroll * temp;
//do the actual swap
temp = employee[j];
employee[j] = employee[j+1];
employee[j+1] = temp;
} //end if
}//end for loop
} //end for loop
==========
void sortNetPayUsingExselSort(employee * employees[], int numberOfEmployees)
{
int lower, upper, sortflag = 0, sml = 0, scan = 0;
lower = 0;
upper = numberOfEmployees - 1;
while( (lower < upper) && (sortflag == 1) )
{
sml = lower;
sortflag = 0;
scan = lower + 1;
while (scan <= upper - ...)
{
if( employees[scan]->getNetPay() > employees[scan + 1]->getNetPay() )
{
swap(employees, scan, scan + 1);
sortflag = ...;
if( employees[scan]->getNetPay() < employees[sml]->...)
{
sml = scan;
}
}
scan++;
} // while
swap(employees, lower, sml);
upper = upper - 1;
lower = lower + ...;
} // while
void payroll::printdata(){
cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
cout<<setw(6)<<employeename<<setw(12)<<employeeid<<setw(4)
<<hoursworked<<setw(3)<<overtime<<setw(8)<<taxamount<<setw(8)
<<netpay<<setw(8)<<averagenetpay<<endl; }//PRINTDATA
void payroll::printreport(){
int i = 0;
printheadings();
while(fin>>employeename>>employeeid>>maritalstatus>>hoursworked>>hourlyrate){
calculatehourlygrosspay();
calculatesalarygrosspay();
calculatehourlytax();
calculatesalarytax();
calculatehourlynetpay();
calculatesalarynetpay();
calculateaveragenetpay();
sortNetPayUsingExselSort();
printdata();
i++; }//WHILE
}//PRINTREPORT
int main(){
payroll employee;
employee.printreport(); }//MAIN
|