Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

do the HourlyWorker constructors using member initialization list class Employee

ID: 3602611 • Letter: D

Question

do the HourlyWorker constructors using member initialization list

class Employee

{

public:

   Employee( const char*, const char* );

   ˜Employee();

      void print() const;

protected:

   char* fname; char* lname;

};

Employee::Employee( const char* pF, const char* pL )

{

fname = new char[ strlen( pF ) + 1 ];

strcpy( fname, pF );

lname = new char[ strlen( pL ) + 1 ];

strcpy( lname, pL );

}

Employee::˜Employee()

{

delete lname;

delete fname;

}

void Employee::print() const

{

cout << fname << ’ ’ << lname;

}

class HourlyWorker : public Employee

{

public:

          HourlyWorker(const char*, const char*, double, double);

    double getPay() const;

    void print() const;

private:

    double wage; double hours;

};

Explanation / Answer

Answer:

#include <iostream>
#include <cstring>
using namespace std;
class Employee
{
public:
Employee( const char*, const char* );
~Employee();
void print() const;

protected:
char* fname; char* lname;
};

Employee::Employee( const char* pF, const char* pL )
{
fname = new char[ strlen( pF ) + 1 ];
strcpy( fname, pF );
lname = new char[ strlen( pL ) + 1 ];
strcpy( lname, pL );
}
Employee::~Employee()
{
delete lname;
delete fname;
}

void Employee::print() const
{
cout << fname << " " << lname;

}
class HourlyWorker : public Employee
{
public:
HourlyWorker(const char*, const char*, double, double);
double getPay() const;
void print() const;

private:
double wage; double hours;

};
HourlyWorker::HourlyWorker( const char* pF, const char* pL, double w, double h ) : Employee(pF, pL),wage(w), hours(h) {

}

int main()
{
   
return 0;
}