Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <string>
- #include <ctime>
- using std::string;
- using std::cout;
- using std::endl;
- struct Date
- {
- unsigned int year;
- unsigned short month;
- unsigned short day;
- };
- class Person
- {
- protected:
- Date d;
- string sname;
- public:
- Person(Date date, string sn) :d(date), sname(sn)
- {}
- virtual void display_info() = 0;
- virtual unsigned short get_age()
- {
- time_t now = time(0);
- tm* gmt = new tm;
- gmtime_s(gmt, &now);
- unsigned short res = gmt->tm_year - d.year + 1900;
- if (gmt->tm_mon < d.month)
- res--;
- else if ((gmt->tm_mon == d.month) && (gmt->tm_mday < d.day))
- res--;
- return res;
- }
- };
- class Enrollee :public Person
- {
- private:
- string fac;
- public:
- Enrollee(Date d, string sn, string f): Person(d,sn), fac(f)
- {}
- void display_info() override
- {
- cout << "Дата рождения: ";
- if (d.day < 10)
- cout << "0";
- cout << d.day << ".";
- if (d.month < 10)
- cout << "0";
- cout << d.month << ".";
- cout << d.year << endl;
- cout << "Фамилия: " << sname << endl;
- cout << "Факультет: " << fac << endl;
- }
- };
- class Student : public Enrollee
- {
- private:
- unsigned short course;
- public:
- Student(Date d, string sn, string fac, short c) :Enrollee(d,sn,fac), course(c)
- {}
- void display_info() override
- {
- Enrollee::display_info();
- cout << "Курс: " << course << endl;
- }
- };
- class Lecture :public Person
- {
- private:
- string fac;
- string post;
- unsigned short exp;
- public:
- Lecture(Date dt, string sn, string f, string p, unsigned short e) : Person(dt, sn), fac(f), post(p), exp(e)
- {}
- void display_info() override
- {
- cout << "Дата рождения: ";
- if (d.day < 10)
- cout << "0";
- cout << d.day << ".";
- if (d.month < 10)
- cout << "0";
- cout << d.month << ".";
- cout << d.year << endl;
- cout << "Фамилия: " << sname << endl;
- cout << "Факультет: " << fac << endl;
- cout << "Должность: " << post << endl;
- cout << "Стаж: " << exp << endl;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement