﻿ Parallel Arrays
```//*********************************************************
// GrossPay2.cpp
//
// Calculate and display the gross pay given the hourly
// wage and the number of hours worked.
//
// D. Searls
// Asbury College
// Aug 2003
//*********************************************************
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;

const double MAXHOURS = 40.0;
const double OT_MULTIPLIER = 1.5;
const int MAXSIZE = 100;

//*********************************************************
// getEmployeeData
//
// Out Parameters: identity, hours, wageRate, n
//
// Returns: void
//*********************************************************
void getEmployeeData(string identity[], double hours[],
double wageRate[], int & n)
{
ifstream infile;
string id;
double hourlyWage;
double hoursWorked;

infile.open("EmployeeData.txt");
n = 0;
infile >> id >> hourlyWage >> hoursWorked;
while (!infile.fail() && n < MAXSIZE)
{
identity[n] = id;
wageRate[n] = hourlyWage;
hours[n] = hoursWorked;
n = n+1;

infile >> id >> hourlyWage >> hoursWorked;
}
infile.close();
}

//*********************************************************
// calculateGrossPay
//
// In Parameters: hours, payRate, n
//
// Out Parameter: grossPay
//
// Returns: void
//*********************************************************
void calculateGrossPay(const double hours[], const double payRate[],
double grossPay[], int n)
{
for(int i = 0; i < n; i++)
{
if (hours[i] <= MAXHOURS)
{
grossPay[i] = hours[i] * payRate[i];
}
else
{
grossPay[i] = MAXHOURS * payRate[i]
+ (hours[i] - MAXHOURS) * OT_MULTIPLIER * payRate[i];
}
}
}

//*********************************************************
// displayGrossPay
//
// In Parameters: id, grossPay, n
//
// Returns: void
//*********************************************************
void displayGrossPay(const string employeeID[],
const double grossPay[], int n)
{
ofstream outfile;

outfile.open("PayrollReport2.txt");

outfile << fixed << setprecision(2);
outfile << "Employee  Gross Pay" << endl;
outfile << "--------  ---------" << endl;
for (int i = 0; i < n; i++)
{
outfile << setw(8) << employeeID[i]
<< setw(11) << grossPay[i] << endl;
}
outfile.close();
}

//*********************************************************
//               M A I N   D R I V E R
//*********************************************************

int main()
{
int n;              // Number of employees
string empID[MAXSIZE];
double hoursWorked[MAXSIZE];
double hourlyWage[MAXSIZE];
double grossPay[MAXSIZE];

getEmployeeData(empID, hoursWorked, hourlyWage, n);
calculateGrossPay(hoursWorked, hourlyWage, grossPay, n);
displayGrossPay(empID, grossPay, n);

cout << "Output sent to 'PayrollReport2.txt'" << endl;

return 0;
}```