#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

class Employee {
private:
    string name;
    Employee* manager;

public:
    Employee(string n, Employee* m) : name(n), manager(m) {}

    void print_superiors() {
        vector<string> superiors;
        Employee* current = this;
        while (current != nullptr) {
            superiors.push_back(current->name);
            current = current->manager;
        }
        reverse(superiors.begin(), superiors.end());

        cout << "Superiors of " << name << ":";
        for (size_t i = 0; i < superiors.size(); ++i) {
            cout << " " << superiors[i];
            if (i < superiors.size() - 1) {
                cout << " ->";
            }
        }
        cout << endl;
    }
};

int main() {
    Employee ceo("Hannah", nullptr);
    Employee regional("Kyle", &ceo);
    Employee manager1("Hank", &regional);
    Employee employee1("Kara", &manager1);
    Employee manager2("Riley", &regional);
    Employee employee2("Dan", &manager2);
    employee1.print_superiors();
    regional.print_superiors();
    employee2.print_superiors();
    manager1.print_superiors();
    manager2.print_superiors();

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: