Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using std::endl;
- using std::cout;
- using std::string;
- class Person
- {
- public:
- Person(){}
- Person(string name, int age, string city)
- {
- this->age = age;
- this->city = city;
- this->name = name;
- }
- virtual void GetInfo() {}
- protected:
- int age;
- string name;
- string city;
- };
- class Citizen : public Person
- {
- public:
- using Person::Person;
- virtual void GetInfo()
- {
- cout << "Citizen" << endl;
- cout << "Name: " << name << endl;
- cout << "Age: " << age << endl;
- cout << "City: " << city << endl;
- cout << endl;
- }
- };
- class Employee : public Person
- {
- public:
- using Person::Person;
- virtual void GetInfo()
- {
- cout << "Employee" << endl;
- cout << "Name: " << name << endl;
- cout << "Age: " << age << endl;
- cout << "City: " << city << endl;
- cout << endl;
- }
- };
- class Student : public Person
- {
- public:
- using Person::Person;
- virtual void GetInfo()
- {
- cout << "Employee" << endl;
- cout << "Name: " << name << endl;
- cout << "Age: " << age << endl;
- cout << "City: " << city << endl;
- cout << endl;
- }
- };
- int main()
- {
- Person *List[3];
- List[0] = new Employee("Bjarne Straustrup", 55, "Chervonohrad");
- List[1] = new Student("Linux Torvalds", 26, "Toronto");
- List[2] = new Citizen("Dmitri Komisarenko", 18, "Orenburg");
- for (int i = 0; i < 3; i++)
- {
- List[i]->GetInfo();
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement