G
GeekBoy
Seems I am having trouble understanding make a relation of accessing the
structs in functions;
Thanks in advance, since 10^10 messages an hour go through here.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
struct personnel
{
string fname; // members of personnel struct
string lname;
};
struct time
{
int hour; // members of time struct
int min;
};
// function prototypes
void getData(ifstream& iFile, string personnelEmployee[], const float
timeCardIn[], const float timeCardOut[], int index);
void hoursWorked(const float timeCardIn[], const float timeCardOut[], const
float hours[], int index);
int latest(const float timeCardOut[], int index);
void PrintData(ofstream& iFile, string personnelEmployee[], const float
timeCardIn[], const float timeCardOut[], int index, int mLate);
int main()
{
personnel employee[20]; // make personnel a member of struct personnel
time cardI[20]; // make cardI a memeber of struct time
time cardO[20];// make cardO a member of struct time
//time hoursW[20];
int Index, Late;
ifstream inFile;
ofstream outFile;
inFile.open("indata.txt"); //open the data file and check if file can be
opened
if (!inFile)
{
cerr << "Error Opening File" << endl;
system ("pause");
return -1;
}
outFile.open("outdata.txt"); //open or create this file
getData(inFile, employee, cardI, cardO, Index); //call the getData function
return 0;
} // end of main
// function to read data in from inData.txt file
void getData(ifstream& iFile, string personnelEmployee[], const float
timeCardIn[], const float timeCardOut[], int index)
{
int count = 0;
iFile >> personnelEmployee[count].fname >> personnelEmployee[count].lname >>
timeCardIn[count].hr timeCardIn[count].min;
while(! EOF)
{
count++;
iFile >> personnelEmployee[count].fname >> personnelEmployee[count].lname
}
// function to determine the amount of hours worked
hoursWorked(const float timeCardIn[], const float timeCardOut[], const float
hours, int count)
{ int x;
int minW;
for (x =0; x < count; x++)
minW = (timeCardOut[x].hr *60 + timeCardOut[x].min)- (timeCardIn[x].hr
* 60 + timeCardIn[x].min);
hours[x].hrs == minW/60;
hours[x].min == minW%60;
}
latest(const float timeCardOut,int index)
{
float minW;
int lateIndex = 0, int minW int x;
for (x = 0; x < index; x++)
minW=(timeCardOut[x].hr *60 + timeCardOut[x].min);
if (minW > timeCardOut[lateIndex].hr * 60 + timeCardOut[lateIndex].min)
lateIndex = x;
return;
}
// function to print the final data calculated
printData(ofstream& oFile, string personnelEmployee[], const float
timeCardIn[], const float timeCardOut[], int index, int mLate);"
{
for (int x=o; x < index; x++)
{
file << personnelEmployee[x].fname << personnelEmployee[x].lname <<
timeCardOut[x];
}
}
structs in functions;
Thanks in advance, since 10^10 messages an hour go through here.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
struct personnel
{
string fname; // members of personnel struct
string lname;
};
struct time
{
int hour; // members of time struct
int min;
};
// function prototypes
void getData(ifstream& iFile, string personnelEmployee[], const float
timeCardIn[], const float timeCardOut[], int index);
void hoursWorked(const float timeCardIn[], const float timeCardOut[], const
float hours[], int index);
int latest(const float timeCardOut[], int index);
void PrintData(ofstream& iFile, string personnelEmployee[], const float
timeCardIn[], const float timeCardOut[], int index, int mLate);
int main()
{
personnel employee[20]; // make personnel a member of struct personnel
time cardI[20]; // make cardI a memeber of struct time
time cardO[20];// make cardO a member of struct time
//time hoursW[20];
int Index, Late;
ifstream inFile;
ofstream outFile;
inFile.open("indata.txt"); //open the data file and check if file can be
opened
if (!inFile)
{
cerr << "Error Opening File" << endl;
system ("pause");
return -1;
}
outFile.open("outdata.txt"); //open or create this file
getData(inFile, employee, cardI, cardO, Index); //call the getData function
return 0;
} // end of main
// function to read data in from inData.txt file
void getData(ifstream& iFile, string personnelEmployee[], const float
timeCardIn[], const float timeCardOut[], int index)
{
int count = 0;
iFile >> personnelEmployee[count].fname >> personnelEmployee[count].lname >>
timeCardIn[count].hr timeCardIn[count].min;
while(! EOF)
{
count++;
iFile >> personnelEmployee[count].fname >> personnelEmployee[count].lname
}>> timeCardIn[count].cardI;
}
// function to determine the amount of hours worked
hoursWorked(const float timeCardIn[], const float timeCardOut[], const float
hours, int count)
{ int x;
int minW;
for (x =0; x < count; x++)
minW = (timeCardOut[x].hr *60 + timeCardOut[x].min)- (timeCardIn[x].hr
* 60 + timeCardIn[x].min);
hours[x].hrs == minW/60;
hours[x].min == minW%60;
}
latest(const float timeCardOut,int index)
{
float minW;
int lateIndex = 0, int minW int x;
for (x = 0; x < index; x++)
minW=(timeCardOut[x].hr *60 + timeCardOut[x].min);
if (minW > timeCardOut[lateIndex].hr * 60 + timeCardOut[lateIndex].min)
lateIndex = x;
return;
}
// function to print the final data calculated
printData(ofstream& oFile, string personnelEmployee[], const float
timeCardIn[], const float timeCardOut[], int index, int mLate);"
{
for (int x=o; x < index; x++)
{
file << personnelEmployee[x].fname << personnelEmployee[x].lname <<
timeCardOut[x];
}
}