Skip to content

Instantly share code, notes, and snippets.

@nicolekorch
Created November 26, 2025 17:12
Show Gist options
  • Select an option

  • Save nicolekorch/159b3d08b2e819470984a96433c0bef8 to your computer and use it in GitHub Desktop.

Select an option

Save nicolekorch/159b3d08b2e819470984a96433c0bef8 to your computer and use it in GitHub Desktop.
#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];
}
}
@nicolekorch
Copy link
Author

рр

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment