1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
const int MAX = 100;
const int SIZE = 15;
struct empdata
{
//data members
char firstname[SIZE];
char lastname[SIZE];
char idnumber[SIZE];
char datehired[SIZE];
char fullname[31];
double payrate;
double hoursworked;
double grosspay;
void Show();
};
class employeedata
{
private:
string fname;
string lname;
string fulln;
string empid;
string hiredate;
double prate;
double hworked;
public:
//accessor
void setfname(string ,string);
void setfirstn(string);
void setlastn(string);
void setempid(string);
void sethired(string);
void setrate(double);
void sethours(double);
//mutator
string getfname()const;
string getfirstn()const;
string getlastn()const;
string getempid()const;
string gethired()const;
double getrate()const;
double gethours()const;
//constructors
employeedata()
{
}
employeedata(struct empdata& a)
{
setfirstn(a.firstname);
setlastn(a.lastname);
setfname(a.firstname,a.lastname);
setempid(a.idnumber);
sethired(a.datehired);
setrate(a.payrate);
sethours(a.hoursworked);
}
};
void Show(empdata &);
void employeedata::setfirstn(string f)
{
fname = f;
}
void employeedata::setlastn(string l)
{
lname = l;
}
void employeedata::setfname(string fi, string la)
{
string temp1 = la;
int len = la.length();
int size = fi.length();
temp1.insert(len, 1, ',');
temp1.insert( len + 1, " ");
temp1.insert( len + 2, fi );
fulln = temp1;
}
void employeedata::setempid(string id)
{
empid = id;
}
void employeedata::sethired(string hi)
{
hiredate = hi;
}
void employeedata::setrate(double rat)
{
prate = rat;
}
void employeedata::sethours(double ho)
{
hworked = ho;
}
string employeedata::getfirstn() const
{
return fname;
}
string employeedata::getlastn() const
{
return lname;
}
string employeedata::getfname() const
{
return fulln;
}
//********************************************************************************************************************
int main ()
{
employeedata BayWestIndustries[MAX];
int index = 0 , count = 0;
fstream labfile;
labfile.open("Employees.bin", ios::in);
if(labfile.fail())
{
cout << "Unable to open the data file!!!" <<endl;
cout << "Please make sure your employees.csv file is in the same location as the program!"<<endl<<endl<<endl;
system("PAUSE");
return 999;
}
while(!labfile.eof())
{
empdata EmployeeRecord;
char temp[SIZE];
labfile.getline(EmployeeRecord.firstname,SIZE,',');
labfile.getline(EmployeeRecord.lastname,SIZE,',');
labfile.getline(EmployeeRecord.idnumber,SIZE,',');
labfile.getline(EmployeeRecord.datehired,SIZE,',');
labfile.getline(temp, SIZE,',');
EmployeeRecord.payrate = atof(temp);
labfile.getline(temp, SIZE,'\n');
EmployeeRecord.hoursworked = atof(temp);
employeedata temporary (EmployeeRecord);
EmployeeRecord.Show();
BayWestIndustries[index] = EmployeeRecord;
cout << endl << endl;
cout << temporary.getfirstn() << " " << temporary.getlastn() << endl << endl << temporary.getfname() << endl << BayWestIndustries[index].getfirstn()<< endl << endl;
index++;
getch();
}
labfile.close();
}
//*******************************************************************************************************************
void empdata::Show()
{
cout<< "Name: " << firstname << " " << lastname<< endl << "Date Hired: "
<< datehired << endl << "Employee ID: " << idnumber << endl << "Hours @ Pay: "
<< hoursworked << " @ " << payrate << endl << endl;
return;
}
|