Question: DO NOT COPY FROM OTHER POSTS TO ANSWER!! Answer as soon as possible please!! MAIN GOAL: Implement a simple inheritance hierarchy between the Person and

DO NOT COPY FROM OTHER POSTS TO ANSWER!!

Answer as soon as possible please!!

MAIN GOAL:

Implement a simple inheritance hierarchy between the Person and Employee class, where both classes include a pointer-based dynamic array. As a result, you are required to include the big-3 in both classes.

Implement a set of virtual functions to realize polymorphism.

Take advantage of polymorphism to manage a dynamic array that consists of both Person objects and Employee projects.

DESCRIPTION:

The two header files below describe the interface of the base class Person and its derived class Empolyee, respectively. Please implement all the functions declared in these two header files in their corresponding .cpp files.

File #1: Header file: Person.h

#ifndef Person_h

#define Person_h

#include

#include

#include using namespace std;

class Person{

public:

//******************Note*********

//This interface is by no means complete. Please feel free to

// add more functions if needed. The test cases however will only

// test the following functions.

virtual ~Person();

Person();

//0->SSN, "na"->name, "personal@"->personalEmail, 10->cntPlaces, allocate space to placesVisited and initializes each place to "unknown" Person& operator=(const Person& rhs );

//copy constructor Person( const Person &clone ); string getPlace(int i) const;

//return the i-th place in the placesVisited array if i is valid; otherwise return "out-of-boundary". virtual string getEmail() const;

//return personalEmail virtual void setEmail( string new_email);

//new_email-->personalEmail virtual string getTypeOfObj() const;

//return "Person" private: int SSN; string name; string personalEmail;

string *placesVisited;

int cntPlaces;

//companion variable of the above pointer };

#endif /* Person_h */

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

File # 2: Header file: Employee.h

#ifndef Employee_h

#define Employee_h

#include "Person.h"

class Employee:public Person

{ private:

string work_email;

double salary;

double *sal_change_rates;

int cnt_sal_changes;

public: virtual ~Employee();

Employee();

//0.0->salary, 10->cnt_sal_changes, "work@"->work_email, sal_change_rates: allocate memory to hold 10 doubles, each of which has an initial value of 0.0

Employee( const Employee& clone);

Employee operator=(const Employee& rhs );

double getChangeRate( int i) const; ////return the i-th rate in the sal_change_rates array if i is valid; otherwise return -1.00

virtual string getEmail() const; //return work_email

virtual void setEmail( string new_email); //new_email-->work_email

virtual string getTypeOfObj() const; //return "Employee"

};

//see below for more details about this function.

void mixedArray( Person** &arrayPersonEmp, int numPersons, int numEmployees); //see below for more details about this function.

void deleteMixedArray(Person** &arrayPersonEmp, int size );

#endif /* Employee_hpp */

Notice that Employee.h contains two stand-alone functions. The first one

void mixedArray( Person** &arrayPersonEmp, int numPersons, int numEmployees); 

The first parameter of this function is an array of Person pointers (i.e., Person *).

This function is going to first allocate an array of (numPersons + numEmployees ) Person pointers.

Next, for each of the first numPersons pointers on this array, say arrayPersonEmp[ i ], this function will create a Person object using the new operator and make it the pointee of arrayPersonEmp[ i ]. Furthermore, it will call Person's setEmail() member function to set each newly created Person object's personalEmail to personal @ qmail.com.

Finally, for each of the next numEmployees pointers on this array, say arrayPersonEmp[ j ], this function will create an Employeeobject using the new operator and make it the pointee of arrayPersonEmp[ j ]. Similarly, it will call Employee's setEmail()member function to set each newly created Employee object's work_email to work @ qmail.com.

For example, if numPersons=12 and numEmployees=10, this function will result in the following:

arrayPersonEmp will be an array of 22 Person pointers

each of the first 12 Person pointers' pointees will be a Person object. Each Person object's personalEmail will bepersonal @ qmail.com

each of the next 10 Person pointers' pointees will be an Employee object. Each Employee object's work_email will bework @ qmail.com.

Good to know: the following statement will make p point to a single Person object:

Person *p = new Person; 

The second standalone function is

void deleteMixedArray(Person** &arrayPersonEmp, int size ); 

This function is going to deallocate the space held by arrayPersonEmp, which is an array of size Person pointers. Each of such Personpointers has a dynamically allocated pointee, which is either a Person object or an Employee one.

Your responsibility in this coding lab is to implement the following three program files:

FILE 3:

Person.cpp: implement all the member functions declared in Person.h

FILE 4:

Employee.cpp: implement all the member functions and the two stand-alone functions declared in Employee.h

FILE 5:

testPersonEmployee.cpp: test your Person and Employee ADTs and the two stand-alone functions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!