﻿ Two-Dimensional Arrays
```//*********************************************************
// GrossPay5.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 MAXROWS = 100;
const int MAXCOLS = 3;
const int WAGE = 0;   // Indicates wage column
const int HOURS = 1;  // Indicates hours column
const int PAY = 2;    // Indicates pay column

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

infile.open("EmployeeData.txt");
n = 0;
infile >> identity >> wageRate >> hoursWorked;
while (!infile.fail() && n < MAXROWS)
{
id[n] = identity;
data[n][WAGE] = wageRate;
data[n][HOURS] = hoursWorked;
n = n+1;

infile >> identity >> wageRate >> hoursWorked;
}
infile.close();
}

//*********************************************************
// calculateGrossPay
//
// In Parameter: n
//
// In/Out Parameter: data
//
// Returns: void
//*********************************************************
void calculateGrossPay(double data[][MAXCOLS], int n)
{
for(int i = 0; i < n; i++)
{
if (data[i][HOURS] <= MAXHOURS)
{
data[i][PAY] = data[i][HOURS] * data[i][WAGE];
}
else
{
data[i][PAY] = MAXHOURS * data[i][WAGE]
+ (data[i][HOURS] - MAXHOURS)
* OT_MULTIPLIER * data[i][WAGE];
}
}
}

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

outfile.open("PayrollReport5.txt");

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

//**********************************************************
//              M A I N   D R I V E R
//**********************************************************
int main()
{
int n;                          // Number of employees
string identity[MAXROWS];       // Employee identifiers
double data[MAXROWS][MAXCOLS];  // Employee data

getEmployeeData(identity, data, n);
calculateGrossPay(data, n);
displayGrossPay(identity, data, n);

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

return 0;
}```