Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- class Person {
- public:
- Person(const string& a) :Name(a){}
- virtual void Walk(const string& destination) const {
- cout << Person_Type << ": " << Name << " walks to: " << destination << endl;};
- const string Name,Person_Type;
- string get_type() { return Person_Type;}
- protected:
- string Person_Type="TYPE";
- };
- class Student:public Person {
- public:
- Student(const string& name, const string& favouriteSong) :
- Person(name),
- FavouriteSong(favouriteSong) {Person_Type = "Student";}
- void Learn()const {
- cout << Person_Type << ": " << Name << " learns" << endl;
- }
- void Walk (const string& destination)const override {
- cout << Person_Type << ": " << Name << " walks to: " << destination << endl;
- cout << Person_Type << ": " << Name << " sings a song: " << FavouriteSong << endl;
- }
- void SingSong() const {
- cout << Person_Type << ": " << Name << " sings a song: " << FavouriteSong << endl;
- }
- private:
- const string FavouriteSong;
- };
- class Teacher:public Person {
- public:
- Teacher(const string& name, const string& subject) :
- Person(name),
- Subject(subject) {Person_Type = "Teacher";}
- void Teach() {
- cout << Person_Type << ": " << Name << " teaches: " << Subject << endl;
- }
- private:
- const string Subject;
- };
- class Policeman:public Person {
- public:
- Policeman(string name):
- Person(name) {Person_Type = "Policeman";}
- void Check(Person t) {
- cout << Person_Type << ": " << Name << " checks "<<t.get_type()<<". "<< t.get_type()<<"'s name is: " << t.Name << endl;
- }
- };
- void VisitPlaces(const Person& t, const vector<string>& places) {
- for (const auto& p : places) {
- t.Walk(p);
- }
- }
- int main() {
- Teacher t("Jim", "Math");
- Student s("Ann", "We will rock you");
- Policeman p("Bob");
- VisitPlaces(t, { "Moscow", "London" });
- p.Check(s);
- VisitPlaces(s, { "Moscow", "London" });
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement