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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
class payroll{
public:
int employeeid;
string firstname, lastname;
char taxstatus, typeemp;
double hoursworked, hourlyrate, overtimehours, overtimepay, grosspay, grosssalary, taxrate, taxamount, netpay, minnp, maxnp;
double minnet(double, int);
double maxnet(double, int);
void printminmax(double, double);
};//end class
class Employee :public payroll{
public:
ifstream input;
payroll empi[100];
int counter;
void headers();
virtual void grosspaycalc() = 0;
virtual void taxratecalc() = 0;
virtual void netpaycalc() = 0;
virtual void employee_report() = 0;
virtual void displayinfo() = 0;
void netpaysort();
};//end
class Employee_Pay : public Employee{
public:
Employee_Pay();//constructor
~Employee_Pay();//destructor
void grosspaycalc(){
for (int i = 0; i<counter; i++) {
if(empi[i].typeemp == 'S')
{
double gross_pay = empi[i].grosspay/52;
empi[i].hourlyrate = gross_pay/40;
if (empi[i].hoursworked>40) {
empi[i].overtimehours = empi[i].hoursworked - 40;
empi[i].overtimepay = 1.5*empi[i].overtimehours*empi[i].hourlyrate;
}
else
{
empi[i].overtimehours = 0;
empi[i].overtimepay = 0;
}
}
else if (empi[i].hoursworked>40){
empi[i].overtimehours = empi[i].hoursworked - 40;
empi[i].overtimepay = 1.5*empi[i].overtimehours*empi[i].hourlyrate;
empi[i].grosspay = empi[i].overtimepay + (empi[i].hoursworked*empi[i].hourlyrate);
}//end if
else
{
empi[i].overtimehours = 0;
empi[i].overtimepay = 0;
empi[i].grosspay = empi[i].hoursworked*empi[i].hourlyrate;
}
}//end for
}//end grosspay
void taxratecalc(){
for (int i = 0; i<counter; i++) {
if (empi[i].grosspay>1000) {
empi[i].taxrate = .30;
}//end if
if (empi[i].grosspay>800 && empi[i].grosspay <= 1000) {
empi[i].taxrate = .20;
}//end if
if (empi[i].grosspay>500 && empi[i].grosspay <= 800) {
empi[i].taxrate = .10;
}//end if
if (empi[i].grosspay >= 0 && empi[i].grosspay <= 500) {
empi[i].taxrate = 0;
}//end if
if ((empi[i].taxstatus == 'H' || empi[i].taxstatus == 'h') && (empi[i].grosspay>500)){
empi[i].taxrate = empi[i].taxrate - .05;
}//end if
if (empi[i].taxstatus == 'S' || empi[i].taxstatus == 's'){
empi[i].taxrate = empi[i].taxrate + .05;
}//end if
if (empi[i].taxstatus == 'M' || empi[i].taxstatus == 'm'){
empi[i].taxrate = empi[i].taxrate;
}//end if
}//end for
}//end taxrate
void netpaycalc(){
for (int i = 0; i<counter; i++) {
empi[i].taxamount = empi[i].grosspay*empi[i].taxrate;
empi[i].netpay = empi[i].grosspay - empi[i].taxamount;
}//end for
}//end
void displayinfo(){
//if (empi[i].typeemp == 'N' || empi[i].typeemp == 'n') {
cout << setiosflags(ios::fixed | ios::showpoint | ios::left) << setprecision(2);
for(int i=0; i<counter; i++)
cout << setw(10) << empi[i].employeeid << setw(12) << empi[i].firstname << setw(12) << empi[i].lastname << setw(17) << empi[i].taxstatus << setw(12) << empi[i].typeemp << setw(12) << empi[i].hoursworked << setw(12) << empi[i].hourlyrate << setw(12) << empi[i].grosspay << setw(15) << empi[i].overtimehours << setw(14) << empi[i].overtimepay << setw(12) << empi[i].taxrate * 100 << setw(12) << empi[i].taxamount << setw(12) << empi[i].netpay << endl;
//}//end if
}//end
void employee_report(){
grosspaycalc();
taxratecalc();
netpaycalc();
sortnetpay();
}//end input
};//end Employee_Pay class
Employee_Pay::Employee_Pay():Employee(){
input.open("pay.txt");
counter=0;
while (input >> empi[counter].firstname >> empi[counter].lastname >> empi[counter].employeeid >> empi[counter].taxstatus >> empi[counter].typeemp
>> empi[counter].hoursworked >> empi[counter].hourlyrate >> empi[counter].grosspay) {
counter++;
}//end while
}//end of constructor
Employee_Pay::~Employee_Pay(){
input.close();
}// end destructor
//end function
void headers();
int main(int argc, char * argv[]){
const int MAXSIZE = 70;
Employee_Pay hourly_report;
cout << setw(60) << "PAYROLL SYSTEM" << endl;
<< endl;
headers();
//for (int i = 0; i<MAXSIZE; i++) {
hourly_report.employee_report();
hourly_report.displayinfo();
//}//end for
return 0;
}// end main
void headers(){
cout << setiosflags(ios::fixed | ios::showpoint | ios::left);
cout << setw(10) << "EMP ID" << setw(12) << "FIRST NAME" << setw(12) << "LAST NAME" << setw(17) << "MARITAL STATUS" << setw(12) << "PAY TYPE" << setw(12) << "HOUR WORK" << setw(12) << "HOUR RATE" << setw(12) << "GROSS PAY" << setw(15) << "OVERTIME HOUR" << setw(14) << "OVERTIME PAY" << setw(12) << "TAX RATE" << setw(12) << "TAX AMOUNT" << setw(12) << "NET PAY" << endl;
<< endl;
}//end
//sort netpay
void Employee::netpaysort(){
for (int pass = 1; pass <= counter; pass = pass + 1) {
for (int i = 0; i<counter - 1; i = i + 1) {
if (empi[i].netpay<empi[i + 1].netpay) {
swap(empi[i].netpay, empi[i + 1].netpay);
}//end if
}//end for
}//end for
}//end
//minimum netpay
double payroll::minnet(double minnp, int n){
if(n==0){
minnp=netpay;
}
if(netpay<minnp){
minnp=netpay;
}
cout<<endl<<"The minimum net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
return minnp;
}//end minimum
//maximum netpay
double payroll::maxnet(double maxnp, int n){
if (n==0){
maxnp=netpay;
}
if(netpay>maxnp){
maxnp=netpay;
}
cout<<endl<<"The maximum net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
return maxnp;
}//end maximum
|