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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
class payroll {
ifstream fin;
public: string lastname, firstName, lastName;
char ms,maritalStatus,salaried, paystatus;
int employeeid;
float taxrate;
double wage, hoursWorked, employeeId, hoursworked, overtimehours, regularhours, hourlyrate, regularpay, minnp, maxnp, taxamount, netpay, grosspay, overtimepay, yearlysalary;
double findnetpay(), maxnet(double, int), minnet(double, int);
double findgrosspayhourly();
double findgrosspaysalaried();
void settingthevariables(char[], int, char, char, double, double, double);
double getNetPay();
void printheaders();
void printdata();
void findtaxamount();
void printminmax(double, double);
payroll();
payroll(char* alastname, int aemployeeid, char ams, char apaystatus,double ahoursworked, double ahourlyrate, double ayearlysalary);
~payroll();
};
payroll::payroll(char* alastname, int aemployeeid, char ams, char apaystatus,double ahoursworked, double ahourlyrate, double ayearlysalary)
{
lastname = alastname;
aemployeeid = employeeid;
ms = ams;
paystatus = apaystatus;
hoursworked = ahoursworked;
hourlyrate = ahourlyrate;
yearlysalary = ayearlysalary;
}
class Employee {
public:
virtual double getNetPay() const;
void setID(double);
void setFirstName(string);
void setLastName(string);
void setMaritalStatus(char);
void setHoursWorked(double);
void setHourlyRate(double);
void employeeSwap(Employee x[], int i, int j);
void printdata() const;
Employee();
Employee(double id,string firstName,string lastName,char maritalStatus,double hoursWorked,double hourlyRate);
~Employee();
private:
double id;
string firstName, lastName;
char maritalStatus;
double hoursWorked, hourlyRate;
}; //class employee
class SalariedEmployee : public Employee{
public:
double getNetPay();
double setWage(double);
SalariedEmployee();
~SalariedEmployee();
private:
double wage; }; // class salaried employee
class EmployeeList {
public:
void sortByNetPayAscending();
void printdata() const;
void add(Employee *);
EmployeeList(int capacity);
~EmployeeList();
private:
const int capacity;
int size;
Employee **list;
void employeeSwap(int, int);
}; // class employee list
void Employee::employeeSwap(Employee x[], int i, int j){
Employee temp;
temp=x[i];
x[i]=x[j];
x[j]=temp; }// sorts the employees by netpay
void sortByNetPayAscending(Employee employees[], int numEmployees){
for(int i=1; i<numEmployees; i++){
for(int j=0; j<numEmployees-i;j++){
if(employees[j].getNetPay() > employees[j+1].getNetPay()){
employees[j].employeeSwap(employees,j,j+1); }}}// bubble sort netpay, keeping the data indexed
}
void payroll::findtaxamount() {
taxrate = .30;
taxamount = grosspay * taxrate;
}// findtaxamount
double payroll::findgrosspayhourly() {
if (hoursworked > 40 ) {
overtimehours = hoursworked - 40;
regularpay = 40 * hourlyrate;
overtimepay = 1.5* hourlyrate * overtimehours;
grosspay = overtimepay + regularpay ; }
else {
grosspay = hoursworked * hourlyrate;
regularpay = grosspay; }
return grosspay; }
double payroll::findgrosspaysalaried() {
regularpay = yearlysalary/52;
overtimehours = hoursworked - 40;
grosspay = regularpay;
if (hoursworked > 0) {
overtimehours = hoursworked - 40;
overtimepay = 1.5* overtimehours * (regularpay/40);
grosspay = regularpay + overtimepay;
return grosspay;
}// If
};//findgrosspay
double payroll::findnetpay() {
netpay = grosspay - taxamount;
return netpay;
}
double payroll::minnet(double minnp, int i) {
if (i == 0) {minnp = 10000000;}
if (netpay < minnp) {minnp = netpay;}
return minnp;
}
double payroll::maxnet(double maxnp, int i) {
if (i == 0) {maxnp = 0;}
if (netpay > maxnp) {maxnp = netpay;}
return maxnp;
}
void sortdata( payroll *employees[], int numOfEmployees)
{
for(int i=1; i<numOfEmployees; i++)
{
for(int j=0; j<numOfEmployees-i;j++){
if(employees[j]->getNetPay() > employees[j+1]->getNetPay())
{
payroll * tmp = employees[j];
employees[j] = employees[j+1];
employees[j+1] = tmp;
}//if you like you can use swap funtion
}// bubble sort netpay, keeping the data indexed
}//sortdata
}
void payroll::printheaders(){
cout << "------------------------------------------------------------------------------" << endl;
cout << "LAST NAME OT PAY TAX NETPAY" << endl;
cout << "-------------------------------------------------------------------------------" << endl;
}
void payroll::printdata() {
cout<<setw(15)<<left<<lastname;
cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
cout<<setw(15)<<overtimepay<<setw(15)<<taxamount<<setw(15)<<netpay<<endl; }
void payroll::printminmax(double minnp, double maxnp) {
cout<<endl<<"The Max. NETPAY is $"<<maxnp<<endl;
cout<<"The Min. NETPAY is $"<<minnp<<endl;
}
int main() {
const int MAXSIZE = 100;
string lastname[MAXSIZE];
double overtimepay[MAXSIZE],taxamount[MAXSIZE], netpay[MAXSIZE];
SalariedEmployee e;
Employee employees[6];
int numEmployees;
payroll report;
payroll settingthevariables;
payroll findgrosspay;
payroll findtaxamount ;
payroll findnetpay ;
payroll minnet;
payroll maxnet;
char alastname[14], ams, apaystatus;
int aemployeeid,n, i=0;
string firstName, lastName;
char maritalStatus,salaried;
double employeeId, hoursWorked,wage, ahoursworked, ayearlysalary, ahourlyrate, minnp, maxnp, ataxamount, anetpay,
aovertimepay;
report.printheaders();
payroll *employee[6];
ifstream fin;
fin.open("2252011.in");
while (fin>>alastname>>aemployeeid>>ams>>apaystatus>>ahoursworked>>ahourlyrate>>ayearlysalary) {
payroll *ep = new payroll(alastname, aemployeeid, ams, apaystatus, ahoursworked, ahourlyrate, ayearlysalary);
employee[i] = ep;
i++;
}
} //out of while loop
sortdata(employee,6);
int rec_count = 0;
printheader();
while(rec_count <6)
{
employee[rec_count]->printdata();
rec_count ++;
}
printfooter();
//delete of the allocated objects
rec_count = 0;
while(rec_count < 6)
delete employee[i];
}
//end of main
system ("pause");
}
|