Monday, 25 December 2017
Case Study: Package Inheritance Hierarchy
Package-delivery services, such as OCS®, TCS® and JCS®, offer a number of different shipping options, each with specific costs
associated.
Create an inheritance hierarchy to represent various types of packages. Use Package as the base class of the hierarchy, and then
include classes TwoDayPackage and OvernightPackage that derive from Package.
1. ADT: Package
1. The class should have following private data members
1. Two strings to represent the name of the sender and receiver.
2. Two strings to hold the address of the sender and receiver.
3. Two strings to contain the city of the sender and receiver.
4. A float named weight to store the weight of the package in ounce.
5. A float named costPerOunce to store the cost per ounce of the package.
2. A constructor which accepts the names, addresses, cities of the sender and receiver and the weight and its cost per ounce
as arguments and assigns them to the appropriate member variables. Ensure that the weight and cost per ounce contain
positive values.
3. calculateCost member function that returns the cost associated with shipping the package, i.e. weight * costPerOunce.
2. ADT: TwoDayPackage
1. The class should have private data member of type float named flatFee to represent the company charges for two-daydelivery
service.
2. A constructor which accepts all the required information for the two-day-delivery package including the flatFee as
arguments and assigns them to the appropriate member variables. Ensure that the flatFee contains positive value.
3. calculateCost member function that computes and return the shipping cost by adding the flat fee to the weight-based
cost calculated by base class Package's calculateCost function.
3. ADT: OvernightPackage
1. The class should have private data member of type float named feePerOunce to represent the additional cost charged for
overnight-delivery service.
2. A constructor which accepts all the required information for the overnight package including the additional fee per ounce
as arguments and assigns them to the appropriate member variables. Ensure that the fee per ounce contains positive
value.
3. calculateCost member function that adds the additional fee per ounce to the standard cost per ounce before calculating
the shipping cost and then computes and return the shipping cost.
4. Main Function
Once you have written your classes, write main function and test the functionality of each of the classes thoroughly by creating
their objects.
Code link.....
https://www.dropbox.com/s/uibbqxwz8kam2g7/Package_Inheritance.cpp?dl=0
Subscribe to:
Post Comments (Atom)
ADT: RationalNumber
Define a class for rational numbers. A rational number is “ratio-nal” number, composed of two integers with division indicated. The division...
-
Design a class called NumDays. The class’s purpose is to store a value that represents a number of work hours and convert it to a number of ...
-
Define a class for rational numbers. A rational number is “ratio-nal” number, composed of two integers with division indicated. The division...
-
LCM is most early technique that is taught in school. it helps us in Calculation of Fractions. here I have written code for finding LCM of ...
No comments:
Post a Comment