178k views
2 votes
Can someone help me with part 2?

I already have the part one but I am not sure how to begin with part 2
Part 1 – 45%
Consider using the following Card class as a base class to implement a hierarchy of related
classes:
class Card
{
string name;
public:
Card(){name = "";};
Card(string n){ name = n;};
virtual bool is_expired() const;
virtual void print() const;
};
bool Card::is_expired() const
{ return false;
}
1. Implement definitions for each of the derived classes. For each derived class, supply
private data members and the declarations (but not the definitions) of the constructors and
the print function.
2. Implement constructors for each of the three derived classes. Each constructor needs to
call the base class constructor to set the name.
3. Write a main program that tests the constructors, is_expired(), and print functions in the
derived classes. In the print function, print the name of object class and other data
members based on the object class.
Part 2 – 35%
Given the following base class Employee
#include
class Employee {
protected:
double payRate;
std::string name;
public:
Employee(std::string empName, double empRate);
double pay() const;
void print() const;
};
Employee::Employee(std::string empName, double empRate)
: name(empName), payRate(empRate) {
// nothing else to do
}
double Employee::pay() {
return payRate;
}
void Employee::print() const {
std::cout << "Name: " << name << std::endl;
std::cout << "Pay rate: " << payRate << std::endl;
}
1. Derive a new class Hourly from Employee, where Hourly meets the following criteria:
- Its constructor takes the same arguments as its parent, calls its parent's constructor,
and sets an additional private variable representing the number of hours worked to 0.
- It implements a new method addHours which lets the user increase the number of
hours this employee has worked so far.
2. Derive another new class Executive from Employee, where Executive meets the
following criteria:
- Its constructor takes the same arguments as its parent, calls its parent's constructor,
and sets an additional private variable representing the amount of bonus pay to 0.
- It implements a new method awardBonus which lets the user set the bonus pay for this
employee.
3. Write a short main program that tests the new implemented functions in part Part2.1 and
Part2.2.
(Note) Be sure to use the #ifndef/#define/#endif technique in each of your header files to
avoid multiple inclusion of header files.

User Kdu
by
8.2k points

1 Answer

5 votes

Final answer:

To implement derived classes Hourly and Executive from the Employee base class, follow the steps described.

Step-by-step explanation:

Part 2 - Deriving Hourly and Executive classes from Employee

In order to implement the derived classes Hourly and Executive from the base class Employee, follow these steps:

  1. For the Hourly class:
  • Define a new class Hourly that is derived from the Employee class.
  • In the constructor of the Hourly class, call the base class constructor and initialize the additional private member representing the number of hours worked to 0.
  • Implement a new method addHours in the Hourly class that allows the user to increase the number of hours the employee has worked.
For the Executive class:
  • Define a new class Executive that is derived from the Employee class.
  • In the constructor of the Executive class, call the base class constructor and initialize the additional private member representing the amount of bonus pay to 0.
  • Implement a new method awardBonus in the Executive class that allows the user to set the bonus pay for this employee.
Write a short main program that tests the new implemented functions in part 2.1 and 2.2.
User Woolyninja
by
8.1k points

No related questions found