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.
1. Header file: Person.h
#ifndef Person_h
#define Person_h
#include <iostream>
#include <string>
#include <new>
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 */
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 Personobject 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@gmail.com.
- Finally, for each of the next numEmployees pointers on this array, say arrayPersonEmp[ j ], this function will create an Employee object 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@gmail.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 be personal@gmail.com
- each of the next 10 Person pointers’ pointees will be an Employee Each Employee object’s work_email will be work@gmail.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:
- cpp: implement all the member functions declared in Person.h
- cpp: implement all the member functions and the two stand-alone functions declared in Employee.h
- cpp: test your Person and Employee ADTs and the two stand-alone functions.