/* Author:
David Ang
Date:
Hw: Project
4
*/
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
//Prototypes
void info ();
double gross_pay ();
double tax_withheld ();
double net_pay ();
void final_display ();
//Declare and initialize
int employee_id[5]={0},
check = 1,
counter=0,
x=0;
string fname[5],
lname[5];
double hour_pay[5]= {0},
hour_worked[5]={0},
tax_rate[5]={0} ,
gr_pay[5]={0},
taxes_withheld[5]={0},
n_pay[5]={0};
//Main Function
int main ()
{
ofstream
outFile; //create
file objet
outFile.open
("E_infor.txt", ios::out); //open file
if
(outFile.is_open () ) //Determines if the file was opened
successfully
{
do {
//get user inputs
info ();
//cal. gross pay
gr_pay[counter] = gross_pay();
//cal. tax
taxes_withheld[counter] =
tax_withheld ();
//cal. net pay
n_pay[counter]= net_pay ();
//count number of employees
counter++;
cout<<setiosflags (ios::fixed
| ios::showpoint)
<<setprecision (2);
cout << "Enter negative
to quit OR a positive to continue : ";
cin >> check;
cout << endl;
} while (check >=0); //end while
//display Pay Stub
for(x; x<counter; x++)
{
final_display ();
}
outFile << setiosflags(
ios::left ) << setw( 12 ) <<"Emp. Name"
<<
setiosflags( ios::left ) << setw( 13 )<<"Emp. Num."
<<
setiosflags( ios::left ) << setw( 10 )<<"Wage"
<<
setiosflags( ios::left ) << setw( 10 )<<"Tax Rate"
<<
setiosflags( ios::left ) << setw( 10 )<<"Pay" <<
endl;
for (x=0; x<counter; x++)
{
outFile << setiosflags(
ios::left ) << setw(6)<<fname[x]
<< setiosflags( ios::left ) <<
setw(6)<<lname[x]
<< setiosflags( ios::left ) << setw( 13
)<<employee_id[x]
<< setiosflags( ios::left ) << setw( 10
)<<hour_pay[x]
<< setiosflags( ios::left ) << setw( 10
)<< tax_rate[x]
<< setiosflags( ios::left ) << setw( 10
)<< n_pay[x] << endl;
}
outFile.close (); //close
file
cout << "\nResults are
stored in 'E_infor.txt'." << endl;
}
else
cout << "File could not
be opened." << endl;
//end if for determining if file was
opended successfully
return 0;
} //end Main
//Functions
void info () //employee's
infor function
{
cout
<< "Enter Employee's ID : ";
cin
>> employee_id[counter];
cout
<< "Enter Employee's Name : ";
cin
>> lname[counter]>>fname[counter];
cout
<< "Enter Employee hours : ";
cin
>> hour_worked[counter];
cout
<< "Enter Employee wage rate : ";
cin
>>hour_pay[counter];
cout
<< "Enter Employee tax rate : ";
cin
>> tax_rate[counter];
if
(tax_rate[counter] >=1)
tax_rate[counter] = tax_rate[counter] / 100;
else
tax_rate[counter] = tax_rate[counter];
cout
<< endl;
}
double gross_pay () //cal.
gross pay function
{
gr_pay[counter]
= hour_pay[counter] * hour_worked[counter];
if
(hour_worked[counter] > 40)
gr_pay[counter]= (
40*hour_pay[counter]) + (hour_pay[counter] * (hour_worked[counter] - 40) *
1.5);
return
gr_pay[counter];
} //end of
gross pay function
double tax_withheld () //cal.
tax withheld function
{
taxes_withheld[counter]
= (gr_pay[counter] * tax_rate[counter]);
return
taxes_withheld[counter];
} //end of tax
withheld function
double net_pay () //cal.
net pay function
{
n_pay[counter]
= (gr_pay[counter] - taxes_withheld[counter]);
return
n_pay[counter];
} //end of net
pay function
void final_display () //display
Paystub function
{
cout
<<endl;
cout
<< "PAY STUB"<<endl;
cout
<< "Emp. Num: " <<employee_id[x]<<endl;
cout
<< "Hours : "
<<hour_worked[x]<<endl;
cout
<< "Wage :
"<<hour_pay[x]<<endl;
cout
<< "Gross : "<<(
40*hour_pay[x]) + (hour_pay[x] * (hour_worked[x] - 40) * 1.5)<<endl;
cout
<< "Tax : "
<<gr_pay[x] * tax_rate[x]<<endl;
cout
<< "-----------------"<<endl;
cout<< "Pay " <<(40* hour_pay[x]) + (hour_pay[x] *
(hour_worked[x] - 40) * 1.5)-gr_pay[x] * tax_rate[x] <<endl;
cout
<< "Pay to the order of : "<<lname[x]<< " "<<fname[x] <<". This amount :$"
<<n_pay[x]<<" ."<<endl;
cout
<<endl;
} // end of display