Assignment #8

Problem Statement

This assignment has you play around with inheritance and polymorphism.

What to Do

  1. Define a base class called Employee that contains a name (string), a social security number (string), and the respective accessor functions. It contains a function called print whose task is to output the name and social security number, and an overloaded operator< that orders employees by name. You should not use protected members. Include a two-parameter constructor, using initializer lists, and give all parameters defaults.
  2. Next, derive a class called Hourly that adds a new data member to store an hourly wage (double). Its print function must print the name, social security number, and salary (with phrase "per hour"). It will certainly want to call the base class print. Provide an accessor and mutator for the salary, and make sure that its constructor initializes a salary.
  3. Next, derive another class called Salaried that adds a new data member to store a yearly salary (double). Its print function must print the name, social security number, and salary (with phrase "annual"). Provide an accessor and mutator for the salary, and make sure that its constructor initializes a salary. Exercise the classes by declaring objects of type Salaried and Hourly via constructors and calling their print methods.
  4. Provide a single operator<< that prints an Employee (by calling print). This method will automatically work for anything in the Employee hierarchy.
  5. Make Employee abstract by providing an abstract salary accessor and mutator, and then decide which members should be virtual.
  6. In order to hold all employees, create a class called Roster that is able to hold a variable number of Employee * objects. Roster should have a multiset of Employee * (ordered by name). Part of the multiset template instantiation includes an appropriate function object. Provide the capability to add an employee, and print the entire roster of employees. To add an employee, Roster::add creates a Employee object and calls multiset::insert. Don't worry about error checks. To summarize, Roster has public methods named add and print.
  7. Write a short test program, in which you create a Roster object, call new for both kinds of Employee, sending the result to Roster::add, and output the Roster via a call to print.

What to Submit

Submit your source code for all classes, the final test program and its output.