The main objectives for this assignment involve Dynamic Binding (Polymorphism) which means binding of a function call to its definition at run-time (late binding). You will use classes related through inheritance that are already provided to demonstrate these objectives

  • Demonstrate how to enable a class with dynamic binding.
  • Demonstrate how to pass objects as arguments to a function using a polymorphic reference.
  • Demonstrate how to call a member function that is bound to its definition at run-time.

The classes and main program provided are ready to compile and run without errors or warnings, but the desired output is not quite correct yet. (See what prints now and what should print at the end of these instructions). You will need to decide which of the existing class member functions require dynamic (late) binding and how to enable this polymorphic feature. No new member functions are necessary, and no modifications to any class implementations (in those class .cpp files) are necessary. In the main program source code listing, you also will need to write another program function called printResult(); this function should be declared and defined where indicated by the TO-DO comments. It will be necessary to call this function from inside main() in order to demonstrate the objectives and for getting the desired output. The function should be called repeatedly, once for each object passed as an argument, and it will be defined so that it prints the information shown for that object.

  • Use the Employee class and its related classes.
  • Make modifications to class declarations (.h files) where necessary to enable dynamic binding for only those member functions requiring dynamic binding.
  • Declare and define the printResult() program function using a parameter type that will accept any of the related objects as actual arguments. (Call this function repeatedly passing each object defined inside main, one-by-one, as an argument.)
  • IMPORTANT: Write a comment before (or next to) every statement that you believe demonstrates dynamic (late) binding of a function call to its definition. For example: // this is dynamic binding
  • Compile and run the program to make sure it is working before making any changes. Verify that the program output matches that which is shown below under This is what prints now...
  • Study the class specifications (declarations in .h file) and implementations (function definitions in .cpp files) so that you completely understand what they do. Note however that not all member functions need to be called in the main program in order to meet the assignment objectives, requirements, or other recommendations and only are included for completeness.
  • Add another derived class called PieceWorker. This type of employee has earnings based on the quantity of pieces produced and the wage per piece (quantity * wagePerPiece). Your class should declare private data members for these two values and one constructor for defining an object with the first and last name, and the quantity and wage per piece. The design of your class should be consistent with the other derived classes. In the main program, define another variable using this class, and include its output in the results.
  • In the main program, declare a local variable for array of pointers using Employee as the data type, and make the array size 10. Assign the addresses of the existing objects to the first few array elements making this a partially-filled array. Write a new function in the main program file that will accept the array of pointers and the count of how many array elements to process. This new function, getTotalEarnings(), should add up the earnings for the employees using a loop and then return the sum back to the main function. The main program should then calculate the average earnings and print the total earnings and average earnings.
  • Since the main program is designed to use only objects of derived classes, you should be able to make Employee an abstract class; revise the Employee.h and Employee.cpp files so that one of its existing virtual functions is declared a pure virtual function a function that is declared in the base class but defined only in derived classes.
This is what prints now...
- Demonstrating Polymorphism -
- End Program –

What to do..

- Demonstrating Polymorphism -
Boss: John Smith
Earnings: $800.00
Commission worker: Sue Jones
Earnings: $857.75
Hourly worker: Karen Price
Earnings: $550.40
Piece worker: Bob Lewis
Earnings: $514.08
Total Earnings: 2722.23
Average Earnings: 680.56
- End Program -
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.