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
|
#include <iostream> //including library (directive header file)
#include <windows.h> //makes console look pretty
#include <fstream> //Library to read files
#include <iomanip>
using namespace std;
int main() {
SetConsoleTitleW(L"Payroll System"); //Set Console Title
ifstream input;
input.open("numemployees4.txt"); //Opens the file
char ms[6] = {'H', 'h', 'M', 'M', 'S', 's'};
char employeeid[100][12];
char firstname[100][14], lastname[100][15];
int hoursworked[100];
double hourlyrate[100], grosspay[100], taxamount[100], taxrate[100], netpay[100], ot[100], otpay[100], regpay[100];
int counter = 0;
int i;
while (input >> firstname[counter]>> lastname[counter]>> employeeid[counter] >> hoursworked[counter] >> hourlyrate[counter] >> ms[100])
counter = counter + 1;
for (i = 0; i < counter; i++){
if (hoursworked[i] > 40)
ot[i] = hoursworked [i] - 40;
otpay[i] = ot[i] * hourlyrate[i] * 1.5;
regpay [i] = 40 * hourlyrate[i];
}
if (ot[i] = 0){
otpay[i] = 0;
regpay [i] = hoursworked[i] * hourlyrate[i];
}
for (i = 0, i < counter; i++;) {
grosspay[i] = regpay[i] + otpay[i] ;
}
for (i = 0; i < counter; i++){
if (grosspay[i] > 1000)
taxrate[i] = 0.30;
else if (grosspay [i] > 800)
taxrate [i] = 0.20;
else if (grosspay [i] > 500)
taxrate[i] = 0.10;
}
for (i = 0; i < counter; i++){
if (ms[i] == 's' || ms[i] == 'S')
taxrate[i] = taxrate[i] + 0.05;
else if (ms[i] == 'h' || ms[i] == 'H')
taxrate[i] = taxrate[i] - 0.05;
else if (ms[i] == 'm' || ms[i] == 'M')
taxrate[i] = taxrate[i];
}
for (i = 0; i < counter; i++){
taxamount[i] = grosspay[i] * taxrate[i];
}
for (i = 0; i < counter; i++){
netpay[i] = grosspay[i] - taxamount[i];
}
cout << setw(7) << "FIRST NAME" <<setw(14)<< "LAST NAME"<<setw(14)<< "EMPLOYEE ID" << setw(7) << "STAT" << setw(14) << "HOURS WORKED" << setw(14) << "GROSS PAY" <<endl << endl;
for (i=0; i<counter; i++){
cout<< setw(7)<< firstname[i] << setw(14)<< lastname[i]<< setw(14)<< employeeid[i]<< setw(7)<< ms[counter] <<setw(14)<< hoursworked[i] <<setw(14)<<grosspay[i]<<endl;
}
cout << "\n"; //Creates space
input.close(); //Closes the open file
//system("pause");
return 0;
}
|