Tavxela

Untitled

Jun 20th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class University {
  7. public:
  8. University(string name, int year);
  9. ~University() = default;
  10. virtual void info() const;
  11.  
  12. protected:
  13. string name;
  14. int year;
  15.  
  16. };
  17.  
  18. University::University(string name, int year) {
  19. this->name = name;
  20. this->year = year;
  21. }
  22.  
  23. void University::info() const {
  24. cout << "name: " << name <<
  25. "\nyear: " << year << endl;
  26. }
  27.  
  28. class doctoralStudent :
  29. protected University {
  30. public:
  31. doctoralStudent(int scholarship, int articles, string name, int year);
  32. ~doctoralStudent() = default;
  33. void info() const;
  34. int getArt() { return articles; }
  35. int getScho() { return scholarship; }
  36. void setScho(int scho) { scholarship = scho; }
  37. protected:
  38. int scholarship;
  39. int articles;
  40. };
  41.  
  42. doctoralStudent::doctoralStudent(int scholarship, int articles, string name, int year):
  43. University(name, year), scholarship(scholarship), articles(articles){}
  44.  
  45. void doctoralStudent::info() const{
  46. University::info();
  47. cout << "\nscholarship: " << scholarship <<
  48. "\narticles: " << articles << endl;
  49. }
  50.  
  51. class Proffesor :
  52. protected doctoralStudent {
  53. public:
  54. Proffesor(string, int, int, int, string, int);
  55. ~Proffesor() = default;
  56. void info() const;
  57. int getExp() { return experience; }
  58. void setExp(int exp) { experience = exp; }
  59. private:
  60. string position;
  61. int experience;
  62. };
  63.  
  64. Proffesor::Proffesor(string pos, int exp, int scho, int art, string name, int year):
  65. doctoralStudent(scho, art, name, year){
  66. position = pos;
  67. experience = exp;
  68. }
  69.  
  70. void Proffesor::info() const{
  71. doctoralStudent::info();
  72. cout << "\nposition: " << position <<
  73. "\nexperience: " << experience << endl;
  74. }
  75.  
  76. int main() {
  77. University* TSU = new University("TSU", 1881);
  78. doctoralStudent* stud = new doctoralStudent(2000, 6, "MIT", 1995);
  79. Proffesor* prof = new Proffesor("LECTURER", 10, 5000, 25, "TSU", 1881);
  80.  
  81. cout << "University: " << endl;
  82. TSU->info();
  83. cout << endl;
  84. cout << "Student: " << endl;
  85. stud->info();
  86. cout << endl;
  87. cout << "Proffesor: " << endl;
  88. prof->info();
  89.  
  90. int tmp = prof->getExp();
  91.  
  92. prof->setExp(tmp + 5);
  93.  
  94. tmp = stud->getScho();
  95. if (stud->getArt() > 4) {
  96. stud->setScho(tmp * 3);
  97. }
  98.  
  99. cout << "Proffesor: " << endl;
  100. prof->info();
  101. cout << endl;
  102. cout << "Student: " << endl;
  103. stud->info();
  104.  
  105. delete TSU;
  106. delete stud;
  107. delete prof;
  108. }
Add Comment
Please, Sign In to add comment