#ifndef EMPLOYEES_H #define EMPLOYEES_H #include"hourly.h" #include"salary.h" #include"piecework.h" class Employees{ private: Employee *all[MAX]; int EmployeeCount; void qs_lname(int left, int right); public: Employees():EmployeeCount(0){} void add(Employee &e); void remove(Employee &e); int search(char* l); void quickSort(){qs_lname(0,EmployeeCount-1);} void calcAllGross(void); void calcAllNet(void); void sortTypes(); void printReport(); }; void Employees::calcAllGross(void) { for(int i =0;icalcGross(); } void Employees::qs_lname(int left, int right) { int i, j; const char *x; // temp string i = left; j = right; x = all[(left+right)/2]->getLastName(); // sorting by last name do { while((strcmp(all[i]->getLastName(),x) < 0) && (i < right))i++; while((strcmp(all[j]->getLastName(),x) > 0) && (j > left)) j--; if(i <= j) { // swap Employee *temp =all[i]; all[i] = all[j]; all[j] = temp; i++; j--; } } while(i <= j); if(left < j) qs_lname(left, j); if(i < right) qs_lname(i, right); } void Employees::sortTypes() { //bubble sort for(int i=0 ; iGetType() < all[i]->GetType() || // last name and type (all[j]->GetType() == all[i]->GetType() && all[j]->getLastName() > all[i]->getLastName() ) ) { Employee* pTemp = all[i]; all[i] = all[j]; all[j] = pTemp; } } } void Employees:: calcAllNet(void) { for(int i =0;icalcNet(); } void Employees::add(Employee &e) { if(EmployeeCountgetLastName())==0) return i; } return-1; } void Employees::remove(Employee &e) { int found=search(e.getLastName()); if (found >= 0) { Employee *erase=0; // Null Pointer all[found]=all[EmployeeCount-1];//set found to last pointer all[EmployeeCount-1]=erase;//set last pointer to null --EmployeeCount; sortTypes(); } } void Employees::printReport() { FILE * report;//create file report= fopen("./Report.lst","wt");//open file if (report == NULL) { printf("\n\nReport file open error ....\n"); exit; } int lasttype = -1; sortTypes(); for(int i=0;iGetType() != lasttype) // type changed or very first { if (i > 0) all[i-1]->printSubTotal(report); // virtual function that prints the sub-total of the previous group fprintf(report,"\n"); // print space line // print the title of the next group all[i]->printTitle(report); } // print the current employee fprintf(report,"\n%s : %6.2f \n",all[i]->getFullName(),all[i]->getGross()); lasttype = all[i]->GetType(); } //print subtotals for last group if (EmployeeCount > 0) all[EmployeeCount-1]->printSubTotal(report); } #endif