Question: using c + + Problem One Statement Polymorphism, Virtual Function, Override and Final The context of the problem statement is adopted from the textbook exercises

using c++
Problem One Statement Polymorphism, Virtual Function, Override and Final
The context of the problem statement is adopted from the textbook exercises 11.9 and 12.12 and presented below.
11.9(Package Inheritance Hierarchy) Package-delivery services, such as FedEx, DHL and UPS, offer a number of different shipping options, each with specific costs associated. Create an inheritance hierarchy to represent various types of packages. Use class Package as the base class of the hierarchy, then include classes TwoDayPackage and OvernightPackage that derive from Package.
Base-class Package should include data members representing the name, address, city, state and ZIP code for both the sender and the recipient of the package, in addition to data members that store the weight (in ounces) and cost per ounce to ship the package. Packages constructor should initialize these data members. Ensure that the weight and cost per ounce contain positive values. Package should provide a public member function calculateCost that returns a double indicating the cost associated with shipping the package. Packages calculateCost function should determine the cost by multiplying the weight by the cost per ounce.
Derived-class TwoDayPackage should inherit the functionality of base-class Package, but also include a data member that represents a flat fee that the shipping company charges for two-day-delivery service. TwoDayPackages constructor should receive a value to initialize this data member. TwoDayPackage should redefine member function calculateCost so that it computes the shipping cost by adding the flat fee to the weight-based cost calculated by base-class Packages calculateCost function.
Class OvernightPackage should inherit directly from class Package and contain an additional data member representing an additional fee per ounce charged for overnight-delivery service. OvernightPackage should redefine member function calculateCost so that it adds the additional fee per ounce to the standard cost per ounce before calculating the shipping cost.
Task 1.1 Design and draw the hierarchy of the inheritance of this package system in UML diagrams to represent the specification in the context. Annotate at the member function level and/or class level the virtual, override and final keywords as part of the signatures.
Task 1.2 Develop programs according to the design in Task 1.1 for each class to meet the specification in the context. (Kind reminder : virtual destructor should be applied properly.)
Task 1.3 Program the testDriver.cpp with the main() function to call testStaticBinding() and testDynamicBinding().
(a) Write the unit test function for static binding with objects created for each type of Package and tests member function calculateCost.
void testStaticBinding()
(b) Write the unit test function for polymorphism using dynamic binding. The case should contain an array or a vector of Package pointer to ten objects of classes TwoDayPackage (five objects) and OvernightPackage (five objects). Loop through the vector to process the Packages polymorphically. For each Package, invoke get functions to obtain the address information of the sender and the recipient, then print the two addresses as they would appear on mailing labels. Also, call each Packages calculateCost member function and print the result. Keep track of the total shipping cost for all Packages in the vector, and display this total when the loop terminates.
void testDynamicBinding()
(c) Write the testDriver.cpp file with the main() to invoke test functions of (a) and (b).
Task 1.4 Produce the vtable for each class and observe the virtual function entries of each class declared in the above context. Based on the vtable artifacts, fill in the template for your program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!