Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. class Person {
  9. public:
  10.     Person(const string& a) :Name(a){}
  11.     virtual void Walk(const string& destination) const {
  12.         cout << Person_Type << ": " << Name << " walks to: " << destination << endl;};
  13.     const string Name,Person_Type;
  14.     string get_type() { return Person_Type;}
  15. protected:
  16.     string Person_Type="TYPE";
  17.    
  18. };
  19.  
  20.  
  21.  
  22. class Student:public Person {
  23. public:
  24.  
  25.     Student(const string& name, const string& favouriteSong) :
  26.        
  27.         Person(name),
  28.         FavouriteSong(favouriteSong) {Person_Type = "Student";}
  29.        
  30.  
  31.     void Learn()const {
  32.         cout << Person_Type << ": " << Name << " learns" << endl;
  33.     }
  34.  
  35.     void Walk (const string& destination)const override {
  36.         cout << Person_Type << ": " << Name << " walks to: " << destination << endl;
  37.         cout << Person_Type << ": " << Name << " sings a song: " << FavouriteSong << endl;
  38.     }
  39.  
  40.     void SingSong() const {
  41.         cout << Person_Type << ": " << Name << " sings a song: " << FavouriteSong << endl;
  42.     }
  43.  
  44. private:
  45.     const string FavouriteSong;
  46. };
  47.  
  48.  
  49. class Teacher:public Person {
  50. public:
  51.  
  52.     Teacher(const string& name, const string& subject) :
  53.         Person(name),
  54.         Subject(subject) {Person_Type = "Teacher";}
  55.  
  56.     void Teach() {
  57.         cout << Person_Type << ": " << Name << " teaches: " << Subject << endl;
  58.     }
  59.  
  60. private:
  61.     const string Subject;
  62. };
  63.  
  64.  
  65. class Policeman:public Person {
  66. public:
  67.     Policeman(string name):
  68.         Person(name) {Person_Type = "Policeman";}
  69.  
  70.     void Check(Person t) {
  71.         cout << Person_Type << ": " << Name << " checks "<<t.get_type()<<". "<< t.get_type()<<"'s name is: " << t.Name << endl;
  72.     }  
  73.  
  74. };
  75.  
  76.  
  77. void VisitPlaces(const Person& t, const vector<string>& places) {
  78.     for (const auto& p : places) {
  79.         t.Walk(p);
  80.     }
  81. }
  82.  
  83.  
  84. int main() {
  85.     Teacher t("Jim", "Math");
  86.     Student s("Ann", "We will rock you");
  87.     Policeman p("Bob");
  88.  
  89.     VisitPlaces(t, { "Moscow", "London" });
  90.     p.Check(s);
  91.     VisitPlaces(s, { "Moscow", "London" });
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement