Instructions:
... Write one or more constructors and the appropriate accessor and mutator functions for the class. Write one or more constructors and the appropriate accessor and mutator functions for the class. Demonstrate the classes by writing a program that uses a ProductionWorker object.
Unfortunately the base constructor with the derived class in line 56, is causing an error.
Line 85 refuses to pass the name John Doe.
I also tried the following combination for the int main, and it said it couldn't find payment in the Employee class. It looks like it can distinguish between emp1 for Employee and ProdWorker
Employee emp1("John Doe", 2);
ProductionWorker emp1(2, 37); //shift type, work hours
// Print out name and pay (based on 40 hours work).
cout << "Name: " << emp1.getName() << endl;
cout << "Pay: " << emp1.payment(40.0) << endl;
The full code
#include <iostream>
#include <string>
using namespace std;
class Employee
{
protected:
string name;
int number;
int date;
public:
Employee()
{ name = " ";
number = 0;
date = 0; }
//Employee(string na, int nu, int d)
//{ //name = na;
//number = nu;
//date = d;
//set(name, number, date); }
//mutators
void setName(string na)
{ name = na; }
void setNum(int nu)
{ number = nu; }
void setDate(int d)
{ date = d; }
string getName() const
{ return name; }
int geNumber() const
{ return number; }
int getDate() const
{ return date; }
};
class ProductionWorker : public Employee
{
private:
int shift;
double rate;
public:
ProductionWorker() : Employee()
{ shift = 1;
rate = 0.0; }
ProductionWorker(int s, double r) : Employee(na, nu, d)
{ shift = s;
rate = r; }
void setShift(int s)
{ shift = s; }
void setRate(int r)
{ rate = r; }
string getShift(int s) const
{ string shiftType;
if (shift == 1)
shiftType = "Day";
if (shift == 2)
shiftType = "Night";
return shiftType; }
double getRate() const
{ return rate; }
double payment(double h) const //h = hoursworked
{ return h * rate; }
};
int main()
{
Employee emp1("John Doe", 2);
ProductionWorker pw1(2, 37); //shift type, work hours
// Print out name and pay (based on 40 hours work).
cout << "Name: " << emp1.getName() << endl;
cout << "Pay: " << pw1.payment(40.0) << endl;
}

New Topic/Question
Reply



MultiQuote





|