Advertisement
Infiniti_Inter

35 problem 5

May 21st, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int dm[12] = { 31, 27, 31, 30, 31, 30, 31,30, 31,30,31,30 };
  8.  
  9. int currentData = 21052019;
  10.  
  11. int D(int data)
  12. {
  13.     int day = data / 1000000;
  14.     int m = data / 10000;
  15.     m = m % 100;
  16.     int g = data % 10000;
  17.     for (int i = 0; i < m; ++i)
  18.         day += dm[i];
  19.     return day + g * 365;
  20. }
  21.  
  22. class Persona
  23. {
  24. public:
  25.     virtual void info() = 0;
  26.     virtual void old() = 0;
  27. };
  28. class Enrollee : public Persona
  29. {
  30. protected:
  31.     string vam, fak;
  32.     int data;
  33. public:
  34.     Enrollee(string vam, int data, string fak)
  35.     {
  36.         this->vam = vam;
  37.         this->data = data;
  38.         this->fak = fak;
  39.     }
  40.     void info()
  41.     {
  42.         cout << "Vamilia: " << vam << " Data(dd/mm/gg): " << data << " Fakultet: " << fak << endl;
  43.     }
  44.     void old() override
  45.     {
  46.         int day = D(currentData) - D(data);
  47.         int g = day / 365;
  48.         day %= 365;
  49.         int m = 0;
  50.         for (int i = 0; i < 12; ++i)
  51.             if (day - dm[i] > 0)
  52.             {
  53.                 m++;
  54.                 day -= dm[i];
  55.             }
  56.         cout << day << " days, " << m << " month, " << g << "Years\n\n";       
  57.     }
  58. };
  59. class Student :public Enrollee
  60. {
  61. protected:
  62.     int kurs;
  63. public:
  64.     Student(string vam, int data, string fak, int kurs) : Enrollee(vam, data, fak) { this->kurs = kurs; }
  65.     void info()
  66.     {
  67.         cout << "Vamilia: " << vam << " Data(dd/mm/gg): " << data << " Fakultet: " << fak << " Kurs:" << kurs << endl;
  68.     }
  69.  
  70. };
  71. class Teacher : public Enrollee
  72. {
  73. protected:
  74.     string dol;
  75.     float staj;
  76. public:
  77.     Teacher(string vam, int data, string fak, string dol, float staj) : Enrollee(vam, data, fak)
  78.     {
  79.         this->dol = dol;
  80.         this->staj = staj;
  81.     }
  82.     void info()
  83.     {
  84.         cout << "Vamilia: " << vam << " Data(dd/mm/gg): " << data << " Fakultet: " << fak << " Doljnost: " << dol << " Staj: " << staj << endl;
  85.     }
  86.  
  87. };
  88. int main()
  89. {
  90.     int currentData = 00000001;
  91.     Persona *a[3];
  92.     a[0] = new Enrollee("Ivanov", 23 * 1000000 + 12 * 10000 + 1991, "CSIT");
  93.     a[1] = new Student("Sidoriv",  2 * 1000000 +  2 * 10000 + 2000, "CSIT", 2);
  94.     a[2] = new Teacher("Petrova", 25 * 1000000 +  9 * 10000 + 1968, "MexMat", "prepodavatel", 20);
  95.     for (int i = 0; i < 3; ++i)
  96.     {
  97.         a[i]->old();
  98.     }
  99.     for (int i = 0; i < 3; i++)
  100.     {
  101.         delete a[i];
  102.     }
  103.     system("pause");
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement