Advertisement
myname0

class_36

May 5th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Persona
  8. {
  9. public:
  10.         virtual void Show() = 0;
  11.         virtual int Age(int year, int month, int day) = 0;
  12. };
  13.  
  14. class Enrolle: public Persona
  15. {
  16. protected:
  17.     string Surname;
  18.     int DOB;
  19.     string Faculty;
  20. public:
  21.     Enrolle(): Surname("."), DOB(00000000), Faculty(".")
  22.     {
  23.     }
  24.     Enrolle(string a, int x, string b): Surname(a), DOB(x), Faculty(b)
  25.     {
  26.     }
  27.     void Show()
  28.     {
  29.         cout << Surname << "/n" << DOB/1000000 << "." << DOB%1000000/10000 <<"." << DOB%10000 << "/n" << Faculty << endl;
  30.     }
  31.     int Age(int year, int month, int day)
  32.     {
  33.         if (DOB%1000000/10000 < month) return year + 1900 - DOB%10000;
  34.         else if(DOB%1000000/10000 == month)
  35.         {
  36.             if (DOB/1000000 <= day) return year + 1900 - DOB%10000;
  37.             else return year + 1899 - DOB%10000;
  38.         }  
  39.         else return year + 1899 - DOB%10000;
  40.     }
  41.    
  42. };
  43.  
  44. class Student: public Persona
  45. {
  46. protected:
  47.     string Surname;
  48.     int DOB;
  49.     string Faculty;
  50.     int Cours;
  51. public:
  52.     Student(): Surname("."), DOB(00000000), Faculty("."), Cours(0)
  53.     {
  54.     }
  55.     Student(string a, int x, string b, int c): Surname(a), DOB(x), Faculty(b), Cours(c)
  56.     {
  57.     }
  58.     void Show()
  59.     {
  60.         cout << Surname << "/n" << DOB/1000000 << "." << DOB%1000000/10000 <<"." << DOB%10000 << "/n"
  61.             << Faculty << "/n" << Cours << endl;
  62.     }
  63.     int Age(int year, int month, int day)
  64.     {
  65.         if (DOB%1000000/10000 < month) return year + 1900 - DOB%10000;
  66.         else if(DOB%1000000/10000 == month)
  67.         {
  68.             if (DOB/1000000 <= day) return year + 1900 - DOB%10000;
  69.             else return year + 1899 - DOB%10000;
  70.         }  
  71.         else return year + 1899 - DOB%10000;
  72.     }
  73.    
  74. };  
  75.  
  76. class Teacher: public Persona
  77. {
  78. protected:
  79.     string Surname;
  80.     int DOB;
  81.     string Faculty;
  82.     string Post;
  83.     int Experience;
  84. public:
  85.     Teacher(): Surname("."), DOB(00000000), Faculty("."), Post("."), Experience(0)
  86.     {
  87.     }
  88.     Teacher(string a, int x, string b, string d, int e): Surname(a), DOB(x), Faculty(b), Post(d), Experience(e)
  89.     {
  90.     }
  91.     void Show()
  92.     {
  93.         cout << Surname << "/n" << DOB/1000000 << "." << DOB%1000000/10000 <<"." << DOB%10000 << "/n" << Faculty
  94.             << "/n" << Post << "/n" << Experience << endl;
  95.     }
  96.     int Age(int year, int month, int day)
  97.     {
  98.         if (DOB%1000000/10000 < month) return year + 1900 - DOB%10000;
  99.         else if(DOB%1000000/10000 == month)
  100.         {
  101.             if (DOB/1000000 <= day) return year + 1900 - DOB%10000;
  102.             else return year + 1899 - DOB%10000;
  103.         }  
  104.         else return year + 1899 - DOB%10000;
  105.     }
  106. };
  107.  
  108. using namespace std;
  109.  
  110. int main()
  111. {
  112.     time_t t = time(0);
  113.     struct tm now;
  114.     localtime_s(&now,&t);
  115.    /* int age = 1996;
  116.     int year = now.tm_year + 1900 - age;
  117.         cout << year;*/
  118.     setlocale( LC_ALL, "Russian");
  119.     Persona *Human [9];
  120.     Human[0] = new Enrolle("Аванесян", 12091996, "КНИИТ");
  121.     Human[1] = new Student("Бескровнов", 12031996, "КНИИТ", 1);
  122.     Human[2] = new Teacher("Болдырев", 9091972, "КНИИТ","Teacher", 7);
  123.     Human[3] = new Enrolle("Гараничева", 3081945, "КНИИТ");
  124.     Human[4] = new Student("Добрынин", 18052014, "КНИИТ", 1);
  125.     Human[5] = new Teacher("Дьяячков", 19051934, "КНИИТ", "Teacher", 8);
  126.     Human[6] = new Enrolle("Елисеева", 17051967, "КНИИТ");
  127.     Human[7] = new Student("Еремушкин", 30041989, "КНИИТ", 2);
  128.     Human[8] = new Teacher("Ермолаев", 16081996, "КНИИТ", "Teacher", 2);
  129.     Human[9] = new Enrolle("Зажарнов", 12091996, "КНИИТ");
  130.     for(int i = 0; i<10; i++)
  131.     {
  132.         Human[i]->Show();
  133.     }
  134.     int a, b;
  135.     cout << "Ener the age range ";
  136.     cin >> a >> b;
  137.     for(int i = 0; i < 1; i++)
  138.     {
  139.         if (Human[i]->Age(now.tm_year, now.tm_mon, now.tm_mday) > a &&
  140.             Human[i]->Age(now.tm_year, now.tm_mon, now.tm_mday) < b)
  141.             Human[i]->Show();
  142.     }
  143.        
  144.  
  145.         //struct tm {
  146.  //       int tm_sec;     /* seconds after the minute - [0,59] */
  147.  //       int tm_min;     /* minutes after the hour - [0,59] */
  148.  //       int tm_hour;    /* hours since midnight - [0,23] */
  149.  //       int tm_mday;    /* day of the month - [1,31] */
  150.  //       int tm_mon;     /* months since January - [0,11] */
  151.  //       int tm_year;    /* years since 1900 */
  152.  //       int tm_wday;    /* days since Sunday - [0,6] */
  153.  //       int tm_yday;    /* days since January 1 - [0,365] */
  154.  //       int tm_isdst;   /* daylight savings time flag */
  155.  //       };
  156.         return 0;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement