Advertisement
Guest User

Untitled

a guest
May 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Human
  6. {
  7.  
  8. protected:
  9.  
  10.     string surname;
  11.     string name;
  12.     string midname;
  13.     int age;
  14.  
  15. public:
  16.  
  17.     Human()
  18.     {
  19.         surname = "Ivanov";
  20.         name = "Ivan";
  21.         midname = "Ivanovich";
  22.         age = 18;
  23.     }
  24.  
  25.     Human(const string &surname, const string &name, const string &midname, int age)
  26.     : surname(surname), name(name), midname(midname), age(age) {}
  27.  
  28.     virtual void print() = 0;
  29.  
  30.     ~Human(){}
  31.  
  32. };
  33.  
  34. class Student : public Human
  35. {
  36.  
  37. private:
  38.  
  39.     bool on_lesson;
  40.  
  41. public:
  42.  
  43.     Student() : Human()
  44.     {
  45.         on_lesson = false;
  46.     }
  47.  
  48.     Student(const string &surname, const string &name, const string &midname, int age, bool on_lesson)
  49.             : Human(surname, name, midname, age), on_lesson(on_lesson) {}
  50.  
  51.     void print() override {
  52.         cout << "Name: " << name << endl
  53.              << "Surmane: " << surname << endl
  54.              << "Midname: " << midname << endl
  55.              << "Age: " << age << endl
  56.              << "Is he/she on lesson: " << boolalpha << on_lesson << endl;
  57.     }
  58.  
  59.     ~Student(){}
  60.  
  61. };
  62.  
  63. class Boss : public Human
  64. {
  65.  
  66. private:
  67.  
  68.     int number_of_workers;
  69.  
  70. public:
  71.  
  72.     Boss() : Human()
  73.     {
  74.         number_of_workers = 0;
  75.     }
  76.  
  77.     Boss(const string &surname, const string &name, const string &midname, int age, int number_of_workers)
  78.             : Human(surname, name, midname, age), number_of_workers(number_of_workers) {}
  79.  
  80.     void print() override {
  81.         cout << "Name: " << name << endl
  82.              << "Surmane: " << surname << endl
  83.              << "Midname: " << midname << endl
  84.              << "Age: " << age << endl
  85.              << "Number of workers: " << number_of_workers << endl;
  86.     }
  87.  
  88.     ~Boss(){}
  89.  
  90. };
  91.  
  92. int main() {
  93.  
  94.     Student s;
  95.     Boss b;
  96.  
  97.     s.print();
  98.     cout << endl;
  99.     b.print();
  100.  
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement