avr39ripe

PV913InheritanceBasics

Jul 20th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class Human
  5. {
  6. private:
  7.     int parentField;
  8. protected:
  9.     int height{42};
  10. public:
  11.     std::string name;
  12.     int age;
  13.     void print() { std::cout << name << ' ' << age << ' ' << height << '\n'; };
  14. };
  15.  
  16. class Teacher : protected Human
  17. {
  18. public:
  19.     std::string universityName;
  20.     void printTeacher() { print(); std::cout << universityName << '\n'; }
  21.     //void setHeight(int heightP) { height = heightP; };
  22.    // int getHeight() { return height; };
  23. };
  24.  
  25. class Student : public Human
  26. {
  27. public:
  28.     std::string universityName;
  29.     float avgGrade;
  30. };
  31.  
  32. class Employee : public Human
  33. {
  34. public:
  35.     std::string companyName;
  36.     double salary;
  37. };
  38.  
  39. int main()
  40. {
  41.     Teacher me;
  42.   /*  me.name = "Alexander";
  43.     me.age = 38;*/
  44.     me.universityName = "STEP";
  45.     me.printTeacher();
  46.     //me.print();
  47.     //me.setHeight(182);
  48.     //std::cout << me.getHeight() << '\n';
  49.  
  50.     Student student1;
  51.     student1.name = "Bill";
  52.     student1.age = 44;
  53.     student1.universityName = "STEP";
  54.     student1.avgGrade = 9.7;
  55.     student1.print();
  56.  
  57. }
Add Comment
Please, Sign In to add comment