i got this really wierd problem, i'm writing my results to an output file, i use functions A B and C i activate them in that order, the results in the file is printed in a different order, first from A than from C and after that from B. i just can't understand why the results printed in a different order than the activation order. thanx.
the code :
void Manager::AddCommand(Command* com, ofstream &ResultFile)
{
if (com != NULL)
{
if (com->ValidCommand(ResultFile) == true)
commands.push_back(com);
else
delete com;
}
}
bool Command::ValidCommand(ofstream &Result) const
{
if(func<PrintCityCouncilList || func >HireEmployee){
Result << "Command:Failed activating function - invalid function number\n";
return false;}
if ((func == Command::PrintDepartmentEmployees) || (func == Command::PrintDepartmentExpenses) || (func == Command::PrintDepartmentStatistics)){
if(dept<Employee::Engineering ||dept>Employee::Sanitation )
{
Result << "Command:Failed activating function - invalid department number\n";
return false;
}
}
return true;
}
void Manager::ActivateCommand(Command* com, ofstream &Result)
{
if(com != NULL)
{
switch(com->GetFunction())
{
case (Command::PrintCityCouncilList): pcc->PrintCityCouncilDetails(Result);
break;
case (Command::PrintDepartmentEmployees):ActivatePrintDeprtEmployees(com->GetDepartment(), Result);
break;
case (Command::PrintEmployeeSalary):ActivateEmployeeSalary(com->GetId(), Result);
break;
case (Command::PrintDepartmentExpenses):ActivateDeprtExpenses(com->GetDepartment(), Result);
break;
case (Command::PrintCityCouncilExpenses): pcc->AllExpenses (Result);
break;
case (Command::PrintDepartmentStatistics):ActivateDeprtStatistics(com->GetDepartment(), Result);
break;
case (Command::FireEmployee): pcc->RemoveEmployeeFromCC(NULL,com->GetId(),Result);
break;
case (Command::HireEmployee): pcc->AddEmployeeToCC(com->GetId(),com->GetPrivateName(),com->GetSurName(),com->GetDate(),com->GetAddress(),com->GetDepartment(), com->GetStatus(),com->GetSalary(),com->GetPositionPercent(),com->GetPhoneNum(), Result);
break;
default:Result<<"Manager:Failed Activating command - invalid function"<<endl;
break;
}
}
}
void Manager::ActivateCommandsList(ofstream &Result)
{
Command* tmp = NULL;
if (commands.empty() == false)
{
list<Command*>::iterator iter = commands.begin();
while (iter != commands.end())
{
tmp = (Command*)(*iter);
ActivateCommand(tmp,Result);
iter++;
}
}
}