class Employees{
private:
Employee* allEmployees;
int EmployeeCount;
int EmployeeSize;
void qs_lname(int left, int right);
public:
//defualt,w/initializer List
Employees(void) : allEmployees(NULL), EmployeeCount(0), EmployeeSize(0)
{allEmployees= new Employee[EmployeeSize];}
Employees(Employees& e) : allEmployees(NULL), EmployeeCount(e.EmployeeCount), EmployeeSize(e.EmployeeSize)
{
allEmployees= new Employee[e.EmployeeSize];
for(int i=0;i<EmployeeSize;i++)
allEmployees[i]=e.allEmployees[i];
}
~Employees(void){delete [] allEmployees;}
//change state
void add(const Employee& e);
void add(const char*last="",const char* first="",float pr=0.0,float hrs=0.0,float deff=0.0);
void remove(const Employee &e);
void remove(const char * last);
float search(const char* last);
float search(const Employee &e); // overloading
void quicksort(){qs_lname(0,EmployeeCount-1);}
void printPayrollReport(void);
//gets
const int getEmployeeCount(void)const{return EmployeeCount;}
};
The assignment said we should use
Employee * allEmployees[MAX];
But I tried arguing with my professor, saying isnt the whole point of a container to stores things dynamically and not a fixed size, well I think this made him angry and now he is expecting me to use a linked list, (which he hasnt covered in class yet), here is my add method
void Employees::add(const Employee &e)
{
int found=search(e.getLastName());
if (found >= 0)
allEmployees[found] = e; // update the entry found
else
{ if (EmployeeCount < EmployeeSize)
allEmployees[EmployeeCount++] = e;
else
{
EmployeeSize += 32;//<--- this is what he is complaining about
Employee* all = new Employee[EmployeeSize];
for (int i = 0; i < EmployeeCount; ++i)
all[i] = allEmployees[i];
delete [] allEmployees;
allEmployees = all;
allEmployees[EmployeeCount++] = e;
}
}
}
He is saying it is ineffectient to reallocate , how can i use a linked list to solve this ?
thanks
JS

New Topic/Question
Reply




MultiQuote



|