The following code compiles but will not link because the member functions of the two derived classes are missing. I need to implement the missing functions. But I haven't a clue! Any help in the right direction would be appreciated!
Code:
____________________________________________________
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
class Employee //class declaration
{
public:
Employee (void); //constructor
~Employee (void); //destructor
void SetName (const char a_szfirst[], //'mutator'
const char a_szlast[] );
void GetName (char a_szname[], //'accessor'
const int a_buflen );
virtual float GetDollarsPerWeek (void) //'accessor'
{
return 0;
};
private:
char *m_pFirstName; //data members
char *m_pLastName;
};
class HourlyEmployee : public Employee
{
public:
HourlyEmployee (void);
~HourlyEmployee (void);
void SetAvgHoursPerWeek (const int a_hpw);
void SetPayRate (const float a_dph);
float GetDollarsPerWeek (void); //avg 4 weeks per month
private:
int m_AvgHoursPerWeek;
float m_PayRate;
};
class SalaryEmployee : public Employee
{
public:
SalaryEmployee (void);
~SalaryEmployee (void);
enum PayRatePeriod
{
eBiWeekly,
eMonthly
};
void SetPayPeriod (enum PayRatePeriod a_prr);
void SetPayRate (const float a_pr);
float GetDollarsPerWeek (void); //avg 4 weeks per month
private:
enum PayRatePeriod m_PRR;
float m_DollarsPerPeriod;
};
void main (void)
{
const int NAMELEN = 60;
char szname [NAMELEN+2] = {0};
HourlyEmployee oHomer;
oHomer.SetName ("Homer", "Simpson");
oHomer.SetAvgHoursPerWeek (40);
oHomer.SetPayRate (10.0);
oHomer.GetName (szname, NAMELEN); //'access'
printf ("%s averages %.2f per week\n", szname, oHomer.GetDollarsPerWeek () );
SalaryEmployee *pMarge = new SalaryEmployee;
pMarge->SetName ("Marge", "Simpson");
pMarge->SetPayPeriod (SalaryEmployee::eMonthly);
pMarge->SetPayRate (7500.0);
pMarge->GetName (szname, NAMELEN); //'access'
printf ("%s averages %.2f per week\n", szname, pMarge->GetDollarsPerWeek());
}
Employee::Employee (void) constructor implementation
:m_pFirstName(0),
m_PLastName(0);
{
}
Employee::~Employee (void) //destructor implementation
{
if (m_pFirstName !=0)
{
delete [] m_pFirstName, m_pFirstName = 0;
}
if (m_pLastName !=0)
{
delete [] m_pLastName, m_pLastName = 0;
}
}
void Employee::SetName (const char a_szfirst[], //'mutator' implementation
const char a_szlast[] )
{
if (a_szfirst !=0 && a_szfirst[0] !=0)
{
const int buflen=strlen (a_szfirst);
m_pFirstName = new char [buflen+2];
memset (m_pFirstName, 0, (buflen+2));
strcpy (m_pFirstName, a_szfirst);
}
if (a_szlast !=0 && a_szlast [0] !=0)
{
const int buflen = strlen (a_szlast);
m_pLastName = new char [buflen+2];
memset (m_pLastName, 0, (buflen+2));
strcpy (m_pLastName, a_szlast);
}
}
void Employee::GetName (char a_szname[], //'accessor' implementation
const int a_buflen)
{
if (0==m_pFirstName || 0==m_pLastName)
return;
int namelen = strlen(m_pFirstName) + 1 + strlen(m_pLastName);
if (namelen > a_buflen)
return;
sprintf (a_szname, "%s %s", m_pFirstName, m_pLastName);
}
____________________________________________________