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 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int maxsize = 20;
class employee {
public:
ifstream fin;
int data;
std::string id;
std::string first_name;
std::string last_name;
std::string martial_status;
int hours_worked;
int overtime_hours;
int regular_hours;
int salary;
int salary_hours;
float hourly_rate;
float regular_pay;
float overtime_pay;
float gross_pay;
float tax_rate = 0.30;
float tax_amount;
float net_pay;
float sum;
float average;
float n1, n2, n3, n4, n5, n6, n7;
float p1, p2, p3, p4, p5, p6, p7;
void find_overtime_pay ();
void find_regular_pay ();
void find_gross_pay ();
void find_tax_amount ();
void find_net_pay ();
void acknowledge_netpay();
void acknowledge_netpay2();
void calculate_average();
void print_headings ();
void print_all_data ();
employee();
~employee();
void print_average();
};
class hourlyemployee: public employee {
public:
ifstream fin;
void find_regular_hours();
void find_overtime_hours();
//void acknowledge_netpay();
void print_report();
hourlyemployee();
~hourlyemployee();
};
class salariedemployee: public employee {
public:
ifstream fin;
void find_salary_hours();
void find_hourly_rate();
void find_regular_hours2();
void find_overtime_hours2();
//void acknowledge_netpay2();
void print_report2();
salariedemployee();
~salariedemployee();
};
int n;
char id [maxsize];
char first_name [maxsize];
char last_name [maxsize];
char martial_status [maxsize];
int hours_worked;
int overtime_hours;
int regular_hours;
int salary;
float hourly_rate;
float regular_pay;
float overtime_pay;
float gross_pay;
float tax_rate;
float tax_amount = 0.30;
float net_pay;
int i = 1;
int c = 1;
float n1;
float n2;
float n3;
float n4;
float n5;
float n6;
float n7;
float p1, p2, p3, p4, p5, p6, p7;
float sum;
float average;
employee::employee(){
fin.open("");
}//Constuctor
employee::~employee(){
fin.close();
}//Destructor
hourlyemployee::hourlyemployee(){
fin.open("payroll8.txt");
}//Constuctor
hourlyemployee::~hourlyemployee(){
fin.close();
}//Destructor
salariedemployee::salariedemployee(){
fin.open("payroll10.txt");
}//Constuctor
salariedemployee::~salariedemployee(){
fin.close();
}//Destructor
void salariedemployee::find_salary_hours()
{
salary_hours = hours_worked/52;
}
void salariedemployee::find_hourly_rate()
{
hourly_rate = salary/52/40;
}
void hourlyemployee::find_overtime_hours()
{
if( hours_worked > 40 ) overtime_hours = hours_worked - 40;
else overtime_hours = 0;
}
void salariedemployee::find_overtime_hours2()
{
if ( salary_hours > 40 ) overtime_hours = salary_hours - 40;
else overtime_hours = 0;
}
void employee::find_overtime_pay()
{
overtime_pay = overtime_hours * hourly_rate * 1.5;
}
void hourlyemployee::find_regular_hours()
{
if( hours_worked > 40 ) regular_hours = 40;
else regular_hours = hours_worked;
}
void salariedemployee::find_regular_hours2()
{
if( salary_hours > 40 ) regular_hours = 40;
else regular_hours = salary_hours;
}
void employee::find_regular_pay()
{
regular_pay = regular_hours * hourly_rate;
}
void employee::find_gross_pay()
{
gross_pay = regular_pay + overtime_pay;
}
/*void employee::find_tax_rate()
{
if( gross_pay > 1000 ) tax_rate = 0.30;
else if(gross_pay > 800 ) tax_rate = 0.20;
else if(gross_pay > 500 ) tax_rate = 0.10;
else tax_rate = 0.00;
if( martial_status == "s" or "S") tax_rate + 0.05;
else if( martial_status == "h" or "H") tax_rate - 0.05;
else tax_rate + 0.00;
}*/
void employee::find_tax_amount()
{
tax_amount = gross_pay * tax_rate;
}
void employee::find_net_pay()
{
net_pay = gross_pay - tax_amount;
}
void employee::acknowledge_netpay()
{
if (i == 1) n1 = net_pay;
else if (i == 2) n2 = net_pay;
else if (i == 3) n3 = net_pay;
else if (i == 4) n4 = net_pay;
else if (i == 5) n5 = net_pay;
else if (i == 6) n6 = net_pay;
else if (i == 7) n7 = net_pay;
//cout << "n1 is " << n1 << endl;
//cout << "n7 is " << n7 << endl;
}
void employee::acknowledge_netpay2()
{
if (c == 1) p1 = net_pay;
else if (c == 2) p2 = net_pay;
else if (c == 3) p3 = net_pay;
else if (c == 4) p4 = net_pay;
else if (c == 5) p5 = net_pay;
else if (c == 6) p6 = net_pay;
else if (c == 7) p7 = net_pay;
//cout << "p7 is " << p7 << endl;
}
void employee::calculate_average()
{
sum = n1 + n2 + n3 + n4 + n5 + n6 + n7 + p1 + p2 + p3 + p4 + p5 + p6 + p7;
average = sum/7;
//cout << "Sum = " << sum << endl;
//cout << "Average = " << average << endl;
}
void employee::print_headings() {
cout << "ID" << "\t" << "FName"<< "\t" << "LName" << "\t" << "Status" << "\t" << "HW" << "\t" << "HR" << "\t " << "OP" << "\t" << "Gross" << "\t" << "Tax"<< "\t" << "Net"<<endl;
}
void employee::print_all_data()
{
std::cout << id<<"\t"<< first_name<<"\t"<< last_name<<setw(5) << martial_status<< "\t"<< hours_worked<< "\t"<<hourly_rate<< "\t " << overtime_pay<< "\t"
<< gross_pay<< "\t" << tax_amount<< "\t"<< net_pay<<std::endl;
}
void hourlyemployee::print_report()
{
print_headings();
while (fin >> id >> first_name >> last_name >> martial_status >> hours_worked >> hourly_rate ) // *******
{
find_overtime_hours();
find_overtime_pay();
find_regular_hours();
find_regular_pay();
find_gross_pay();
find_tax_amount();
find_net_pay();
acknowledge_netpay();
acknowledge_netpay2();
i++;
calculate_average();
print_all_data();
}
}
void salariedemployee::print_report2()
{
while (fin >> id >> first_name >> last_name >> martial_status >> hours_worked >> salary ) // *******
{
find_salary_hours();
find_hourly_rate();
find_overtime_hours2();
find_overtime_pay();
find_regular_hours2();
find_regular_pay();
find_gross_pay();
find_tax_amount();
find_net_pay();
acknowledge_netpay();
acknowledge_netpay2();
c++;
calculate_average();
print_all_data();
}
}
/*void employee::print_average()
{
std::cout << n1 << " + " << n2 << " + " << n3 << " + " << n4 << " + " << n5 << " + " << n6 << " + " << n7 << " = " << sum <<std::endl;
std::cout << "The average net pay is " << average <<std::endl;*/
}
int main ()
{
employee employee;
hourlyemployee hourlyemployee;
salariedemployee salariedemployee;
hourlyemployee.print_report();
salariedemployee.print_report2();
employee.print_average();
return 0;
}//MAIN
|