In: Computer Science
(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. Package’s 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. Package’s 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. TwoDayPackage’s 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 Package’s 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. Write a test program that creates objects of each type of Package and tests member function calculateCost.
please send a link to a repl.it file to help find the solution or separate the files with names so I can know different header files to use
use c++
Header File
-> Package.h
#pragma once
#include <string>
using namespace std;
struct PersonInfo
{
PersonInfo()
{
name = "";
address ="";
city = "";
state = "";
zip = "";
}
string name;
string address;
string city;
string state;
string zip;
};
class Package
{
public:
Package();
Package(PersonInfo send, PersonInfo recv, double wt,
double rate);
virtual double CalculateCost();
protected:
PersonInfo sender;
PersonInfo receiver;
double weight;
double rate;
};
class TwoDayPackage : public Package
{
public:
TwoDayPackage(PersonInfo send, PersonInfo recv, double
wt, double rate, double fees);
virtual double CalculateCost();
private:
double fee;
};
class OvernightPackage : public Package
{
public:
OvernightPackage(PersonInfo send, PersonInfo recv,
double wt, double rate, double excost);
virtual double CalculateCost();
private:
double extracost;
};
Package.cpp
#include <iostream>
#include "Package.h"
Package::Package()
:weight(0.0), rate(0.0)
{
}
Package::Package(PersonInfo send, PersonInfo recv, double wt,
double rt)
: weight(wt), rate(rt), sender(send),
receiver(recv)
{
}
double Package::CalculateCost()
{
double cost = abs(weight) * abs(rate);
return cost;
}
TwoDayPackage::TwoDayPackage(PersonInfo send, PersonInfo recv,
double wt, double rt, double fees)
:Package(send, recv, wt, rt), fee(fees)
{
}
double TwoDayPackage::CalculateCost()
{
double cost = Package::CalculateCost();
return (cost + fee);
}
OvernightPackage::OvernightPackage(PersonInfo send, PersonInfo
recv, double wt, double rt, double excost)
:Package(send, recv, wt, rt), extracost(excost)
{
}
double OvernightPackage::CalculateCost()
{
double cost = Package::CalculateCost();
double extra = abs(weight) * abs(extracost);
return (cost + extra);
}
Main.cpp
#include <iostream>
#include "Package.h"
using namespace std;
int main()
{
PersonInfo sender;
PersonInfo receiver;
sender.name = "aaa";
sender.address = "India";
sender.city = "delhi";
sender.state = "Delhi";
sender.zip = "110032";
receiver.name = "bbb";
receiver.address = "India";
receiver.city = "delhi";
receiver.state = "Delhi";
receiver.zip = "110032";
TwoDayPackage twodayPack(sender, receiver, 22.3, 44.3,
20);
OvernightPackage overnightPack(sender, receiver, 22.3, 44.3, 2);
double twodaycost =
twodayPack.CalculateCost();
double overnightcost =
overnightPack.CalculateCost();
std::cin.get();
return 0;
}