fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. class Employee {
  7. public:
  8. void SetName(string employeeName) {
  9. name = employeeName;
  10. }
  11.  
  12. virtual void PrintInfo() {
  13. cout << name << endl;
  14. }
  15.  
  16. protected:
  17. string name;
  18. };
  19.  
  20. class Coach : public Employee {
  21. public:
  22. void SetSport(string setSport) {
  23. sport = setSport;
  24. }
  25.  
  26. void PrintInfo() {
  27. cout << name << " coaches " << sport << endl;
  28. }
  29.  
  30. private:
  31. string sport;
  32. };
  33.  
  34. class Author : public Employee {
  35. public:
  36. void SetGenre(string setGenre) {
  37. genre = setGenre;
  38. }
  39.  
  40. void PrintInfo() {
  41. cout << name << " writes " << genre << endl;
  42. }
  43.  
  44. private:
  45. string genre;
  46. };
  47.  
  48. int main() {
  49. Employee* person1;
  50. Coach* person2;
  51. Author* person3;
  52.  
  53. vector<Employee*> personList;
  54. unsigned int i;
  55.  
  56. person1 = new Employee();
  57. person1->SetName("Joe");
  58.  
  59. person2 = new Coach();
  60. person2->SetName("Mia");
  61. person2->SetSport("hockey");
  62.  
  63. person3 = new Author();
  64. person3->SetName("Jose");
  65. person3->SetGenre("mysteries");
  66.  
  67. personList.push_back(person3);
  68. personList.push_back(person1);
  69. personList.push_back(person2);
  70.  
  71. for (i = 0; i < personList.size(); ++i) {
  72. personList.at(i)->PrintInfo();
  73. }
  74.  
  75. return 0;
  76. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Jose writes mysteries
Joe
Mia coaches hockey