Question: The main objectives for this assignment involve Dynamic Binding (Polymorphism) which means binding of a function call to its definition at run - time (late
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.
Objectives to be met
1
Demonstrate how to enable a class with dynamic binding.
2
Demonstrate how to pass objects as arguments to a function using a polymorphic
reference.
3
Demonstrate how to call a member function that is bound to its definition at run
-
time.
Use the start bup project provided in Canvas to complete this assignment.
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 whatshouldprint 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 t
his 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.
Requirements
1.Use the Employee class and its related classes.
2.Make modifications to class declarations (.h files) where necessary to enable dynamic binding for only those member functions requiring dynamic binding.
3.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.)
4.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
5.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.
6.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.
7. 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 functiona
function that is declared in the base class but defined only in derived classes.
(Review section 15.3 Abstract Base Classes and Pure Virtual Functions, and the PureVitual
program in Other Examples.)
Considerations:
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.Review section 15.2 regarding Polymorphism and Virtual Member Functions and Lab Ex.15.1.Additional Requirements:
Include your name and course (CSC240) at the top of the main program file as a comment. Submit your completed assignment in Blackboard.
Be sure you submit the single compressed (zip) file containing the project folder and all files.
This is what prints now...
Demonstrating Polymorphism
End Program
And this is what should print with just
Requirements #1 #4 Demonstrating Polymorphism
Boss: John Smith
Earnings: $800.00
Commission worker: Sue Jones
Earnings: $857.75
Hourly worker: Karen Price
Earnings: $550.40
End Program
...including
Requirement #5
: using Bob Lewis, 2.52, and 204 with a new PieceWorker...
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
End Program
...including Requirement
#6 Demonstrating PolymorphismBoss: 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
If you know how to do it i can comment the cpp and h files it wont let me add anymore to the lab
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
