216: Develop a C++ program to manage a list of employees. Create a base class "Employee" with attributes like name and salary. Derive a class "Manager" from "Employee" to include additional attributes like department and team size.

 

// Develop a C++ program to manage a list of employees. Create a base class
// "Employee" with attributes like name and salary. Derive a class "Manager"
// from "Employee" to include additional attributes like department and team size.

#include <iostream>
using namespace std;
class Employee
{
private:
    string name;
    int salary;

public:
    Employee(string n = "", int s = 0) { name = n, salary = s; }
    virtual void displayEmp() { cout << "Name: " << name << "\nSalary: " << salary << endl; }
};

class Manager : protected Employee
{
private:
    string department;
    int team_size;

public:
    Manager(string n = "", int s = 0, string d = "", int t = 0) : Employee(n, s)
    {
        department = d, team_size = t;
    }
    void displayEmp() override
    {
        Employee::displayEmp();
        cout << "Department: " << department << "\nTeam size: " << team_size << endl;
    }
};

int main()
{
    Manager m1("Developer", 200000, "Cyber Security", 10);
    m1.displayEmp();
    return 0;
}


Comments

Popular posts from this blog

215: Create a C++ program that uses single inheritance to model a simple shape hierarchy. Implement a base class "Shape" with a virtual function "printArea." Derive classes "Rectangle" and "Triangle" from "Shape" and override the "printArea" function to calculate and display their respective areas.

42: ***(Syntax)*** Calculating number of characters and spaces in a string 1- Make a program to calculate the number of characters in a string 2- Modify this and also tell how many spaces are there in that sentence

96: ***(Syntax)*** Functions and Global Variables