Hey guys I'm writing a Payroll class program to calculate gross pay
Write a program that processes Payroll objects. The program should read the
employee surname,number of hours worked,and their hourly pay-rate from a file
The file is below.
So the part im currently having trouble with is writing a function to read in the data from the file into a vector so i can manipulate the vector and display my end results. Any help on how i can fix this would be great thank you!
1 2 3 4 5 6 7 8
Jones 38.5 9.50
King 40.0 9.00
Lee 16.0 7.50
Sanchez 40.0 8.00
Smith 40.0 10.00
Taylor 38.0 8.00
Tucker 22.5 9.50
void readFunction( ifstream &inFile, vector<Payroll> &list )
{
string name;
double hours;
double rate;
double count; // count number of items in the file
Payroll temp;
if( inFile )
{
double count; // count number of items in the file
// read the elements in the file into a vector
while( inFile >> temp )
{
list.push_back( temp );
++count;
}
}
}
You'll need to overload the >> operator of Payroll for this to work. Either that, or extract each data item into individual variables, and construct a temporary Payroll object from them. then push_back the temp object.
I don't have time tonight to get into the details of how to make a constructor that would read an entire record. But someone else should be able to help.