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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.