Code:
#include <iostream>
#include <fstream>
using namespace std;
const int MAX = 100;
int n,hw[MAX],oth[MAX],rh[MAX];
float hr[MAX], rp[MAX], otp[MAX], gp[MAX], tr[MAX], ta[MAX], np[MAX];
/* Function Prototypes */
int readData(int[],float[], const int);
void getOTHours(int[],int[],int);
void getOTPay(int[],float[],float[],int);
void getRegularHours(int[],int[],int);
void getRegularPay(int[],float[],float[],int);
void getGrossPay(float[],float[],float[],int);
void getTaxRate(float[],float[],int);
void getTaxAmount(float[],float[],float[],int);
void getNetPay(float[],float[],float[],int);
void printAll(int[],float[],float[],float[],float[],float[],int);
int main()
{
// Functions
readData(hw,hr,MAX); // Grab Data
getOTHours(hw,oth,n);
getOTPay(oth,hr,otp,n);
getRegularHours(hw,rh,n);
getRegularPay(rh,rp,hr,n);
getGrossPay(rp,otp,gp,n);
getTaxRate(gp,tr,n);
getTaxAmount(gp,ta,tr,n);
getNetPay(gp,np,ta,n);
printAll(hw,hr,otp,gp,ta,np,n);
}
//Function Defs
int readData(int hw[], float hr[], int n){
ifstream fin("payroll.txt");
n = 0;
while(fin>>hw[n]>>hr[n])
n++;
//fin.close;
return n;
}
void getOTHours(int hw[],int oth[],int n){
for(int i = 0;i < n;i++){
if(hw[i] > 40) oth[i] = hw[i] - 40;
else oth[i] = 0;
}// end for loop
}
void getOTPay(int oth[], float hr[],float otp[], int n){
for(int i = 0;i < n; i++){
otp[i] = oth[i] * hr[i] * 1.5;
}
}
void getRegularHours(int hw[],int rh[], int n){
for(int i = 0;i < n; i++){
if(hw[i] > 40)
rh[i] = 40;
else rh[i] = hw[i];
}
}
void getRegularPay(int rh[],float rp[],float hr[], int n){
for(int i = 0;i < n; i++){
rp[i] = rh[i] * hr[i];
}
}
void getGrossPay(float rp[],float otp[], float gp[],int n){
for(int i = 0;i < n; i++){
gp[i] = rp[i] + otp[i];
}
}
void getTaxRate(float gp[], float tr[], int n){
for(int i = 0;i < n; i++){
tr[i] = 0.10;
}
}
void getTaxAmount(float gp[],float ta[],float tr[], int n){
for(int i = 0;i < n; i++){
ta[i] = gp[i] * tr[i];
}
}
void getNetPay(float gp[], float np[], float ta[],int n){
for(int i = 0;i < n; i++){
np[i] = gp[i] - ta[i];
}
}
void printAll(int hw[], float hr[], float otp[],float gp[], float ta[], float np[], int n){
cout<<"Hours"<<"\t"<<"Rate"<<"\t"<<"OTP"<<"\t"<<"GP"<<"\t"<<"Tax"<<"\t"<<"Net"<<endl;
for(int i = 0; i < n; i++){
cout<<" "<<"\t"<<hw[i]<<"\t"<<hr[i]<<"\t"<<otp[i]<<"\t"<<gp[i]<<"\t"<<ta[i]<<"\t"<<np[i]<<endl;
}
}