Structs and other stuff

I need help fine tuning the subsequent program. Structs has really confused me and i'm trying my best to figure out what to do.

The purpose of this program is to read an employee file as structs in an array of employee data.

- I have to prompt for the name of the input file which I wrote the code for. I wrote the code for the structs.

- Now from the input file I am suppose to read the first integer and create a dynamic array of the correct size to hold the employee information. Right now I have at 4.

- From this create a payroll output file.

- Prompt the user for the name of the output file which I wrote the code for

Now overtime pay is calculated for nonexempt employees. An employee is exempt if "Y" appears in the exempt column. Overtime is paid at a 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

#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
// input file name

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

void getbasePay();
void getOvertime();
void getTotal();

int main ()
{
empData dynamicArray[4];

ifstream inFile; // Handle for the input file

string inputfileName; // complete file name include the path

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

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

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

for (int index = 0; index < 4; index++)
{
inFile >> dynamicArray[index].empNumber >> dynamicArray[index].department >>
dynamicArray[index].payRate >> dynamicArray[index].hoursWorked >>
dynamicArray[index].exempt;
}

getbasePay();

getOvertime();

getTotal();

ofstream outFile; // Handle for the output file

string outputfileName; // complete file name include the path

outputfileName = getOutputFileName(); // prompt and obtain the full file
// name

outFile.open(outputfileName.c_str()); // try to open the file

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

for (int index = 0; index < 4; index++)
{
outFile << "Employee Nunber: " << dynamicArray[index].empNumber << "Department: "
<< dynamicArray[index].department << "Pay Rate: " << dynamicArray[index].payRate
<< "Exempt: " << dynamicArray[index].exempt << "Hours Worked: " << dynamicArray[index].hoursWorked << "Base Pay: " << getbasePay <<
"Overtime Pay: " << getOvertime << "Total Pay: " << getTotal;
}

inFile.close(); // close the input file
outFile.close(); // close the output file

//********************************************************************
//
// 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 infName; // 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 >> infName; // cannot handle blanks in a file name or path

cout << endl; // skip a line

return infName;
}

//********************************************************************
//
// Function name: getbasePay
//
// Purpose: to calculate base pay earning of each employee
//
// Input parameters: none
//
// Output parameters: none
//
// Return Value: a double containing the base pay earning of each
// employee
//
//********************************************************************

void getbasePay(dynamicArray)

{
double basePay; //

basePay = dynamicArray.payRate * dynamicArray.hoursWorked;

return basePay;
}

//********************************************************************
//
// Function name: getOvertime
//
// Purpose: to calculate overtime pay for each employee
//
// Input parameters: none
//
// Output parameters: none
//
// Return Value: a double containing the overtime earning of each
// employee
//
//********************************************************************

void getOvertime(dynamicArray)
{
double overTime; //

if (dynamic.hoursWorked > 40)
{
overTime = dynamicArray.payRate * dynamicArray.hoursWorked;
}
return overTime;
}

//********************************************************************
//
// Function name: getTotal
//
// Purpose: to calculate total final earning of each employee
//
// Input parameters: none
//
// Output parameters: none
//
// Return Value: a double containing the total final earning of each
// employee
//
//********************************************************************

void getTotal()
{
double Total; //

Total = basePay + overTime

return Total;
}

//********************************************************************
//
// Function name: getOutputFileName
//
// 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 getOutputFileName()
{
string outfName; // fully qualified name of the file

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

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

cout << endl; // skip a line

return outfName;
}
Topic archived. No new replies allowed.