#include #include #include using namespace std; const int SIZE = 15; struct Employee { char fname[20]; char lname[20]; int hours; double rate; double regPay; double overtimePay; double totalPay; }; struct OTPay { double overtimePay; long int pos; }; struct TotalPay { double totalPay; long int pos; }; struct NameIndex { char lname[20]; long int pos; }; void sortOTPay(OTPay[]); void sortTotalPay(TotalPay[]); void displayByOTPay(ifstream&,OTPay[]); void displayByTotalPay(ifstream&,TotalPay[]); void getEmployee(ifstream&,char *,NameIndex[]); int main() { Employee emp; OTPay byOTPay[SIZE]; TotalPay byTotalPay[SIZE]; NameIndex byName[SIZE]; ifstream infile; int cnt=0; infile.open("employees2.bin",ios::binary); infile.read((char *)&emp,sizeof(Employee)); while(!infile.eof()) { byOTPay[cnt].overtimePay = emp.overtimePay; byTotalPay[cnt].totalPay = emp.totalPay; strcpy(byName[cnt].lname,emp.lname); byOTPay[cnt].pos = cnt*sizeof(Employee); byTotalPay[cnt].pos = cnt*sizeof(Employee); byName[cnt].pos = cnt*sizeof(Employee); cnt++; infile.read((char *)&emp,sizeof(Employee)); } infile.clear(); //program won't give good results without this! sortOTPay(byOTPay); sortTotalPay(byTotalPay); cout << "\nRecords sorted by overtime pay-->\n\n"; displayByOTPay(infile,byOTPay); cout << "\nRecords sorted by total pay-->\n\n"; displayByTotalPay(infile,byTotalPay); char lname[20]; cout << "Enter last name of Employee: "; cin >> lname; getEmployee(infile,lname,byName); infile.close(); return 0; } void sortOTPay(OTPay ot[]) { OTPay temp; for(int i=0;i