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
|
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
const float FEDTAX_RATE = 0.18, STATETAX_RATE = 0.045, //error C2062 float unexpected
const float HOSPITALIZATION = 25.65, UNION_DUES = 0.02; //error C2062
void GetData(string &, float &, float &, bool, bool);
void Calc(float, float, float&, float&, float&, float&, float&, float&, float&, float&);
void SendData(string, float, float, float, float, float, float, float, float,float);
ifstream infile;
ofstream outfile, errorfile;
int main() {
string Name;
int i, j, row = 10, col = 8;
float HoursWorked, HourlyRate;
float TotalHoursWorked, GrossPay,
float FedW, StateW, Union, Hospital, TotalDeductions, NPay;
bool RateError, HoursError;
string Name;
infile.open("Payln.txt");
errorfile.open("FileError.txt");
outfile.open("PayOut.txt");
if (!outfile || !errorfile)
{
cout << "Cannot write the file, please open the Output file" << endl;
cout << "program terminates..." << endl;
exit(1);
}
infile >> Name >> HoursWorked >> HourlyRate;
while (!infile.eof())
{
GetData(Name, HoursWorked, HourlyRate, HoursError, RateError);
if (!HoursError && !RateError)
{
Calc(HoursWorked, HourlyRate, TotalHoursWorked, GrossPay, FedW, StateW, Union, Hospital, TotalDeductions, NPay); //error undeclared identifier
SendData(Name, TotalHoursWorked, HourlyRate, GrossPay, FedW, StateW, Union, Hospital, TotalDeductions, NPay); //error undeclared identifier
}
} // end while
infile >> Name >> HoursWorked >> HourlyRate;
infile.close();
outfile.close();
errorfile.close();
return 0;
} // main end braces
// read data from the files and checking errors
void GetData(string &Name, float &HoursWorked, float &HourlyRate, bool HoursError, bool RateError)
{
infile >> Name >> HoursWorked >> HourlyRate;
HoursError = 25.0;
RateError < 0.0;
if (HoursError)
errorfile << "Error data, should be at least 24 hours:" << Name << " " << HoursWorked << " " << HourlyRate << endl;
if (RateError)
errorfile << "Error data, regulars rate is $8.75: " << Name << " " << HoursWorked << " " << HourlyRate << endl;
}
// Calculate total hours worked, grosspay, deductions and netpay
void Calc(float HoursWorked, float HourlyRate, float &TotalHoursWorked, float &GrossPay, float &FedWithholding, float &StateWithholding, float &UnionDues, float & Hospitalization, float &Deductions, float &NetPay)
{
TotalHoursWorked = TotalHoursWorked + HoursWorked;
GrossPay = TotalHoursWorked * HourlyRate;
FedWithholding = FEDTAX_RATE * GrossPay;
StateWithholding = STATETAX_RATE * GrossPay;
UnionDues = UNION_DUES * GrossPay; //error undeclared identifier
Hospitalization = HOSPITALIZATION; //error undeclared identifier
Deductions = FedWithholding + StateWithholding + UnionDues + Hospitalization;
NetPay = GrossPay - Deductions;
}
// Output the valid data to PayOut.txt file
void SendData(string Name, float TotalHoursWorked, float HourlyRate, float GrossPay, float FedWithholding, float StateWithholding, float UnionDues, float Hospitalization, float Deductions, float NetPay)
{
outfile << fixed << showpoint << setprecision(2);
outfile << "Employees Initials : " << Name << endl;
outfile << "Total Hours Worked : " << TotalHoursWorked << endl;
outfile << "Hourly Rate Pay : " << HourlyRate << endl;
outfile << "Gross Pay : " << GrossPay << endl;
outfile << "Federal Withholding : " << FedWithholding << endl;
outfile << "State Withholding : " << StateWithholding << endl;
outfile << "Union Dues : " << UnionDues << endl;
outfile << "Hospitalization : " << Hospitalization << endl;
outfile << "Total Deductions : " << Deductions << endl;
outfile << "Net Pay : " << NetPay << endl;
}
|