Question

In: Computer Science

(Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different...

(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++

Solutions

Expert Solution

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;
}


Related Solutions

use c++ Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number...
use c++ 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,...
Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping options, each...
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...
1. Do FedEx and UPS offer the same delivery services, or has each chosen to focus...
1. Do FedEx and UPS offer the same delivery services, or has each chosen to focus on different forms of delivery and/or customer needs? Explain
The solution has to be written on C++ Visual Studio Thank you (Package Inheritance Hierarchy) Package-delivery...
The solution has to be written on C++ Visual Studio Thank you (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...
A large logistics fleet company such as UPS, DHL or FedEx is trying to figure out...
A large logistics fleet company such as UPS, DHL or FedEx is trying to figure out supply chain costs for a small supply chain facility. You have been asked to step in as a supply chain consultant. The company has identified the following costs.             Number of trucks used per day in the fleet:                           20 trucks (1 driver each)             Cost per delivery driver for each truck per hour:                   $10             Number of hours of delivery per day:                                     10 hours per day             Number of Driving days...
Evaluate the competitive nature within the air delivery and freight services industry (think UPS and FedEx)...
Evaluate the competitive nature within the air delivery and freight services industry (think UPS and FedEx) using Porter’s Five Forces.
Suppose that for a typical FedEx package delivery, the cost of the shipment is a function...
Suppose that for a typical FedEx package delivery, the cost of the shipment is a function of the weight of the package. You find out that the regression equation for this relationship is (cost of delivery) = 0.728*(weight) + 5.49. If a package you want to ship weighs 13.753 ounces and the true cost of the shipment is $12.229, the residual is -3.273. Interpret this residual in terms of the problem. Question 5 options: 1) The weight is 3.273 points...
1.       United Parcel Service (UPS) provides package delivery services throughout the United States and the world. Discuss...
1.       United Parcel Service (UPS) provides package delivery services throughout the United States and the world. Discuss the impact of seasonal variations in the delivery business for forecasting the firm’s financing requirements. 2.       Dell Computer Corporation (DELL) has long been recognized for its innovative approach to managing its working capital. Describe how Dell pioneered the management of net working capital to free up resources in the firm.
UPS and FedEx Case Study Success for a company comes in many different forms. It could...
UPS and FedEx Case Study Success for a company comes in many different forms. It could be the bottom line, expanding market share, or pushing the boundaries of sustainability. Using the FedEx and UPS Documentary case study video and your own research, analyze the effect that either UPS or FedEx has had on the modern economy. When you are finished with your research, list and explain at least two effects that the company has had on the economy. Focusing on...
In the early 2000’s, DHL expanded its worldwide air express package delivery service to the US...
In the early 2000’s, DHL expanded its worldwide air express package delivery service to the US market in direct competition with UPS and FedEx. After several years and more than one billion dollars in losses, DHL admitted defeat in 2008 withdrawing from most US markets while shedding some 15,000 US jobs. Think back to DHL announcement of its intention to enter the US market. Various stakeholders would greet the prospect of increased competition differently. In this discussion forum, address the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT