Project Two

UML Diagram

"Insert Photo"

Database (Database.h)

#ifndef DATABASE_H
#define DATABASE_H

#include "Employee.h"
#include "Manager.h"
#include <string>

using std::string;

class Database {

    protected:

        vector<Employee*> database;
    
    public:

        Database() = default;

        Database(vector<Employee*> g){
            database = g;
        }

        void AddRecord(Employee *newAdd){
            // add to vector
            database.push_back(newAdd);
        }

        void DisplayRecord(){
            //printing out records

            for (int i = 0; i < database.size(); i++ ){
                database[i]->DisplayEmployee();
            }
        }
};
#endif /* DATABASE_H */

Employee Header File (Employee.h)

#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <cstdlib>
#include <string>
#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;
using std::string;

class Employee {

    protected:
        string first_name;
        string last_name;
        tm hire_year;
        int salary;

    public:
        Employee(){
            // Defualt Constructor
            first_name = "Devin";
            last_name  = "Powers";
            hire_year.tm_year = 2016;
            salary = 20;
        }
        Employee(string first, string last, int sal, tm hyear){
            first_name = first;
            last_name = last;
            salary = sal;
            hire_year.tm_year = hyear.tm_year;
        }

        Employee(Employee& other){

            // Copy Constructor
            first_name = other.first_name;
            last_name = other.last_name;
            salary = other.salary;
            hire_year = other.hire_year;
        }

        Employee& operator=(Employee& other){
            // Overloaded Operator 
            if (this != &other){
                this->first_name = other.first_name;
                this->last_name = other.last_name;
                this->salary = other.salary;
                this->hire_year = other.hire_year;
        }
        return *this;
        }


        string GetFirstName()const{
            return first_name;
        }

        void SetFirstName(string first){
            first_name = first;
        }
        
        string GetLastName()const{
            return last_name;
        }

        void SetLastName(string last){
            last_name = last;
        }


        tm GetHireYear()const{return hire_year;}

        void set_hire_year(int year){hire_year.tm_year = year;}
        void set_hire_year(tm year){hire_year = year;}

        int getSalary()const{return salary;}
        void setSalary(int s){salary = s;}


        virtual void DisplayEmployee()const{
        cout << first_name << " " << last_name << "\tSalary: " << salary
                << "\t Hiring Year: " << hire_year.tm_year << endl;
    }


};
#endif

Employee Header File (Employee.h)


#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <cstdlib>
#include <string>
#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;
using std::string;

class Employee {

    protected:
        string first_name;
        string last_name;
        tm hire_year;
        int salary;

    public:
        Employee(){
            // Defualt Constructor
            first_name = "Devin";
            last_name  = "Powers";
            hire_year.tm_year = 2016;
            salary = 20;
        }
        Employee(string first, string last, int sal, tm hyear){
            first_name = first;
            last_name = last;
            salary = sal;
            hire_year.tm_year = hyear.tm_year;
        }

        Employee(Employee& other){

            // Copy Constructor
            first_name = other.first_name;
            last_name = other.last_name;
            salary = other.salary;
            hire_year = other.hire_year;
        }

        Employee& operator=(Employee& other){
            // Overloaded Operator 
            if (this != &other){
                this->first_name = other.first_name;
                this->last_name = other.last_name;
                this->salary = other.salary;
                this->hire_year = other.hire_year;
        }
        return *this;
        }


        string GetFirstName()const{
            return first_name;
        }

        void SetFirstName(string first){
            first_name = first;
        }
        
        string GetLastName()const{
            return last_name;
        }

        void SetLastName(string last){
            last_name = last;
        }


        tm GetHireYear()const{return hire_year;}

        void set_hire_year(int year){hire_year.tm_year = year;}
        void set_hire_year(tm year){hire_year = year;}

        int getSalary()const{return salary;}
        void setSalary(int s){salary = s;}



    virtual void DisplayEmployee()const{
        cout << first_name << " " << last_name << "\tSalary: " << salary
                << "\t Hiring Year: " << hire_year.tm_year << endl;
    }


};
#endif

Manager File (Manager.h)

#ifndef MANAGER_H
#define MANAGER_H

#include <cstdlib>
#include <vector>
#include <iostream>
#include "Employee.h"

using std::vector;
using namespace std;

class Manager: public Employee {

    protected:

        vector<Employee*> group;
        string department;

    public:
        Manager(){
            // Default Constructor

            first_name = "Devin";
            last_name = "Powers";
            hire_year.tm_year = 2012;
            salary = 32;
            group  = vector<Employee*>();
            department = "CSE";
        }
        Manager(string first, string last, int sal, tm hyear, string dept, vector<Employee*> &g) :Employee(first, last, sal, hyear){
            // Constructor

            first_name = first;
            last_name = last;
            hire_year.tm_year = hyear.tm_year;
            salary = sal;
            department = dept;
            group = g;
            
        }

        Manager(Manager &other){
            first_name = other.first_name;
            last_name = other.last_name;
            salary = other.salary;
            hire_year = other.hire_year;
            department = other.department;
            group = other.group;

        }

