Xom9ik

Lab_9_Task2/3 var (IIl semester)

Dec 7th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.35 KB | None | 0 0
  1. //Lab_9_Task2
  2. #include "stdafx.h"
  3. #include <string>
  4. #include <iostream>
  5. #include <locale>
  6. #include <fstream>
  7. #include <iomanip>
  8.  
  9. using namespace std;
  10. //3.    Классы табель выходов и сотрудник.
  11. //Класс обработчик реализует заполнение табеля выходов и расчет заработной платы сотрудник на основании информации о отработанном времени.
  12. //Класс-сотрудник
  13. class TSotrudnik
  14. {
  15. private:
  16.     string Name;
  17.     string Surname;
  18.     int Id;
  19.     int Time;
  20. public:
  21.     TSotrudnik();
  22.     int getId()
  23.     {
  24.         return Id;
  25.     }
  26.     string getName()
  27.     {
  28.         return Name;
  29.     }
  30.     string getSurname()
  31.     {
  32.         return Surname;
  33.     }
  34.     int getTime()
  35.     {
  36.         return Time;
  37.     }
  38.     void setId(int id)
  39.     {
  40.         Id = id;
  41.     }
  42.     void setName(string name)
  43.     {
  44.         Name = name;
  45.     }
  46.     void setSurname(string surname)
  47.     {
  48.         Surname = surname;
  49.     }
  50.     void setTime(int time)
  51.     {
  52.         Time = time;
  53.     }
  54.     ~TSotrudnik();
  55. };
  56. TSotrudnik::TSotrudnik()
  57. {
  58.     cout << "Constructor class TSotrudnik" << endl;
  59. }
  60. TSotrudnik::~TSotrudnik()
  61. {
  62.     cout << "Destructor class TSotrudnik" << endl;
  63. }
  64. //Класс-табель
  65. class TTabel
  66. {
  67. public:
  68.     TTabel();
  69.     TTabel(TSotrudnik*, int);
  70.     int Max;
  71.     int CurrentPos = 0;
  72.     TSotrudnik *SotrudnikPointer;
  73.     void setMax(int newMax)
  74.     {
  75.         Max = newMax;
  76.     }
  77.     int getMax()
  78.     {
  79.         return Max;
  80.     }
  81.     void addSotrudnik();
  82.     ~TTabel();
  83. };
  84. TTabel::TTabel()
  85. {
  86.     cout << "Constructor class TTabel" << endl;
  87. }
  88. TTabel::TTabel(TSotrudnik *S, int max)
  89. {
  90.     setMax(max);
  91.     SotrudnikPointer = S;
  92. }
  93. TTabel::~TTabel()
  94. {
  95.     cout << "Destructor class TTabel" << endl;
  96. }
  97. void TTabel::addSotrudnik()
  98. {
  99.     string name, surname;
  100.     int id, time;
  101.     cout << "Enter ID: ";
  102.     cin >> id;
  103.     SotrudnikPointer[CurrentPos].setId(id);
  104.     cout << "Enter name: ";
  105.     cin >> name;
  106.     SotrudnikPointer[CurrentPos].setName(name);
  107.     cout << "Enter surname: ";
  108.     cin >> surname;
  109.     SotrudnikPointer[CurrentPos].setSurname(surname);
  110.     cout << "Enter time work: ";
  111.     cin >> time;
  112.     SotrudnikPointer[CurrentPos].setTime(time);
  113.     CurrentPos++;
  114. }
  115. class TableOutput
  116. {//табличный вывод информации в файл и на экран
  117. public:
  118.     virtual void Print(TTabel *T) = 0;
  119.  
  120. };
  121. class StringOutput
  122. {//вывод информации в ленточной форме в файл и на экран
  123. public:
  124.     virtual void Print(TTabel *T) = 0;
  125.  
  126. };
  127. class TableOutput_helper : public TableOutput {
  128. public:
  129.     virtual void TableOutput_Print(TTabel *T) = 0;
  130.     void Print(TTabel *T)
  131.     {
  132.         TableOutput_Print(T);
  133.     }
  134. };
  135. class StringOutput_helper : public StringOutput {
  136. public:
  137.     virtual void StringOutput_Print(TTabel *T) = 0;
  138.     void Print(TTabel *T)
  139.     {
  140.         StringOutput_Print(T);
  141.     }
  142. };
  143. class TProcessor : public TableOutput_helper, public StringOutput_helper
  144. {
  145. public:
  146.     TProcessor();
  147.     TProcessor(TTabel *T);
  148.     TTabel *Tpointer;
  149.     void calculateEarnings(int rate);
  150.     void TableOutput_Print(TTabel *T)
  151.     {
  152.         string out = "";
  153.         cout << "Table Output" << endl;
  154.         out += "Table Output\n";
  155.         cout << "ID\t" << "Name\t" << "Surname\t" << "\tTime" << endl;
  156.         out += "ID\tName\tSurname\t\tTime\n";
  157.         for (int i = 0; i < T[0].CurrentPos; i++)
  158.         {
  159.             out += to_string(T[0].SotrudnikPointer[i].getId()) + "\t" + T[0].SotrudnikPointer[i].getName() + "\t";
  160.             out += T[0].SotrudnikPointer[i].getSurname() + "\t" + to_string(T[0].SotrudnikPointer[i].getTime()) + "\n";
  161.             cout << T[0].SotrudnikPointer[i].getId() << "\t" << T[0].SotrudnikPointer[i].getName() << "\t" << T[0].SotrudnikPointer[i].getSurname() << "\t" << T[0].SotrudnikPointer[i].getTime() << endl;
  162.         }
  163.         ofstream fout;
  164.         fout.open("Table.txt");
  165.         fout << out;
  166.         fout.close();
  167.     }
  168.     void StringOutput_Print(TTabel *T)
  169.     {
  170.         string out = "";
  171.         out += "String Output\n";
  172.         cout << "String Output" << endl;
  173.         cout << "ID: ";
  174.         out += "ID: ";
  175.         for (int i = 0; i < T[0].CurrentPos; i++)
  176.         {
  177.             out += to_string(T[0].SotrudnikPointer[i].getId()) + "; ";
  178.             cout << T[0].SotrudnikPointer[i].getId() << "; ";
  179.         }
  180.         cout << endl;
  181.         cout << "Name: ";
  182.         out += "\nName: ";
  183.         for (int i = 0; i < T[0].CurrentPos; i++)
  184.         {
  185.             out += T[0].SotrudnikPointer[i].getName() + "; ";
  186.             cout << T[0].SotrudnikPointer[i].getName() << "; ";
  187.         }
  188.         cout << endl;
  189.         cout << "Surname: ";
  190.         out += "\nSurname: ";
  191.         for (int i = 0; i < T[0].CurrentPos; i++)
  192.         {
  193.             out += T[0].SotrudnikPointer[i].getSurname() + "; ";
  194.             cout << T[0].SotrudnikPointer[i].getSurname() << "; ";
  195.         }
  196.         cout << endl;
  197.         cout << "Time: ";
  198.         out += "\nTime: ";
  199.         for (int i = 0; i < T[0].CurrentPos; i++)
  200.         {
  201.             out += to_string(T[0].SotrudnikPointer[i].getTime()) + "; ";
  202.             cout << T[0].SotrudnikPointer[i].getTime() << "; ";
  203.         }
  204.         cout << endl;
  205.         out += "\n";
  206.         ofstream fout;
  207.         fout.open("String.txt");
  208.         fout << out;
  209.         fout.close();
  210.     }
  211.     ~TProcessor();
  212. };
  213. void TProcessor::calculateEarnings(int rate)
  214. {
  215.     cout << " __________________________________________________________________" << endl;
  216.     cout << " |     ID     |    Name    |   Surname  |    Time    |  Earnings  | " << endl;
  217.     cout << " |------------|------------|------------|------------|------------|" << endl;
  218.     for (int i = 0; i < Tpointer[0].getMax(); i++)
  219.         cout << left << " |" << setw(12) << Tpointer[0].SotrudnikPointer[i].getId() << "|" << setw(12) << Tpointer[0].SotrudnikPointer[i].getName() << "|" << setw(12)
  220.         << Tpointer[0].SotrudnikPointer[i].getSurname() << "|" << setw(12) << Tpointer[0].SotrudnikPointer[i].getTime() << "|" << setw(12) << Tpointer[0].SotrudnikPointer[i].getTime()*rate << "|" << endl;
  221.     cout << " __________________________________________________________________" << endl;
  222. }
  223. TProcessor::TProcessor()
  224. {
  225.     cout << "Constructor class TProcessor" << endl;
  226. };
  227. TProcessor::TProcessor(TTabel *T)
  228. {
  229.     Tpointer = T;
  230. }
  231. TProcessor::~TProcessor()
  232. {
  233.     cout << "Destructor class TProcessor" << endl;
  234. };
  235.  
  236. int main()
  237. {
  238.     int max = 0, rate = 5;
  239.     string name = "", surname = "";
  240.     int Id = 0;
  241.     cout << "Enter the number of employees: ";
  242.     cin >> max;
  243.     TSotrudnik *employees;
  244.     employees = new TSotrudnik[max];
  245.     TTabel table(employees, max);
  246.     for (int i = 0; i < max; i++)
  247.     {
  248.         table.addSotrudnik();
  249.     }
  250.     TProcessor processor(&table);
  251.     StringOutput* SO = &processor;
  252.     TableOutput* TO = &processor;
  253.     SO->Print(&table);
  254.     TO->Print(&table);
  255.     processor.calculateEarnings(rate);
  256.     system("pause");
  257. }
Advertisement
Add Comment
Please, Sign In to add comment