Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #pragma once
  2. #include <iostream>
  3. #include <string>
  4. #include <ctime>
  5.  
  6. using std::string;
  7. using std::cout;
  8. using std::endl;
  9.  
  10. struct Date
  11. {
  12.     unsigned int year;
  13.     unsigned short month;
  14.     unsigned short day;
  15. };
  16.  
  17. class Person
  18. {
  19. protected:
  20.     Date d;
  21.     string sname;
  22. public:
  23.     Person(Date date, string sn) :d(date), sname(sn)
  24.     {}
  25.     virtual void display_info() = 0;
  26.     virtual unsigned short get_age()
  27.     {
  28.         time_t now = time(0);
  29.         tm* gmt = new tm;
  30.         gmtime_s(gmt, &now);
  31.         unsigned short res = gmt->tm_year - d.year + 1900;
  32.         if (gmt->tm_mon < d.month)
  33.             res--;
  34.         else if ((gmt->tm_mon == d.month) && (gmt->tm_mday < d.day))
  35.             res--;
  36.         return res;
  37.  
  38.     }
  39. };
  40.  
  41. class Enrollee :public Person
  42. {
  43. private:
  44.     string fac;
  45. public:
  46.     Enrollee(Date d, string sn, string f): Person(d,sn), fac(f)
  47.     {}
  48.     void display_info() override
  49.     {
  50.         cout << "Дата рождения: ";
  51.         if (d.day < 10)
  52.             cout << "0";
  53.         cout << d.day << ".";
  54.         if (d.month < 10)
  55.             cout << "0";
  56.         cout << d.month << ".";
  57.  
  58.         cout << d.year << endl;
  59.         cout << "Фамилия: " << sname << endl;
  60.         cout << "Факультет: " << fac << endl;
  61.     }
  62.  
  63. };
  64.  
  65. class Student : public Enrollee
  66. {
  67. private:
  68.     unsigned short course;
  69. public:
  70.     Student(Date d, string sn, string fac, short c) :Enrollee(d,sn,fac), course(c)
  71.     {}
  72.     void display_info() override
  73.     {
  74.         Enrollee::display_info();
  75.         cout << "Курс: " << course << endl;
  76.     }
  77. };
  78.  
  79. class Lecture :public Person
  80. {
  81. private:
  82.     string fac;
  83.     string post;
  84.     unsigned short exp;
  85. public:
  86.     Lecture(Date dt, string sn, string f, string p, unsigned short e) : Person(dt, sn), fac(f), post(p), exp(e)
  87.     {}
  88.     void display_info() override
  89.     {
  90.         cout << "Дата рождения: ";
  91.         if (d.day < 10)
  92.             cout << "0";
  93.         cout << d.day << ".";
  94.         if (d.month < 10)
  95.             cout << "0";
  96.         cout << d.month << ".";
  97.         cout << d.year << endl;
  98.  
  99.         cout << "Фамилия: " << sname << endl;
  100.         cout << "Факультет: " << fac << endl;
  101.         cout << "Должность: " << post << endl;
  102.         cout << "Стаж: " << exp << endl;
  103.     }
  104. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement