Structures(struct) as Function Arguments

Okay I need help completing this assignment:


*******************************************************************************
A sample data file is provided for your testing purposes as follows:

4
101 41 8.11 Y 49
722 32 7.22 N 40
1273 23 5.43 Y 39
2584 14 6.74 N 45

The first integer in the file corresponds to the number of data rows in the file, the data rows represent employee information for a small company and is interpreted as follows:


Employee No. Department Pay Rate Exempt Hours Worked
101 41 8.11 Y 49
722 32 7.22 N 40
1273 23 5.43 Y 39
2584 14 6.74 N 45

Write a C++ program to read the employee file as structs in an array of employee data.
Prompt for the name of the input file.



Read the first integer in the file, then create a dynamic array of the correct size to hold the employee information.


Create a payroll output file with headers similar to that shown in the following list. Prompt for the name of the output file. The output file is to contain the following data:

a. Employee number (left justified)
b. Department
c. Pay Rate
d. Exempt
e. Hours Worked
f. Base pay (pay rate * hours worked)
g. Overtime pay
h. Total pay


Overtime pay is calculated only for nonexempt employees. An employee is exempt if ‘Y’ appears in the exempt column. Overtime is paid at time-and-a-half for all hours worked over 40. If an exempt employee works over 40 hours or under 40 hours, that employee is only paid for 40 hours of work.

For the sample data file the resultant output file would have the following content:

Emp. No. Department Rate Exempt Hours Base Overtime Total
101 41 8.11 Y 49 $324.40 $0.00 $324.40
722 32 7.22 N 40 $288.80 $0.00 $288.80
1273 23 5.43 Y 39 $217.20 $0.00 $217.20
2584 14 6.74 N 45 $269.60 $33.70 $303.30
*****************************************************************************

So far all I have is this:



#include <fstream> // for ifstream
#include <iostream> // for cin, cout and cerr
#include <string> // for string datatype
#include <cstdlib> // needed for the exit function
#include <iomanip>
using namespace std;

struct empData
{
int empNumber;
int department;
double payRate;
double hoursWorked;
char exempt;
};

string getInputFileName(); // a function to prompt for the complete
// file name

int main ()
{
ifstream inFile; // Handle for the input file

string fileName; // complete file name include the path

fileName = getInputFileName(); // prompt and obtain the full file
// name

inFile.open(fileName.c_str()); // try to open the file

if (!inFile.is_open()) // test for unsuccessful file opening
{
cerr << "Cannot open file: " << fileName << endl << endl;
exit (0);
}

//********************************************************************
//
// Function name: getInputFileName
//
// Purpose: to prompt for the fully qualified name of a file
//
// Input parameters: none
//
// Output parameters: none
//
// Return Value: a string containing the fully qualified name of a file
//
//********************************************************************

string getInputFileName()
{
string fName; // fully qualified name of the file

cout << "Please enter the fully qualified name of the " << endl
<< "input data file (i.e. including the path): ";

cin >> fName; // cannot handle blanks in a file name or path

cout << endl; // skip a line

return fName;
}

******************************************************************************

What I need help with is to correctly read the input file as structs in an array of the employee data

I already prompt the user for the input file.

I am confused on how to read the first integer in the file and create a dynamic array of the correct size to hold the employee information.

I have no idea how to create a payroll output file with headers similar to the list above or how to prompt the user for the name of the output file.

Lastly I need to calculate overtime pay only for nonexempt employees, which is paid a time and a half for all hours worked over 40.

I am pretty sure most of theses will be functions but I am just confused how to integrate all this information into the structs.

Thanks a lot.
Topic archived. No new replies allowed.