Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::endl;
  5. using std::cout;
  6. using std::string;
  7.  
  8. class Person
  9. {
  10.  
  11. public:
  12. Person(){}
  13. Person(string name, int age, string city)
  14. {
  15. this->age = age;
  16. this->city = city;
  17. this->name = name;
  18. }
  19. virtual void GetInfo() {}
  20.  
  21. protected:
  22. int age;
  23. string name;
  24. string city;
  25.  
  26. };
  27.  
  28. class Citizen : public Person
  29. {
  30.  
  31. public:
  32. using Person::Person;
  33. virtual void GetInfo()
  34. {
  35. cout << "Citizen" << endl;
  36. cout << "Name: " << name << endl;
  37. cout << "Age: " << age << endl;
  38. cout << "City: " << city << endl;
  39. cout << endl;
  40. }
  41. };
  42.  
  43. class Employee : public Person
  44. {
  45. public:
  46. using Person::Person;
  47. virtual void GetInfo()
  48. {
  49. cout << "Employee" << endl;
  50. cout << "Name: " << name << endl;
  51. cout << "Age: " << age << endl;
  52. cout << "City: " << city << endl;
  53. cout << endl;
  54. }
  55. };
  56.  
  57. class Student : public Person
  58. {
  59. public:
  60. using Person::Person;
  61. virtual void GetInfo()
  62. {
  63. cout << "Employee" << endl;
  64. cout << "Name: " << name << endl;
  65. cout << "Age: " << age << endl;
  66. cout << "City: " << city << endl;
  67. cout << endl;
  68. }
  69. };
  70.  
  71.  
  72. int main()
  73. {
  74. Person *List[3];
  75. List[0] = new Employee("Bjarne Straustrup", 55, "Chervonohrad");
  76. List[1] = new Student("Linux Torvalds", 26, "Toronto");
  77. List[2] = new Citizen("Dmitri Komisarenko", 18, "Orenburg");
  78. for (int i = 0; i < 3; i++)
  79. {
  80. List[i]->GetInfo();
  81. }
  82. system("pause");
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement