Advertisement
Guest User

Untitled

a guest
May 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.82 KB | None | 0 0
  1. using namespace std;
  2. int id_group = 2;
  3.  
  4. class Proc
  5. {
  6.   friend class Group;
  7. public:
  8.   static void execute(Group* group, Restaurant* restaurant, Schedule* schedule, const int time_now, const char chose)
  9.   {
  10.     Group* next;
  11.     ofstream save("run.txt", ios_base::app);
  12.     auto active = true;
  13.     while (active)
  14.     {
  15.       switch (group->GetPhase())
  16.       {
  17.       case 0: // FAZA I
  18.         if (chose == 's')
  19.         {
  20.           do
  21.           {
  22.             cout << '\n' << "Press a key to continue...";
  23.           }
  24.           while (cin.get() != '\n');
  25.         }
  26.         next = new Group(id_group++);
  27.         schedule->AddToAgenda(new Event(next, rand() % 20 + time_now));
  28.         save << "appearance was planned group id=" << group->GetId() << endl;
  29.         if (group->GoToBuffet())
  30.         {
  31.           save << "group add to queue to buffet (group id=" << group->GetId() << ")" << endl;
  32.           cout << "group add to queue to buffet (group id=" << group->GetId() << ")" << endl;
  33.           restaurant->AddToQueue(group, 'b');
  34.           if (restaurant->IsBuffetFree(group) != nullptr && restaurant->IsFirst('b') == group) group->SetPhase(5);
  35.           else
  36.           {
  37.             group->SetPhase(5);
  38.             active = false;
  39.             break;
  40.           }
  41.         }
  42.         else
  43.         {
  44.           save << "group add to queue to manager (group id=" << group->GetId() << ")" << endl;
  45.           cout << "group add to queue to manager (group id=" << group->GetId() << ")" << endl;
  46.           restaurant->AddToQueue(group, 'm');
  47.           if (restaurant->IsManagerFree() && restaurant->IsFirst('m') == group) group->SetPhase(1);
  48.           else
  49.           {
  50.             group->SetPhase(1);
  51.             active = false;
  52.             break;
  53.           }
  54.         }
  55.         break;
  56.       case 1: // FAZA 2 table only
  57.         if (chose == 's')
  58.         {
  59.           do
  60.           {
  61.             cout << '\n' << "Press a key to continue...";
  62.           }
  63.           while (cin.get() != '\n');
  64.         }
  65.         restaurant->use_employe(restaurant->GetFromQueue('m'), 'm', 0); // dokodzić dobieranie number
  66.         save << "manager pick up group from queue id=" << group->GetId() << endl;
  67.         cout << "manager pick up group from queue id=" << group->GetId() << endl;
  68.         schedule->AddToAgenda(new Event(group, rand() % 20 + time_now));
  69.         group->SetPhase(2);
  70.         active = false;
  71.         break;
  72.       case 2: // FAZA 3 table only
  73.         if (chose == 's')
  74.         {
  75.           do
  76.           {
  77.             cout << '\n' << "Press a key to continue...";
  78.           }
  79.           while (cin.get() != '\n');
  80.         }
  81.         restaurant->free_employe('m');
  82.         save << "manager ended the group service (group id=" << group->GetId() << ")" << endl;
  83.         cout << "manager ended the group service (group id=" << group->GetId() << ")" << endl;
  84.         Restaurant::SetTable(restaurant->IsTableFree(group), group);
  85.         save << "the group took a table (group id=" << group->GetId() << ")" << endl;
  86.         cout << "the group took a table (group id=" << group->GetId() << ")" << endl;
  87.         if (restaurant->IsFirst('m'))
  88.           execute(restaurant->IsFirst('m'), restaurant, schedule, time_now, chose);
  89.         restaurant->AddToQueue(group, 'w');
  90.         if (restaurant->IsWaiterFree(group) != nullptr)
  91.         {
  92.           group->SetPhase(3);
  93.           break;
  94.         } //else
  95.         group->SetPhase(3);
  96.         active = false;
  97.         break;
  98.       case 3: // FAZA 4 table only
  99.         if (chose == 's')
  100.         {
  101.           do
  102.           {
  103.             cout << '\n' << "Press a key to continue...";
  104.           }
  105.           while (cin.get() != '\n');
  106.         }
  107.         restaurant->IsWaiterFree(group);
  108.         restaurant->use_employe(restaurant->GetFromQueue('w'), 'w', group->GetNumberOfEmploye());
  109.         save << "waiter get group from queue and started service (group id=" << group->GetId() << ")" << endl;
  110.         cout << "waiter get group from queue and started service (group id=" << group->GetId() << ")" << endl;
  111.         schedule->AddToAgenda(new Event(group, rand() % 20 + time_now));
  112.         active = false;
  113.         group->SetPhase(4);
  114.         break;
  115.       case 4: // FAZA 5 table only
  116.         if (chose == 's')
  117.         {
  118.           do
  119.           {
  120.             cout << '\n' << "Press a key to continue...";
  121.           }
  122.           while (cin.get() != '\n');
  123.         }
  124.         restaurant->free_employe('w', group->GetNumberOfEmploye());
  125.         save << "waiter ended the group service (group id=" << group->GetId() << ")" << endl;
  126.         cout << "waiter ended the group service (group id=" << group->GetId() << ")" << endl;
  127.         group->SetPhase(5);
  128.         if (restaurant->IsFirst('w'))
  129.         {
  130.           execute(restaurant->IsFirst('w'), restaurant, schedule, time_now, chose);
  131.         }
  132.         break;
  133.       case 5: // faza 6
  134.         if (chose == 's')
  135.         {
  136.           do
  137.           {
  138.             cout << '\n' << "Press a key to continue...";
  139.           }
  140.           while (cin.get() != '\n');
  141.         }
  142.         if (group->GoToBuffet()) // jeżeli bufetowa grupa
  143.         {
  144.           save << "consumption in buffet started (group id=" << group->GetId() << ")" << endl;
  145.           cout << "consumption in buffet started (group id=" << group->GetId() << ")" << endl;
  146.           schedule->AddToAgenda(new Event(group, rand() % 20 + time_now));
  147.           active = false;
  148.         }
  149.         else
  150.         {
  151.           save << "consumption in table started (group id=" << group->GetId() << ")" << endl;
  152.           cout << "consumption in table started (group id=" << group->GetId() << ")" << endl;
  153.           schedule->AddToAgenda(new Event(group, rand() % 20 + time_now));
  154.           active = false;
  155.         }
  156.         group->SetPhase(6);
  157.         break;
  158.       case 6: // FAZA 7
  159.         if (chose == 's')
  160.         {
  161.           do
  162.           {
  163.             cout << '\n' << "Press a key to continue...";
  164.           }
  165.           while (cin.get() != '\n');
  166.         }
  167.         if (group->GoToBuffet()) // jeżeli bufetowa grupa
  168.         {
  169.           save << "place in buffet now is free (group id=" << group->GetId() << ")" << endl;
  170.           cout << "place in buffet now is free (group id=" << group->GetId() << ")" << endl;
  171.           restaurant->free_employe('b', group->GetNumberOfEmploye());
  172.           restaurant->AddToQueue(group, 'c');
  173.           save << "group add to queue to cashiers (group id=" << group->GetId() << ")" << endl;
  174.           cout << "group add to queue to cashiers (group id=" << group->GetId() << ")" << endl;
  175.           if (restaurant->IsFirst('b'))
  176.             execute(restaurant->IsFirst('b'), restaurant, schedule, time_now, chose);
  177.         }
  178.         else
  179.         {
  180.           restaurant->FreeTable(group);
  181.           save << "table now is free (group id=" << group->GetId() << ")" << endl;
  182.           cout << "table now is free (group id=" << group->GetId() << ")" << endl;
  183.           restaurant->AddToQueue(group, 'c');
  184.           save << "group add to queue to cashiers (group id=" << group->GetId() << ")" << endl;
  185.           cout << "group add to queue to cashiers (group id=" << group->GetId() << ")" << endl;
  186.         }
  187.         group->SetPhase(7);
  188.         break;
  189.       case 7: //faza 8
  190.         if (chose == 's')
  191.         {
  192.           do
  193.           {
  194.             cout << '\n' << "Press a key to continue...";
  195.           }
  196.           while (cin.get() != '\n');
  197.         }
  198.         restaurant->IsCashierFree(group); // przed przypisaniem do grupy znajduję nam który to będzie kasjer i zapsiuje to w polu numberofemployee
  199.         save << "group are serviced by cashier (group id=" << group->GetId() << ")" << endl;
  200.         cout << "group are serviced by cashier (group id=" << group->GetId() << ")" << endl;
  201.         restaurant->use_employe(restaurant->GetFromQueue('c'), 'c', group->GetNumberOfEmploye());
  202.         schedule->AddToAgenda(new Event(group, rand() % 20 + time_now));
  203.         group->SetPhase(8);
  204.         break;
  205.       case 8: // faza 9
  206.         if (chose == 's')
  207.         {
  208.           do
  209.           {
  210.             cout << '\n' << "Press a key to continue...";
  211.           }
  212.           while (cin.get() != '\n');
  213.           system("cls");
  214.         }
  215.         restaurant->free_employe('c', group->GetNumberOfEmploye());
  216.         save << "group was pay (group id=" << group->GetId() << ")" << endl;
  217.         cout << "group was pay (group id=" << group->GetId() << ")" << endl;
  218.         if (restaurant->IsFirst('c')) execute(restaurant->IsFirst('c'), restaurant, schedule, time_now, chose);
  219.         save << "group are out of restaurant (group id=" << group->GetId() << ")" << endl;
  220.         cout << "group are out of restaurant (group id=" << group->GetId() << ")" << endl;
  221.         group->terminate();
  222.         active = false;
  223.         break;
  224.       default:
  225.         return;
  226.       }
  227.     }
  228.     save.close();
  229.   }
  230. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement