Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help me complete the following code using C++ Implement a simple inheritance hierarchy between the Person and Employee classes, where both classes include a

please help me complete the following code using C++

  • Implement a simple inheritance hierarchy between the Person and Employee classes, 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.

person.cpp

// // Person.cpp // InheritancePolymorphism-codingLab // // Created by ... //

#include "Person.h"

namespace NS_PersonEmployee{

//implement each of the member functions included in the Person class

}//end-of namespace NS_PersonEmployee

person.h

// // Created by ... on ... //

#ifndef Person_h #define Person_h

#include #include #include

namespace NS_PersonEmployee{

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 };

}//namespace NS_PersonEmployee

#endif /* Person_h */

main.cpp

// // main.cpp // InheritancePolymorphism-codingLab // // Created by Hui Yang on 5/4/22. //

#include "Person.h" #include "Employee.h" #include "UnitTests.h"

int main(int argc, const char * argv[]) { using namespace NS_PersonEmployee; //call your unit tests and/or directly test your code below return 0; }

Employee.cpp

// // Employee.cpp // InheritancePolymorphism-codingLab // // Created by ... on ... //

#include "Employee.h"

namespace NS_PersonEmployee{

//implement Employee's member functions and the two free-standing functions below

}//end-of namespace NS_PersonEmployee

Employee.h

// // Employee.h // // Created by Hui Yang. //

#ifndef Employee_h #define Employee_h

#include "Person.h"

namespace NS_PersonEmployee{

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" };

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

}//End-of namespace NS_PersonEmployee

#endif /* Employee_h */

UnitTests.h

// // UnitTests.h // InheritancePolymorphism-codingLab // // Created by xyz on dmy. //

#ifndef UnitTests_h #define UnitTests_h

#include "Person.h" #include "Employee.h"

namespace NS_UTESTS{ using namespace NS_PersonEmployee;

//Let's follow the CPP core guidline and implement each unit test as an inline function. //Here's an example: inline bool inline_example(){ //a few lines of code return true; }

//include the following unit tests for Person class.

//bool test_PersonDCon(); //test the default constructor Person //bool test_PersonCCon(); //test the copy constructor of Person //bool test_PersonCAssign(); //test the copy assignment operator of Person

//include the following unit tests for Employee class.

//bool test_EmployeeDCon(); //test the default constructor Employee //bool test_EmployeeCCon(); //test the copy constructor of Employee //bool test_EmployeeCAssign(); //test the copy assignment operator of Employee //bool test_mixedArray(); //test the free-standing function mixedArray()

}//end-of namespace NS_UTESTS

#endif /* UnitTests_h */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Write a program to display red cars with price under 18000.

Answered: 1 week ago