        Manager& operator=(Manager &other){

            if (this != &other){
                this->first_name = other.first_name;
                this->last_name = other.last_name;
                this->salary = other.salary;
                this->hire_year = other.hire_year;
                this->department = other.department;
                this->group = other.group;
            }
            return *this; /// pointer to t
        }

        virtual ~Manager(){
            for (int i = 0; i < group.size(); i++ ){
                delete (group[i]);
            }
            group.clear();
        }

        string GetDepartment()const{return department;}
        void SetDepartment(string d){department = d;}

        vector<Employee*> GetGroup()const{return group;}
        void SetGroup(vector<Employee*> &g) {group = g;}

        virtual void DisplayEmployee()const{
            cout << first_name << " " << last_name << "\tSalary: " << salary 
                << "\tHire Year: " << hire_year.tm_year << "\t"
                << department << "Subordinates: " << group.size() << endl;
            
            for (int i = 0; i <group.size(); i++ ){
                cout << "\t Subordinate: ";
                group[i]->DisplayEmployee();
            }
        }
        

};
#endif

Main File (main.cpp)

#include <cstdlib>
#include <iostream>
#include "Employee.h"
#include "Manager.h"
#include "Database.h"

using std::cout;
using std::endl;

int main() {

    cout << endl;

    tm hiring_year; 
    hiring_year.tm_year = 2012;

    vector<Employee*> emps;

    Manager mang("Devin", "Powers", 20, hiring_year, "CSE", emps); 

    mang.DisplayEmployee();
    cout << "Defualt Constructor Check!!!\n";


    // Check Copy Constructors
    Manager manager_one = mang;  // Copy
    manager_one.DisplayEmployee();
    cout << "Copy Constructor Check " << endl;

    // Check Assignment Operator

    hiring_year.tm_year = 2015;
    Manager mang3("SubB_First","SubB_Second",10,hiring_year,"CSE",emps);
    mang3.DisplayEmployee();
    manager_one = mang3;
    manager_one.DisplayEmployee();
    mang3.DisplayEmployee();
    cout<<"Assignment Operator Check\n\n";
    

    //Add subordinates
    emps.push_back(&mang);
    emps.push_back(&manager_one);

        //Add records to database
    vector<Employee*> allEmp;
    Database emp_data(allEmp);

    hiring_year.tm_year=1998;
    emp_data.AddRecord(new Manager("Michael","Scott",30,hiring_year,"CSE",emps));
    hiring_year.tm_year=1999;
    emp_data.AddRecord(new Manager("Bruce","Lee",32,hiring_year,"CSE",emps));
    hiring_year.tm_year=2000;
    emp_data.AddRecord(new Manager("Tom","Brady",35,hiring_year,"EGR",emps));
    hiring_year.tm_year=2001;
    emp_data.AddRecord(new Manager("Dak","Prescott",40,hiring_year,"CHE",emps));
    hiring_year.tm_year=2002;
    emp_data.AddRecord(new Manager("Mike","Evans",50,hiring_year,"EGR",emps));


    
    //display all records
    emp_data.DisplayRecord();

}

Output:

Devin Powers    Salary: 20      Hire Year: 2012 CSESubordinates: 0
Defualt Constructor Check!!!
Devin Powers    Salary: 20      Hire Year: 2012 CSESubordinates: 0
Copy Constructor Check 
SubB_First SubB_Second  Salary: 10      Hire Year: 2015 CSESubordinates: 0
SubB_First SubB_Second  Salary: 10      Hire Year: 2015 CSESubordinates: 0
SubB_First SubB_Second  Salary: 10      Hire Year: 2015 CSESubordinates: 0
Assignment Operator Check

Michael Scott   Salary: 30      Hire Year: 1998 CSESubordinates: 2
         Subordinate: Devin Powers      Salary: 20      Hire Year: 2012 CSESubordinates: 0
         Subordinate: SubB_First SubB_Second    Salary: 10      Hire Year: 2015 CSESubordinates: 0
Bruce Lee       Salary: 32      Hire Year: 1999 CSESubordinates: 2
         Subordinate: Devin Powers      Salary: 20      Hire Year: 2012 CSESubordinates: 0
         Subordinate: SubB_First SubB_Second    Salary: 10      Hire Year: 2015 CSESubordinates: 0
Tom Brady       Salary: 35      Hire Year: 2000 EGRSubordinates: 2
         Subordinate: Devin Powers      Salary: 20      Hire Year: 2012 CSESubordinates: 0
         Subordinate: SubB_First SubB_Second    Salary: 10      Hire Year: 2015 CSESubordinates: 0
Dak Prescott    Salary: 40      Hire Year: 2001 CHESubordinates: 2
         Subordinate: Devin Powers      Salary: 20      Hire Year: 2012 CSESubordinates: 0
         Subordinate: SubB_First SubB_Second    Salary: 10      Hire Year: 2015 CSESubordinates: 0
Mike Evans      Salary: 50      Hire Year: 2002 EGRSubordinates: 2
         Subordinate: Devin Powers      Salary: 20      Hire Year: 2012 CSESubordinates: 0
         Subordinate: SubB_First SubB_Second    Salary: 10      Hire Year: 2015 CSESubordinates: 0