#include <iostream>
#include <string>

class Employee {
protected:
    std::string name;
    int age;
    double salary;

public:
    void enterDetails() {
        std::cout << "Enter employee name: ";
        std::getline(std::cin, name);

        std::cout << "Enter employee age: ";
        std::cin >> age;

        std::cout << "Enter employee salary: $";
        std::cin >> salary;

        // Clear the input buffer
        std::cin.ignore();
    }

    void displayDetails() const {
        std::cout << "Name: " << name << ", Age: " << age << ", Salary: $" << salary << std::endl;
    }
};

class EmployeeList : public Employee {
private:
    static const int numEmployees = 5;

public:
    void enterDetailsForAll() {
        for (int i = 0; i < numEmployees; ++i) {
            std::cout << "\nEnter details for Employee " << i + 1 << ":\n";
            enterDetails();
        }
    }

    void displayDetailsForAll() const {
        std::cout << "\nEmployee Details:\n";
        for (int i = 0; i < numEmployees; ++i) {
            std::cout << "Employee " << i + 1 << ": ";
            displayDetails();
        }
    }
};

int main() {
    EmployeeList employeeList;

    std::cout << "Enter details for 5 employees:\n";
    employeeList.enterDetailsForAll();

    std::cout << "\nDisplaying details for all employees:\n";
    employeeList.displayDetailsForAll();

    return 0;
}

Embed on website

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