Advertisement
AlexandrTalchuk

Untitled

Nov 20th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.33 KB | None | 0 0
  1. //Разработать связи между следующими классами : класс «Служащий»
  2. //(содержащий ФИО служащего), класс «Работники с почасовой оплатой»
  3. //(оплата за час, часы, отработанные за неделю), класс «Работники со сдельной
  4. //оплатой»(оплата за единицу продукции, число единиц продукции,
  5. //  произведенной за неделю).Все классы должны содержать функции
  6. //  получения и изменения всех полей.Написать программу, позволяющую
  7. //  получать сведения о служащих.Использовать конструктор с параметрами,
  8. //  конструктор без параметров, конструктор копирования.В класс добавить
  9. //  необходимый набор полей и методов(минимум два поля и два метода) на
  10. //  свое усмотрение.
  11. #include <iostream>
  12. #include <string>
  13. #include <fstream>
  14. #include<list>
  15. using namespace std;
  16.  
  17. double In(const char* text = "") {
  18.     double res;
  19.     cout << text;
  20.     while (!(cin >> res) || cin.get() != '\n') {
  21.         cout << "Ошибка ввода! Попробуйте еще: " << endl;
  22.         cin.clear();
  23.         while (cin.get() != '\n');
  24.     }
  25.     return res;
  26. }
  27.  
  28. class Employee
  29. {
  30. protected:
  31.     string LastName,FirstName,MiddleName;
  32.     double salary;
  33.     int count;
  34. public:
  35.     Employee() {};
  36.     Employee(string LastName,string FirstName,string MiddleName)
  37.     {
  38.         this->LastName = LastName;
  39.         this->FirstName = FirstName;
  40.         this->LastName = LastName;
  41.     }
  42.  
  43.     Employee(const Employee& other)
  44.     {
  45.         this->LastName = LastName;
  46.         this->FirstName = FirstName;
  47.         this->LastName = LastName;
  48.     }
  49.  
  50.  
  51.     void getName()
  52.     {
  53.         cout << "FullName: " << LastName << FirstName << MiddleName << endl;
  54.     }
  55.    
  56.     void setName()
  57.     {
  58.         cout << "Enter Lastname: ";
  59.         cin >> LastName;
  60.         cout << "Enter FirstName: ";
  61.         cin >> FirstName;
  62.         cout << "Enter MiddleName: ";
  63.         cin >> MiddleName;
  64.     }
  65.     virtual void Work(float salary,int count);
  66.  
  67. };
  68.  
  69. class WorkerWithHoursPay: public Employee
  70. {
  71.  
  72. public:
  73.     WorkerWithHoursPay() {};
  74.     WorkerWithHoursPay(string LastName, string FirstName, string MiddleName, double salary, int count) :Employee(LastName, FirstName, MiddleName)
  75.     {
  76.         this->salary = salary;
  77.         this->count = count;
  78.     }
  79.  
  80.     void Work(float salary,int count) override
  81.     {
  82.         cout << "Enter salary per hour: ";
  83.         cin >> salary;
  84.         cout << "Enter a count of hours per week: ";
  85.         cin >> count;
  86.     }
  87.  
  88. };
  89.  
  90. class WorkerWithIncentivePay:public Employee
  91. {
  92. public:
  93.     WorkerWithIncentivePay() {};
  94.     WorkerWithIncentivePay(string LastName, string FirstName, string MiddleName,double salary,int count) :Employee(LastName, FirstName, MiddleName)
  95.     {
  96.         this->salary = salary;
  97.         this->count = count;
  98.     }
  99.  
  100.     void Work(float salary, int count) override
  101.     {
  102.         cout << "Enter salary per one unit: ";
  103.         cin >> salary;
  104.         cout << "Enter a count of units per week: ";
  105.         cin >> count;
  106.     }
  107.  
  108. };
  109.  
  110. class Group
  111. {
  112.     int WorkersCount;
  113.     string name;
  114.     string type;
  115.     list<Employee> emp;
  116.  
  117. public:
  118.     Group()
  119.     {
  120.         WorkersCount = 0;
  121.         type = "default";
  122.     }
  123.  
  124.     void Set()
  125.     {
  126.         cout << "Enter type of worker: ";
  127.         cin >> this->name;
  128.         while (type == "default")
  129.         {
  130.             cout << "1. Worker with hours pay" << endl;
  131.             cout << "2. Worker with incentive pay" << endl;
  132.             int choice = In("what type of worker? ");
  133.             switch (choice)
  134.             {
  135.             case 1:
  136.                 type = "Worker with hours pay";
  137.                 break;
  138.             case 2:
  139.                 type = "Worker with incentive pay";
  140.                 break;
  141.             default:
  142.                 cout << "Try again!" << endl;
  143.                 break;
  144.             }
  145.         }
  146.         WorkersCount = 0;
  147.     }
  148.     int GetWorkerCount() { return WorkersCount; }
  149.     string GetType() { return type; }
  150.  
  151.     void AddProduct()
  152.     {
  153.         if (type == "Worker with hours pay")
  154.         {
  155.             WorkerWithHoursPay prod;
  156.             emp.push_back(prod);
  157.         }
  158.         else if (type == "Worker with incentive pay")
  159.         {
  160.             WorkerWithIncentivePay prod;
  161.             emp.push_back(prod);
  162.         }
  163.         WorkersCount++;
  164.     }
  165.     void PrintAll()
  166.     {
  167.         int i = 0;
  168.         for (auto prod : emp)
  169.         {
  170.             cout << "==============    " << i + 1 << "    ==============" << endl;
  171.             prod.getName();
  172.             cout << "Worker: " << this->name << endl;
  173.             ++i;
  174.         }
  175.     }
  176. };
  177. void menu()
  178. {
  179.     int choise, countOfWorkers = 0, currentGroup=0;
  180.     bool f = true;
  181.     Group groups[5];
  182.     cout << "Enter countof workers: " << endl;
  183.     cin >> countOfWorkers;
  184.     if (cin.fail() || countOfWorkers <= 0)
  185.     {
  186.         exit(0);
  187.     }
  188.    
  189.     Group group;
  190.     groups[++countOfWorkers] = group;
  191.     groups[currentGroup].Set();
  192.  
  193.     do
  194.     {
  195.         cout << "1. Enter information about workers" << endl << "2. Show information about workers" << endl << "3. Exit" << endl;
  196.         cin >> choise;
  197.         switch (choise)
  198.         {
  199.         case 1:
  200.         {
  201.             Group temp;
  202.             groups[++countOfWorkers] = temp;
  203.             currentGroup = countOfWorkers - 1;
  204.             groups[currentGroup].Set();
  205.         }
  206.         system("cls");
  207.         break;
  208.         case 2:
  209.             if (groups[currentGroup].GetWorkerCount())
  210.                 groups[currentGroup].PrintAll();
  211.             else
  212.                 cout << "Enter workers and after check it" << endl;
  213.             break;
  214.         case 3:
  215.             f = false;
  216.             break;
  217.         default:
  218.             cout << "Try again" << endl;
  219.             break;
  220.         }
  221.  
  222.     } while (f);
  223.    
  224. }
  225.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement