constk

A bit of inheritance 1.1

Sep 23rd, 2020
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include "Windows.h"
  4.  
  5. using namespace std;
  6.  
  7. class Employee
  8. {
  9. public:
  10.     Employee() : name("dafault"), id(0) {}
  11.     Employee(string name, int id) : name(name), id(id) {}
  12.     ~Employee() {}
  13.  
  14.     string getName() { return name; }
  15.     int getId() { return id; }
  16.  
  17.     void setName(string name) { this->name = name; }
  18.     void setId(int id) { this->id = id; }
  19.  
  20.     void show() { cout << id << " > " + name + "." << endl; }
  21.  
  22. protected:
  23.     string name;
  24.     int id;
  25. };
  26.  
  27. class Student
  28. {
  29. public:
  30.     Student() : education("no"), degree("no") {}
  31.     Student(string education, string degree) : education(education), degree(degree) {}
  32.  
  33.     string getEducation() { return education; }
  34.     string getDegree() { return degree; }
  35.  
  36.     void setEducation(string education) { this->education = education; }
  37.     void setDegree(string degree) { this->degree = degree; }
  38.  
  39. protected:
  40.     string education;
  41.     string degree;
  42. };
  43.  
  44. class Manager : private Employee, private Student
  45. {
  46. public:
  47.     Manager() : Employee(), Student(), position("default"), fitnessTaxes(0) {}
  48.     Manager(string name, int id, string education, string degree, string position, double fitnessTaxes) : Employee(name, id), Student(education, degree), position(position), fitnessTaxes(fitnessTaxes) {}
  49.     ~Manager() {}
  50.  
  51.  
  52.     string getEducation() { return Student::getEducation(); }
  53.     string getDegree() { return Student::getDegree(); }
  54.    
  55.     string getName() { return Employee::getName(); }
  56.     int getId() { return Employee::getId(); }
  57.    
  58.     string getPosition() { return position; }
  59.     double getFitnessTaxes() { return fitnessTaxes; }
  60.  
  61.  
  62.     void setEducation(string education) { Student::setEducation(education); }
  63.     void setDegree(string degree) { Student::setDegree(degree); }
  64.    
  65.     void setName(string name) { Employee::setName(name); }
  66.     void setId(int id) { Employee::setId(id); }
  67.    
  68.     void setPosition(string position) { this->position = position; }
  69.     void setFitnessTaxes(double fitnessTaxes) { this->fitnessTaxes = fitnessTaxes; }
  70.  
  71.  
  72.     void show() { cout << id << " > " + name + ", " + position + " pays for fitness " << fitnessTaxes << " bucks." << endl; }
  73.  
  74. protected:
  75.     string position;
  76.     double fitnessTaxes;
  77. };
  78.  
  79. class Scientist : private Employee, private Student
  80. {
  81. public:
  82.     Scientist() : Employee(), Student(), amountOfArticles(0) {}
  83.     Scientist(string name, int id, string education, string degree, int amountOfArticles) : Employee(name, id), Student(education, degree), amountOfArticles(amountOfArticles) {}
  84.     ~Scientist() {}
  85.  
  86.  
  87.     string getEducation() { return Student::getEducation(); }
  88.     string getDegree() { return Student::getDegree(); }
  89.    
  90.     string getName() { return Employee::getName(); }
  91.     int getId() { return Employee::getId(); }
  92.    
  93.     int getAmountOfArticles() { return amountOfArticles; }
  94.  
  95.  
  96.     void setEducation(string education) { Student::setEducation(education); }
  97.     void setDegree(string degree) { Student::setDegree(degree); }
  98.    
  99.     void setName(string name) { Employee::setName(name); }
  100.     void setId(int id) { Employee::setId(id); }
  101.    
  102.     void setAmountOfArticles(int amountOfArticles) { this->amountOfArticles = amountOfArticles;  }
  103.  
  104.  
  105.     void show() { cout << id << " > " + name + ", published " << amountOfArticles << " articles." << endl; }
  106.  
  107. protected:
  108.     int amountOfArticles;
  109. };
  110.  
  111. class Worker : public Employee
  112. {
  113. public:
  114.     Worker() : Employee() {}
  115.     Worker(string name, int id) : Employee(name, id) {}
  116.  
  117.     void show() { cout << id << " > " + name + " is a bricklayer, works for three days, without salary!!!" << endl; }
  118.  
  119.     ~Worker() {}
  120. };
  121.  
  122. class Brigadier : public Worker
  123. {
  124. public:
  125.     Brigadier() : Worker(), productionRate(0.0) {}
  126.     Brigadier(string name, int id, int productionRate) : Worker(name, id), productionRate(productionRate) {}
  127.     ~Brigadier();
  128.  
  129.     int getProductionRate() { return productionRate; }
  130.  
  131.     void setProductionRate(int productionRate) { this->productionRate = productionRate; }
  132.  
  133.     void show() { cout << id << " > " + name + " is brigadier. His production rate is " << productionRate << "%" << endl; }
  134.  
  135. protected:
  136.     int productionRate;
  137. };
  138.  
  139. int main()
  140. {
  141.     SetConsoleCP(1251);
  142.     SetConsoleOutputCP(1251);
  143.  
  144.     Employee * e = new Employee("Todd Howard", 0);
  145.     e->show();
  146.  
  147.     Manager * m = new Manager("Kim Chen In", 1, "non", "non", "the dictator", 300);
  148.     m->show();
  149.     cout << m->getName() + " finished " + m->getEducation() + " as " + m->getDegree() << endl;
  150.  
  151.     Scientist * s = new Scientist("Popov", 2, "rsreu", "candidate of science", 150);
  152.     s->show();
  153.     cout << s->getName() + " finished " + s->getEducation() + " as " + s->getDegree() << endl;
  154.  
  155.     Worker * w = new Worker("Rabotyaga", 3);
  156.     w->show();
  157.  
  158.     Brigadier * b = new Brigadier("Boss of the gym", 4, 100);
  159.     b->show();
  160.  
  161.     getchar();
  162.     return 0;
  163. }
RAW Paste Data