Program 8 – Employee Class

Make a class Employee with a name and salary. Make a class Manager inherit from Employee. Add an instance variable, named department, of type string. Supply a method to string that prints the manager’s name, department and salary. Make a class Executive inherit from Manager. Supply a method to string that prints the string “Executive” followed by the information stored in the Manager super class object. Supply a test program that tests these classes and methods.

#include<iostream>
using namespace std;

class employee{
    protected:
        float sal;
        char name[50];
};
class manager:public employee{
    protected:
        char dep[30];
    public:
        void getData();
        void display();
};

void manager::getData()
{
    cout<<"Enter name: ";
    gets(name);
    cout<<"Enter department: ";
    gets(dep);
     cout<<"Enter salary: ";
    cin>>sal;
}

void manager::display()
{
    cout<<"Name: "<<name<<endl;
    cout<<"Salary: "<<sal<<endl;
    cout<<"Department"<<dep<<endl;
}

class executive:public manager
{
    public:  
        void display(manager m)
        {
            cout<<"Executive: "<<endl;
            m.display();
        }
};
int main()
{
  
    manager m1;
    m1.getData();
    executive e;
    m1.display();
    e.display(m1);
}

LEAVE A REPLY