Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to design an abstract class called Employee whose members are as given b

ID: 650876 • Letter: Y

Question

You are to design an abstract class called Employee whose members are as given below (make them protected):

Data memebrs:

char *name

long int ID

Two constructors:

A Default constructor // intitialize data memebrs to the default values

and a copy constructor

Methods:

setPerson (char *n, long int id) //allows user to set information for each person

A function called Print () // should be a virtual function, that prints the data attributes of the class.

and a destructor

Also define two classes that derived from class Employee, called Manager and Secretary. Each class should inherit all members from the baseclass and has its own data members and member functions as well.

The Manager should have a data member called degree for his/her undergraduated degree (e.g. diploma, bachelor, master, doctor), the Secretary should have her contract (can be a Boolean value 1/0 for permanent/temporary).

All member functions of derived class should be overrided from their base class.

Write the following main() to test your classes

int main() {

Employee * p = new Manager(

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;

class Employee{
   public:
       string name;
       long int ID;
       Employee(){

       }
       Employee(string n,long int id){
           name = n;
           ID = id;
       }
       ~Employee(void){
       }
       virtual void Print() {};
};

class Manager : public Employee {
   public:
       string degree;
       Manager(string n,long int id,string deg) : Employee(n,id){
           degree = deg;
       }
       void Print(){
           cout << "Name is " << name << endl;
           cout << "ID is " << ID << endl;
           cout << "Degree is " << degree << endl;
       }
};

class Secretary : public Employee {
   public:
       string position;
       Secretary() : Employee(){

       }
       void setPerson(string n,long int id,string deg){
           name = n;
           ID = id;
           position = deg;
       }
       void Print(){
           cout << "Name is " << name << endl;
           cout << "ID is " << ID << endl;
           cout << "position is " << position << endl;
       }
};


int main(){
   Employee *p = new Manager("Bruce Lee", 0234567, "Dr.");
   p->Print();
   Secretary p2;
   p2.setPerson("Wilma Jones", 0341256, "permanent");
   delete p;
   p = & p2;
   p->Print();
   return 0;
}

Yes, polymorphic Behaviour can be observed easily.
C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function.

As you can see, each of the child classes has a separate implementation for the constructor(). This is how polymorphism is generally used. You have different classes with a function of the same name, and different constructor and take form of each other.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote