Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- int id_group = 2;
- class Proc
- {
- friend class Group;
- public:
- static void execute(Group* group, Restaurant* restaurant, Schedule* schedule, const int time_now, const char chose)
- {
- Group* next;
- ofstream save("run.txt", ios_base::app);
- auto active = true;
- while (active)
- {
- switch (group->GetPhase())
- {
- case 0: // FAZA I
- if (chose == 's')
- {
- do
- {
- cout << '\n' << "Press a key to continue...";
- }
- while (cin.get() != '\n');
- }
- next = new Group(id_group++);
- schedule->AddToAgenda(new Event(next, rand() % 20 + time_now));
- save << "appearance was planned group id=" << group->GetId() << endl;
- if (group->GoToBuffet())
- {
- save << "group add to queue to buffet (group id=" << group->GetId() << ")" << endl;
- cout << "group add to queue to buffet (group id=" << group->GetId() << ")" << endl;
- restaurant->AddToQueue(group, 'b');
- if (restaurant->IsBuffetFree(group) != nullptr && restaurant->IsFirst('b') == group) group->SetPhase(5);
- else
- {
- group->SetPhase(5);
- active = false;
- break;
- }
- }
- else
- {
- save << "group add to queue to manager (group id=" << group->GetId() << ")" << endl;
- cout << "group add to queue to manager (group id=" << group->GetId() << ")" << endl;
- restaurant->AddToQueue(group, 'm');
- if (restaurant->IsManagerFree() && restaurant->IsFirst('m') == group) group->SetPhase(1);
- else
- {
- group->SetPhase(1);
- active = false;
- break;
- }
- }
- break;
- case 1: // FAZA 2 table only
- if (chose == 's')
- {
- do
- {
- cout << '\n' << "Press a key to continue...";
- }
- while (cin.get() != '\n');
- }
- restaurant->use_employe(restaurant->GetFromQueue('m'), 'm', 0); // dokodzić dobieranie number
- save << "manager pick up group from queue id=" << group->GetId() << endl;
- cout << "manager pick up group from queue id=" << group->GetId() << endl;
- schedule->AddToAgenda(new Event(group, rand() % 20 + time_now));
- group->SetPhase(2);
- active = false;
- break;
- case 2: // FAZA 3 table only
- if (chose == 's')
- {
- do
- {
- cout << '\n' << "Press a key to continue...";
- }
- while (cin.get() != '\n');
- }
- restaurant->free_employe('m');
- save << "manager ended the group service (group id=" << group->GetId() << ")" << endl;
- cout << "manager ended the group service (group id=" << group->GetId() << ")" << endl;
- Restaurant::SetTable(restaurant->IsTableFree(group), group);
- save << "the group took a table (group id=" << group->GetId() << ")" << endl;
- cout << "the group took a table (group id=" << group->GetId() << ")" << endl;
- if (restaurant->IsFirst('m'))
- execute(restaurant->IsFirst('m'), restaurant, schedule, time_now, chose);
- restaurant->AddToQueue(group, 'w');
- if (restaurant->IsWaiterFree(group) != nullptr)
- {
- group->SetPhase(3);
- break;
- } //else
- group->SetPhase(3);
- active = false;
- break;
- case 3: // FAZA 4 table only
- if (chose == 's')
- {
- do
- {
- cout << '\n' << "Press a key to continue...";
- }
- while (cin.get() != '\n');
- }
- restaurant->IsWaiterFree(group);
- restaurant->use_employe(restaurant->GetFromQueue('w'), 'w', group->GetNumberOfEmploye());
- save << "waiter get group from queue and started service (group id=" << group->GetId() << ")" << endl;
- cout << "waiter get group from queue and started service (group id=" << group->GetId() << ")" << endl;
- schedule->AddToAgenda(new Event(group, rand() % 20 + time_now));
- active = false;
- group->SetPhase(4);
- break;
- case 4: // FAZA 5 table only
- if (chose == 's')
- {
- do
- {
- cout << '\n' << "Press a key to continue...";
- }
- while (cin.get() != '\n');
- }
- restaurant->free_employe('w', group->GetNumberOfEmploye());
- save << "waiter ended the group service (group id=" << group->GetId() << ")" << endl;
- cout << "waiter ended the group service (group id=" << group->GetId() << ")" << endl;
- group->SetPhase(5);
- if (restaurant->IsFirst('w'))
- {
- execute(restaurant->IsFirst('w'), restaurant, schedule, time_now, chose);
- }
- break;
- case 5: // faza 6
- if (chose == 's')
- {
- do
- {
- cout << '\n' << "Press a key to continue...";
- }
- while (cin.get() != '\n');
- }
- if (group->GoToBuffet()) // jeżeli bufetowa grupa
- {
- save << "consumption in buffet started (group id=" << group->GetId() << ")" << endl;
- cout << "consumption in buffet started (group id=" << group->GetId() << ")" << endl;
- schedule->AddToAgenda(new Event(group, rand() % 20 + time_now));
- active = false;
- }
- else
- {
- save << "consumption in table started (group id=" << group->GetId() << ")" << endl;
- cout << "consumption in table started (group id=" << group->GetId() << ")" << endl;
- schedule->AddToAgenda(new Event(group, rand() % 20 + time_now));
- active = false;
- }
- group->SetPhase(6);
- break;
- case 6: // FAZA 7
- if (chose == 's')
- {
- do
- {
- cout << '\n' << "Press a key to continue...";
- }
- while (cin.get() != '\n');
- }
- if (group->GoToBuffet()) // jeżeli bufetowa grupa
- {
- save << "place in buffet now is free (group id=" << group->GetId() << ")" << endl;
- cout << "place in buffet now is free (group id=" << group->GetId() << ")" << endl;
- restaurant->free_employe('b', group->GetNumberOfEmploye());
- restaurant->AddToQueue(group, 'c');
- save << "group add to queue to cashiers (group id=" << group->GetId() << ")" << endl;
- cout << "group add to queue to cashiers (group id=" << group->GetId() << ")" << endl;
- if (restaurant->IsFirst('b'))
- execute(restaurant->IsFirst('b'), restaurant, schedule, time_now, chose);
- }
- else
- {
- restaurant->FreeTable(group);
- save << "table now is free (group id=" << group->GetId() << ")" << endl;
- cout << "table now is free (group id=" << group->GetId() << ")" << endl;
- restaurant->AddToQueue(group, 'c');
- save << "group add to queue to cashiers (group id=" << group->GetId() << ")" << endl;
- cout << "group add to queue to cashiers (group id=" << group->GetId() << ")" << endl;
- }
- group->SetPhase(7);
- break;
- case 7: //faza 8
- if (chose == 's')
- {
- do
- {
- cout << '\n' << "Press a key to continue...";
- }
- while (cin.get() != '\n');
- }
- restaurant->IsCashierFree(group); // przed przypisaniem do grupy znajduję nam który to będzie kasjer i zapsiuje to w polu numberofemployee
- save << "group are serviced by cashier (group id=" << group->GetId() << ")" << endl;
- cout << "group are serviced by cashier (group id=" << group->GetId() << ")" << endl;
- restaurant->use_employe(restaurant->GetFromQueue('c'), 'c', group->GetNumberOfEmploye());
- schedule->AddToAgenda(new Event(group, rand() % 20 + time_now));
- group->SetPhase(8);
- break;
- case 8: // faza 9
- if (chose == 's')
- {
- do
- {
- cout << '\n' << "Press a key to continue...";
- }
- while (cin.get() != '\n');
- system("cls");
- }
- restaurant->free_employe('c', group->GetNumberOfEmploye());
- save << "group was pay (group id=" << group->GetId() << ")" << endl;
- cout << "group was pay (group id=" << group->GetId() << ")" << endl;
- if (restaurant->IsFirst('c')) execute(restaurant->IsFirst('c'), restaurant, schedule, time_now, chose);
- save << "group are out of restaurant (group id=" << group->GetId() << ")" << endl;
- cout << "group are out of restaurant (group id=" << group->GetId() << ")" << endl;
- group->terminate();
- active = false;
- break;
- default:
- return;
- }
- }
- save.close();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement