Created
November 26, 2025 17:12
-
-
Save nicolekorch/159b3d08b2e819470984a96433c0bef8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cstring> | |
| using namespace std; | |
| class Employer { | |
| public: | |
| virtual void Print() const = 0; | |
| virtual ~Employer() {} | |
| }; | |
| class President : public Employer { | |
| char* info; | |
| public: | |
| President(const char* s) { | |
| info = new char[strlen(s) + 1]; | |
| strcpy(info, s); | |
| } | |
| void Print() const override { | |
| cout << "President: " << info << endl; | |
| } | |
| ~President() { | |
| delete[] info; | |
| } | |
| }; | |
| class Manager : public Employer { | |
| char* info; | |
| public: | |
| Manager(const char* s) { | |
| info = new char[strlen(s) + 1]; | |
| strcpy(info, s); | |
| } | |
| void Print() const override { | |
| cout << "Manager: " << info << endl; | |
| } | |
| ~Manager() { | |
| delete[] info; | |
| } | |
| }; | |
| class Worker : public Employer { | |
| char* info; | |
| public: | |
| Worker(const char* s) { | |
| info = new char[strlen(s) + 1]; | |
| strcpy(info, s); | |
| } | |
| void Print() const override { | |
| cout << "Worker: " << info << endl; | |
| } | |
| ~Worker() { | |
| delete[] info; | |
| } | |
| }; | |
| int main() { | |
| Employer* arr[3]; | |
| arr[0] = new President("Head of company"); | |
| arr[1] = new Manager("Sales department"); | |
| arr[2] = new Worker("Factory employee"); | |
| for (int i = 0; i < 3; i++) { | |
| arr[i]->Print(); | |
| delete arr[i]; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
рр