// F.T. Liu // Example program from comp 1672 // Implementation of Employee class // This class is our first example of a class that dynamically allocates memory #include #include "employee.h" using namespace std; // default constructor Employee::Employee() :myFirstName(0), myLastName(0), myWage(0) { } // constructor for setting values Employee::Employee(const char *firstname, const char *lastname, float wage) :myFirstName(0), myLastName(0), myWage(0) { myFirstName = new char[strlen(firstname)+1]; strcpy(myFirstName, firstname); myLastName = new char[strlen(lastname)+1]; strcpy(myLastName, lastname); if (wage >=0) myWage = wage; } // destructor Employee::~Employee() { if (myFirstName) delete myFirstName; if (myLastName) delete myFirstName; myWage = 0; } // copy constructor Employee::Employee(const Employee ©) // copy constructor { // implement this for homework } // assignment operator const Employee &Employee::operator=(const Employee &rhs) { // implement this for homework } void Employee::display() const { cout << myFirstName << " " << myLastName << ": " << myWage; } // accessor function for the first name const char * Employee::firstname() const { return myFirstName; } // accessor function for the last name const char * Employee::lastname() const { return myLastName; } // accessor function for the wage float Employee::wage() const { return myWage; } // set function for the first name void Employee::firstname(const char *fn) { if (myFirstName) delete myFirstName; myFirstName = new char[strlen(fn)+1]; strcpy(myFirstName, fn); } // set function for the last name void Employee::lastname(const char *ln) { if (myLastName) delete myLastName; myLastName = new char[strlen(ln)+1]; strcpy(myLastName, ln); } // set function for the wage void Employee::wage(float w) { if (w>=0) myWage = w; }