"Your program should use the following one-dimensional arrays.
empId: An array of long integers to hold employee identification numbers. Assume there will be no more than 20 identification numbers, but your code should check that the file doesn't enter anymore. If an attempt is made to enter 21, process only the first 20.
hours: An array of doubles to hold the number of hours worked by each employee. Fractional hours are possible.
payRate: an array of doublesnto hold each employee's hourly pay rate.
wages: an array to hold each employee's gross wages.
The program should relate the data in each array through the subscripts. For example, the number in element 0 of the hours should be the number of hours worked by the employee whose identification number is stored in element 0 of the empId array. That same employee's pay rate should be stored in element 0 of the payRate array."
Here's what I have so far:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
const int SIZE=6;
int empId[SIZE];
double hours[SIZE];
double payRate[SIZE];
double wages[SIZE];
#include <iostream>
#include <string>
#include <fstream>
int main()
{
// If an attempt is made to enter 21, process only the first 20.
constint SIZE = 20 ;
int empId[SIZE] {} ; // initialise to all zeroes
double hours[SIZE] {} ; // initialise to all zeroes
double payRate[SIZE] {} ; // initialise to all zeroes
double wages[SIZE] {} ; // initialise to all zeroes
const std::string inFileName = "wages.txt" ; // place the name of the actual file here
std::ifstream inFile( inFileName) ; // open the file for input
if( !inFile.is_open() )
{
std::cerr << "could not open input file '" << inFileName << "'\n" ;
return 1 ; // return non-zero to indicate failure
}
// file was opened
int count = 0 ;
// check that count < SIZE first
while( count < SIZE && inFile >> empId[count] >> hours[count] >> payRate[count] ) ++count ;
for( int i = 0 ; i < count ; ++i )
{
// compute wages
// etc.
}
}