pawn007

error

May 1st, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Person
  5. {
  6. public:
  7. string profession;
  8. int age;
  9.  
  10. Person(): profession("unemployed"), age(16) { }
  11. void display()
  12. {
  13. cout << "My profession is: " << profession << endl;
  14. cout << "My age is: " << age << endl;
  15. walk();
  16. talk();
  17. }
  18. void walk() { cout << "I can walk." << endl; }
  19. void talk() { cout << "I can talk." << endl; }
  20. };
  21.  
  22. // MathsTeacher class is derived from base class Person.
  23. class MathsTeacher : public Person
  24. {
  25. public:
  26. void teachMaths() { cout << "I can teach Maths." << endl; }
  27. };
  28.  
  29. // Footballer class is derived from base class Person.
  30. class Footballer : public Person
  31. {
  32. public:
  33. void playFootball() { cout << "I can play Football." << endl; }
  34. };
  35.  
  36. int main()
  37. {
  38. MathsTeacher teacher;
  39. teacher.profession = "Teacher";
  40. teacher.age = 23;
  41. teacher.display();
  42. teacher.teachMaths();
  43.  
  44. Footballer footballer;
  45. footballer.profession = "Footballer";
  46. footballer.age = 19;
  47. footballer.display();
  48. footballer.playFootball();
  49.  
  50. return 0;
  51. }
Add Comment
Please, Sign In to add comment