Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- int dm[12] = { 31, 27, 31, 30, 31, 30, 31,30, 31,30,31,30 };
- int currentData = 21052019;
- int D(int data)
- {
- int day = data / 1000000;
- int m = data / 10000;
- m = m % 100;
- int g = data % 10000;
- for (int i = 0; i < m; ++i)
- day += dm[i];
- return day + g * 365;
- }
- class Persona
- {
- public:
- virtual void info() = 0;
- virtual void old() = 0;
- };
- class Enrollee : public Persona
- {
- protected:
- string vam, fak;
- int data;
- public:
- Enrollee(string vam, int data, string fak)
- {
- this->vam = vam;
- this->data = data;
- this->fak = fak;
- }
- void info()
- {
- cout << "Vamilia: " << vam << " Data(dd/mm/gg): " << data << " Fakultet: " << fak << endl;
- }
- void old() override
- {
- int day = D(currentData) - D(data);
- int g = day / 365;
- day %= 365;
- int m = 0;
- for (int i = 0; i < 12; ++i)
- if (day - dm[i] > 0)
- {
- m++;
- day -= dm[i];
- }
- cout << day << " days, " << m << " month, " << g << "Years\n\n";
- }
- };
- class Student :public Enrollee
- {
- protected:
- int kurs;
- public:
- Student(string vam, int data, string fak, int kurs) : Enrollee(vam, data, fak) { this->kurs = kurs; }
- void info()
- {
- cout << "Vamilia: " << vam << " Data(dd/mm/gg): " << data << " Fakultet: " << fak << " Kurs:" << kurs << endl;
- }
- };
- class Teacher : public Enrollee
- {
- protected:
- string dol;
- float staj;
- public:
- Teacher(string vam, int data, string fak, string dol, float staj) : Enrollee(vam, data, fak)
- {
- this->dol = dol;
- this->staj = staj;
- }
- void info()
- {
- cout << "Vamilia: " << vam << " Data(dd/mm/gg): " << data << " Fakultet: " << fak << " Doljnost: " << dol << " Staj: " << staj << endl;
- }
- };
- int main()
- {
- int currentData = 00000001;
- Persona *a[3];
- a[0] = new Enrollee("Ivanov", 23 * 1000000 + 12 * 10000 + 1991, "CSIT");
- a[1] = new Student("Sidoriv", 2 * 1000000 + 2 * 10000 + 2000, "CSIT", 2);
- a[2] = new Teacher("Petrova", 25 * 1000000 + 9 * 10000 + 1968, "MexMat", "prepodavatel", 20);
- for (int i = 0; i < 3; ++i)
- {
- a[i]->old();
- }
- for (int i = 0; i < 3; i++)
- {
- delete a[i];
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement