Question

In: Computer Science

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, 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

cpp code:

package.h

#ifndef PACKAGE_H_INCLUDED
#define PACKAGE_H_INCLUDED

using namespace std;

//package class
class Package
{
//sender
string sen_name;
string sen_address;
string sen_city;
string sen_state;
string sen_ZIP;

//recipient
string rec_name;
string rec_address;
string rec_city;
string rec_state;
string rec_ZIP;

double weight;
double cost;

public:
  
Package();
//constructor with parameter
Package(string,string,string,string,string,string,string,string,string,string,double,double);
//calculate cost
double calculateCost ();

};

//two day package class inherits base class
class TwoDayPackage : public Package
{
double flatFee; //fee

public:
//constructor
TwoDayPackage(string,string,string,string,string,string,string,string,string,string,double,double,double);
double calculateCost (); //compute cost


};

//two day package class inherits base class

class OvernightPackage : public Package
{
double additionalFee; //fee

public:
//constructor
OvernightPackage(string,string,string,string,string,string,string,string,string,string,double,double,double);
double calculateCost (); //compute cost

};
#endif // PACKAGE_H_INCLUDED

package.cpp

#include <iostream>
#include "package.h"

using namespace std;

//set varibles
Package::Package(string n1,string a1,string c1,string s1,string z1,string n2,
string a2,string c2,string s2,string z2,double w,double c)
{
//sender
this->sen_name=n1;
this->sen_address=a1;
this->sen_city=c1;
this->sen_state=s1;
this->sen_ZIP=z1;

//recipient
this->rec_name=n2;
this->rec_address=a2;
this->rec_city=c2;
this->rec_state=s2;
this->rec_ZIP=z2;

//set weight
this->weight=w;
this->cost=c; //set cost
}

//compute and return cost
double Package::calculateCost()
{
return weight*cost;
}

//derived class, set base class values
TwoDayPackage::TwoDayPackage(string n1,string a1,string c1,string s1,string z1,string n2,
string a2,string c2,string s2,string z2,double w,double c,double f):Package(n1,a1,c1,s1,z1,n2,a2,c2,s2,z2,w,c)
{

this->flatFee=f;//set flat fee
}

//return cost with flat fee
double TwoDayPackage::calculateCost()
{
return Package::calculateCost()+flatFee;
}

//derived class, set base class values
OvernightPackage::OvernightPackage(string n1,string a1,string c1,string s1,string z1,string n2,
string a2,string c2,string s2,string z2,double w,double c,double f):Package(n1,a1,c1,s1,z1,n2,a2,c2,s2,z2,w,c)
{
this->additionalFee=f;//set additional fee
}

//return cost with additional fee
double OvernightPackage::calculateCost()
{
return Package::calculateCost()+additionalFee;
}

main.cpp

#include <iostream>
#include <string>
#include "package.h"

using namespace std;


int main()
{
//set twoday package class
TwoDayPackage p1("smith","2ndCross","Hudson","NY","1234","Angel","3rdCross","","NY","2342",5,230.5,50);

//set overnigth package class
OvernightPackage p2("smith","2ndCross","Jamaica","NY","1234","Angel","3rdCross","","NY","2342",4,300,100);

//call function
cout << "TwoDayPackage cost: "<<p1.calculateCost() << endl;
cout << "OvernightPackage cost: "<<p2.calculateCost() << endl;
return 0;
}

output:

//for any clarification please do comments. if you found this solution useful, please give me thumbs up


Related Solutions

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.
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...
c++ using polymorphyism , create an inheritance hierarchy for the following types of insurance : Home,...
c++ using polymorphyism , create an inheritance hierarchy for the following types of insurance : Home, vehicle , life 2 member functions should be included: - calcpremium    - Home- 0.5% of the value of the home    - Life- 1% of the value of the policy    - Vehicle - 0.5% of the value of the policy calcCommission Home- 0.2% of the value of the home Life- 1% of the value of the policy Vehicle - 0.5% of the...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the opportunity to overload or override an inherited member function. What is the difference? and which one is the better?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT