title: Create a vector of base class objects and store derived class objects within
body: <p>I am trying to create an employee database (Vector of Employees). There are 3 types of employees ie. employees is the base class and Manager, Engg and Scientist are derived class.
  Every employee has first name and last name. In addition to the name, each of the 3 types of employees have unique stats ie. Manager has number of meetings/week whereas the Engg has work experience and so on.</p>
  
  <p>I have a couple of questions
  1. Should I upcast the derived objects to the base class or downcast the base class to the derived class? 
  2. How do I use polymorphism to override methods, since I want the user to add an employee type and based on the type selected the respective entry fields should appear ie. in case of a Manager, in addition to the first and last names, the program should also ask for meetings/week?</p>
  
  <p>Here is my Class file</p>
  
  <pre><code>class Employee{
  public:
  Employee();
   Employee(string fName, string lName, int sal);
  virtual void printEmp();
  string getFirstName();
  string getLastName();
  
  protected:
  string m_fName;
  string m_lName;
  int m_sal;
  };
  
  
  class Manager : public Employee{
  public:
  Manager();
  Manager(string fName, string lName, int sal, int meets, int hols);
  void printEmp();
  
  
  protected:
  int m_meets;
  int m_hols;
  };
  </code></pre>
  
  <p>Here is the implementation</p>
  
  <pre><code>Employee::Employee(){
  m_fName = "Default";
  m_lName = "Default";
  m_sal = 0;
  }
  
  
  Employee::Employee(string fName, string lName, int sal){
  m_fName = fName;
  m_lName = lName;
  m_sal = sal;
  }
  
  void Employee::printEmp(){
  cout &lt;&lt; "First Name: " &lt;&lt; m_fName &lt;&lt; endl
      &lt;&lt; "Last Name: " &lt;&lt; m_lName &lt;&lt; endl
      &lt;&lt; "Salary: " &lt;&lt; m_sal &lt;&lt; endl;
  }
  
  
  string Employee::getLastName(){
  return m_lName;
  }
  
  string Employee::getFirstName(){
  return m_fName;
  }
  
  Manager::Manager(string fName, string lName, int sal, int meets, int hols) :         Employee(fName, lName, sal), m_meets(meets), m_hols(hols)
  {
  //empty
  }
  
  void Manager::printEmp(){
  Employee::printEmp();
  cout &lt;&lt; "Meets/Week: " &lt;&lt; m_meets &lt;&lt; endl
      &lt;&lt; "Holidays/Year: " &lt;&lt; m_hols &lt;&lt; endl &lt;&lt; endl;
  </code></pre>
  
  <p>Here is the main</p>
  
  <pre><code>int main(){
  
      bool exit = false;
      vector&lt;Employee*&gt; dBVector;
  
      while (!exit){
  
          cout &lt;&lt; "Welcome to Employee Database, Enter an option to continue..." &lt;&lt; endl;
          cout &lt;&lt; "1) Add an Employee, 2) Delete an Employee, 3) Save Database, 4) Exit" &lt;&lt; endl;
          int input;
          cin &gt;&gt; input;
  
          string fNameInp;
          string lNameInp;
          int salInp;
          string lNameSearch;
          int i; // for loop in Delete employee case
          bool deleted = false;
  
          switch (input){
          case 1: //Add
              cout &lt;&lt; "1) Add a Manager, 2) Add an Engg, 3) Add a Researcher" &lt;&lt; endl;
              int empInput;
              cin &gt;&gt; empInput;
  
  
  
              if (empInput == 1){
  
  
                  cout &lt;&lt; "Enter First Name: ";
                  cin &gt;&gt; fNameInp;
  
                  cout &lt;&lt; "Enter Last Name: ";
                  cin &gt;&gt; lNameInp;
  
                  cout &lt;&lt; "Enter Salary: ";
                  cin &gt;&gt; salInp;
  
                  cout &lt;&lt; "Number of meetings/week: ";
                  int meetsInp;
                  cin &gt;&gt; meetsInp;
  
                  cout &lt;&lt; "Number of holidays/year: ";
                  int holsInp;
                  cin &gt;&gt; holsInp;
  
                  Manager mEmp(fNameInp, lNameInp, salInp, meetsInp, holsInp);
                  Employee &amp;emp = mEmp;
                  dBVector.push_back(&amp;mEmp);
                  dBVector[dBVector.size()-1]-&gt;printEmp();
  
              }
  
              else if (empInput == 2){
                  cout &lt;&lt; "Enter First Name: ";
                  cin &gt;&gt; fNameInp;
  
                  cout &lt;&lt; "Enter Last Name: ";
                  cin &gt;&gt; lNameInp;
  
                  cout &lt;&lt; "Enter Salary: ";
                  cin &gt;&gt; salInp;
  
                  cout &lt;&lt; "Cpp Experience (Y/N): ";
                  string cppInp;
                  cin &gt;&gt; cppInp;
  
                  cout &lt;&lt; "Years of experience: ";
                  float expInp;
                  cin &gt;&gt; expInp;
  
                  cout &lt;&lt; "Engg Type (Chem, Mech, IT): ";
                  string typInp;
                  cin &gt;&gt; typInp;
  
                  Engg eEmp(fNameInp, lNameInp, salInp, cppInp, expInp, typInp);
                  Employee &amp;emp = eEmp;
                  dBVector.push_back(&amp;eEmp);
                  dBVector[dBVector.size() - 1]-&gt;printEmp();
  
              }
  
              else if (empInput == 3){
                  cout &lt;&lt; "Enter First Name: ";
                  cin &gt;&gt; fNameInp;
  
                  cout &lt;&lt; "Enter Last Name: ";
                  cin &gt;&gt; lNameInp;
  
                  cout &lt;&lt; "Enter Salary: ";
                  cin &gt;&gt; salInp;
  
                  cout &lt;&lt; "School of PhD: ";
                  string schoolInp;
                  cin &gt;&gt; schoolInp;
  
                  cout &lt;&lt; "Topic of PhD: ";
                  string topImp;
                  cin &gt;&gt; topImp;
  
                  Researcher rEmp(fNameInp, lNameInp, salInp, schoolInp, topImp);
                  Employee &amp;emp = rEmp;
                  dBVector.push_back(&amp;rEmp);
                  dBVector[dBVector.size() - 1]-&gt;printEmp();
  
              }
              break;
  
          case 2: // Delete Emp
              for (int x = 0; x &lt; dBVector.size(); x++){
                  dBVector[x]-&gt;getLastName();
                  cout &lt;&lt; endl;
              }
  
              cout &lt;&lt; "Input Last name of the employee to delete: " &lt;&lt; endl;
              cin &gt;&gt; lNameSearch;
              for (i = 0; i &lt; dBVector.size(); i++){
                  if (dBVector[i]-&gt;getLastName() == lNameSearch){
                      dBVector.erase(dBVector.begin() + i);
                      cout &lt;&lt; dBVector[i]-&gt;getFirstName() &lt;&lt; "has been deleted from database";
                      deleted = true;
                      break;
                  }
              }
              if (deleted == false &amp;&amp; i == dBVector.size()){
                  cout &lt;&lt; "No Employee with Last Name - " &lt;&lt; lNameSearch &lt;&lt; " exists in Database." &lt;&lt; endl;
              }
              else
                  break;
  
          case 3: //save
              cout &lt;&lt; "saving..." &lt;&lt; endl;
              break;
  
          case 4: //exit
              exit = true;
              break;
          }
      }
  }
  Please Help!
  </code></pre>