Advertisement
constk

A bit of inheritance 1.2

Sep 24th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.36 KB | None | 0 0
  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.     void input()
  22.     {
  23.         cout << "Input name: "; cin >> name;
  24.         cout << "Input id:   "; cin >> id;
  25.     }
  26.  
  27. protected:
  28.     string name;
  29.     int id;
  30. };
  31.  
  32. class Student
  33. {
  34. public:
  35.     Student() : education("no"), degree("no") {}
  36.     Student(string education, string degree) : education(education), degree(degree) {}
  37.  
  38.     string getEducation() { return education; }
  39.     string getDegree() { return degree; }
  40.  
  41.     void setEducation(string education) { this->education = education; }
  42.     void setDegree(string degree) { this->degree = degree; }
  43.  
  44.     void show() { cout << "Finished " + education + " as " + degree + "." << endl; }
  45.     void input()
  46.     {
  47.         cout << "Input education: "; cin >> education;
  48.         cout << "Input degree:    "; cin >> degree;
  49.     }
  50.  
  51. protected:
  52.     string education;
  53.     string degree;
  54. };
  55.  
  56. class Manager : private Employee, private Student
  57. {
  58. public:
  59.     Manager() : Employee(), Student(), position("default"), fitnessTaxes(0) {}
  60.     Manager(string name, int id, string education, string degree, string position, double fitnessTaxes) : Employee(name, id), Student(education, degree), position(position), fitnessTaxes(fitnessTaxes) {}
  61.     ~Manager() {}
  62.  
  63.  
  64.     string getEducation() { return Student::getEducation(); }
  65.     string getDegree() { return Student::getDegree(); }
  66.    
  67.     string getName() { return Employee::getName(); }
  68.     int getId() { return Employee::getId(); }
  69.    
  70.     string getPosition() { return position; }
  71.     double getFitnessTaxes() { return fitnessTaxes; }
  72.  
  73.  
  74.     void setEducation(string education) { Student::setEducation(education); }
  75.     void setDegree(string degree) { Student::setDegree(degree); }
  76.    
  77.     void setName(string name) { Employee::setName(name); }
  78.     void setId(int id) { Employee::setId(id); }
  79.    
  80.     void setPosition(string position) { this->position = position; }
  81.     void setFitnessTaxes(double fitnessTaxes) { this->fitnessTaxes = fitnessTaxes; }
  82.  
  83.  
  84.     void show()
  85.     {
  86.         Employee::show();
  87.         Student::show();
  88.         cout << "Is a " << position << ", pays for fitness " << fitnessTaxes << " dollars." << endl;
  89.     }
  90.     void input()
  91.     {
  92.         Employee::input();
  93.         Student::input();
  94.         cout << "Input position:      "; cin >> position;
  95.         cout << "Input fitness taxes: "; cin >> fitnessTaxes;
  96.     }
  97.  
  98. protected:
  99.     string position;
  100.     double fitnessTaxes;
  101. };
  102.  
  103. class Scientist : private Employee, private Student
  104. {
  105. public:
  106.     Scientist() : Employee(), Student(), amountOfArticles(0) {}
  107.     Scientist(string name, int id, string education, string degree, int amountOfArticles) : Employee(name, id), Student(education, degree), amountOfArticles(amountOfArticles) {}
  108.     ~Scientist() {}
  109.  
  110.  
  111.     string getEducation() { return Student::getEducation(); }
  112.     string getDegree() { return Student::getDegree(); }
  113.    
  114.     string getName() { return Employee::getName(); }
  115.     int getId() { return Employee::getId(); }
  116.    
  117.     int getAmountOfArticles() { return amountOfArticles; }
  118.  
  119.  
  120.     void setEducation(string education) { Student::setEducation(education); }
  121.     void setDegree(string degree) { Student::setDegree(degree); }
  122.    
  123.     void setName(string name) { Employee::setName(name); }
  124.     void setId(int id) { Employee::setId(id); }
  125.    
  126.     void setAmountOfArticles(int amountOfArticles) { this->amountOfArticles = amountOfArticles;  }
  127.  
  128.  
  129.     void show()
  130.     {
  131.         Employee::show();
  132.         Student::show();
  133.         cout << "Published " << amountOfArticles << " articles." << endl;
  134.     }
  135.     void input()
  136.     {
  137.         Employee::input();
  138.         Student::input();
  139.         cout << "Input amount of articles: "; cin >> amountOfArticles;
  140.     }
  141.  
  142. protected:
  143.     int amountOfArticles;
  144. };
  145.  
  146. class Worker : public Employee
  147. {
  148. public:
  149.     Worker() : Employee() {}
  150.     Worker(string name, int id) : Employee(name, id) {}
  151.     ~Worker() {}
  152.  
  153.     void show() { Employee::show(); }
  154.     void input() { Employee::input(); }
  155. };
  156.  
  157. class Brigadier : public Worker
  158. {
  159. public:
  160.     Brigadier() : Worker(), productionRate(0.0) {}
  161.     Brigadier(string name, int id, int productionRate) : Worker(name, id), productionRate(productionRate) {}
  162.     ~Brigadier() {}
  163.  
  164.     int getProductionRate() { return productionRate; }
  165.  
  166.     void setProductionRate(int productionRate) { this->productionRate = productionRate; }
  167.  
  168.     void show()
  169.     {
  170.         Worker::show();
  171.         cout<< "Is a brigadier. His production rate is " << productionRate << "%" << endl;
  172.     }
  173.     void input()
  174.     {
  175.         Worker::input();
  176.         cout << "Input production rate: "; cin >> productionRate;
  177.     }
  178.  
  179. protected:
  180.     int productionRate;
  181. };
  182.  
  183. int main()
  184. {
  185.     SetConsoleCP(1251);
  186.     SetConsoleOutputCP(1251);
  187.  
  188.     Employee * e = new Employee();
  189.     e->input();
  190.     e->show();
  191.     puts("##################################");
  192.  
  193.     Manager * m = new Manager();
  194.     m->input();
  195.     m->show();
  196.     puts("##################################");
  197.    
  198.     Scientist * s = new Scientist();
  199.     s->input();
  200.     s->show();
  201.     puts("##################################");
  202.  
  203.     Worker * w = new Worker();
  204.     w->input();
  205.     w->show();
  206.     puts("##################################");
  207.  
  208.     Brigadier * b = new Brigadier();
  209.     b->input();
  210.     b->show();
  211.     puts("##################################");
  212.  
  213.     system("pause>nul");
  214.     return 0;
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement