Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Help. Inheritence Problem. Hi, I have this c++ programming problem I need he

ID: 3858531 • Letter: C

Question

C++ Help. Inheritence Problem.

Hi, I have this c++ programming problem I need help with.

the prompt is:

"Package-delivery services such as FedEx, UPS, and DHL 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,then include classes TwoDayPackage and OvernightPackage that derive from Package. Base class Package should include data members representing name, address, 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. TwoDayPackages's constructor should receive a value to initialize this data member. TwoDayPackage should redefine member function calculate-Cost so that it computes the shipping cost by adding the flat fee to the weight-based cost calculated by base class Package's calculate Cost function. Derived 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 theshipping cost. Write a test program that creates objects of each type of Package and tests member function calculateCost."

I have the program written, but it doesn't compile. I am trying to only use cpp files and not header(.h) files, I know using header files would be easier but I am trying to put it all on cpp files.

External link below:

https://www.dropbox.com/sh/v2tdg48n580bue1/AADQ8_Qg6HzBG1NRWMPMaI2Wa?dl=0

This is the dropbox link to my file.

The file is 123Test. Ignore the other ones. For some reason the "<<" operands towards the end of the file cause an error and Im not sure why.

Explanation / Answer

Answer: /* C++ Package Inheritance Hierarchy program. (Package Inheritance Hierarchy) Package-deliveryservices, 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 calculate-Cost 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. Write a test program that creates objects of each type of Package and tests member function calculateCost. */ #include #include #include using namespace std; class Package { private: string sender_name; string sender_address; string sender_city; string sender_state; string sender_ZIP; string recipient_name; string recipient_address; string recipient_city; string recipient_state; string recipient_ZIP; double weight; double costperounce; public: //set functions for all data Package(string sender_n, string sender_addr, string sender_c, string sender_s, string sender_Z, string recipient_n, string recipient_addr, string recipient_c,string recipient_s, string recipient_Z, double wei, double cost); //constructor void setsender_name(string sender_n); string getsender_name(); void setsender_address(string sender_addr); string getsender_address(); void setsender_city(string sender_c); string getSendCity(); void setsender_state(string sender_s); string getsender_state(); void setsender_ZIP(string sender_Z); string getsender_ZIP(); void setrecipient_name(string recipient_n); string getrecipient_name(); void setrecipient_address(string recipient_addr); string getrecipient_address(); void setrecipient_city(string recipient_c); string getrecipient_city(); void setrecipient_state(string recipient_s); string getrecipient_state(); void setrecipient_ZIP(string recipient_Z); string getrecipient_ZIP(); void setweight(double w); double getweight(); void setcostperounce(double cost); double getcostperounce(); double calculateCost(); }; Package::Package(string sender_n, string sender_addr, string sender_c, string sender_s, string sender_Z, string recipient_n, string recipient_addr,string recipient_c,string recipient_s, string recipient_Z, double wei, double cost) { sender_name = sender_n; sender_address = sender_addr; sender_city = sender_c; sender_state = sender_s; sender_ZIP = sender_Z; recipient_name = recipient_n; recipient_address = recipient_addr; recipient_city = recipient_c; recipient_state = recipient_s; recipient_ZIP = recipient_Z; if(wei > 0.0 && cost > 0.0) { weight = wei; costperounce = cost; } else { weight = 0.0; costperounce = 0.0; } } void Package::setsender_name(string sender_n) { sender_name = sender_n; } string Package::getsender_name() { return sender_name; } void Package::setsender_address(string sender_addr) { sender_address = sender_addr; } string Package::getsender_address() { return sender_address; } void Package::setsender_city(string sender_c) { sender_city = sender_c; } string Package::getSendCity() { return sender_city; } void Package::setsender_state(string sender_s) { sender_state = sender_s; } string Package::getsender_state() { return sender_state; } void Package::setsender_ZIP(string sender_Z) { sender_ZIP = sender_Z; } string Package::getsender_ZIP() { return sender_ZIP; } void Package::setrecipient_name(string recipient_n) { recipient_name = recipient_n; } string Package::getrecipient_name() { return recipient_name; } void Package::setrecipient_address(string recipient_addr) { recipient_address = recipient_addr; } string Package::getrecipient_address() { return recipient_address; } void Package::setrecipient_city(string recipient_c) { recipient_city = recipient_c; } string Package::getrecipient_city() { return recipient_city; } void Package::setrecipient_state(string recipient_s) { recipient_state = recipient_s; } string Package::getrecipient_state() { return recipient_state; } void Package::setrecipient_ZIP(string recipient_Z) { recipient_ZIP = recipient_Z; } string Package::getrecipient_ZIP() { return recipient_ZIP; } void Package::setweight(double w) { weight = (w < 0.0 ) ? 0.0 : w; } double Package::getweight() { return weight; } void Package::setcostperounce(double cost) { costperounce = ( cost < 0.0) ? 0.0 : cost; } double Package::getcostperounce() { return costperounce; } double Package::calculateCost() { double result; result = weight * costperounce; return result; } class TwoDayPackage : public Package { private: double two_day_delivery_fee; public: TwoDayPackage(string sender_n, string sender_addr, string sender_c, string sender_s, string sender_Z, string recipient_n, string recipient_addr,string recipient_c,string recipient_s, string recipient_Z,double wei, double cost, double delivery_fee); double gettwo_day_delivery_fee(); void settwo_day_delivery_fee(double delivery_fee); double calculateCost(); }; TwoDayPackage::TwoDayPackage(string sender_n, string sender_addr, string sender_c, string sender_s, string sender_Z, string recipient_n, string recipient_addr,string recipient_c,string recipient_s, string recipient_Z, double wei, double cost, double delivery_fee) :Package(sender_n, sender_addr, sender_c, sender_s, sender_Z, recipient_n, recipient_addr, recipient_c, recipient_s, recipient_Z,wei,cost) { settwo_day_delivery_fee(delivery_fee); } double TwoDayPackage::gettwo_day_delivery_fee() { return two_day_delivery_fee; } void TwoDayPackage::settwo_day_delivery_fee(double delivery_fee) { two_day_delivery_fee = delivery_fee; } double TwoDayPackage::calculateCost() { double result; result = Package::calculateCost() + two_day_delivery_fee; return result; } class OvernightPackage : public Package { private: double overnight_delivery_fee; public: OvernightPackage(string sender_n, string sender_addr, string sender_c, string sender_s, string sender_Z, string recipient_n, string recipient_addr, string recipient_c,string recipient_s, string recipient_Z, double wei, double cost, double delivery_fee); double calculateCost(); double getovernight_delivery_fee(); void setovernight_delivery_fee(double delivery_fee); }; OvernightPackage::OvernightPackage(string sender_n, string sender_addr, string sender_c, string sender_s, string sender_Z, string recipient_n, string recipient_addr,string recipient_c,string recipient_s, string recipient_Z, double wei, double cost, double delivery_fee) :Package(sender_n, sender_addr, sender_c, sender_s, sender_Z, recipient_n, recipient_addr, recipient_c, recipient_s, recipient_Z,wei,cost) { setovernight_delivery_fee(delivery_fee); } double OvernightPackage::getovernight_delivery_fee() { return overnight_delivery_fee; } void OvernightPackage::setovernight_delivery_fee(double delivery_fee) { overnight_delivery_fee = delivery_fee; } double OvernightPackage::calculateCost() { double result; result = (getcostperounce() + overnight_delivery_fee) * getweight(); return result; } //main method int main(int argc, char *argv[]) { OvernightPackage item1("Tom Brown", "123 Main Street", "Phoenix", "Arizona", "89754", "John", "123 bent street", "Hartford", "Connecticut", "87540", 12.00, 1.50, 1.10); TwoDayPackage item2("Monique Smith", "987 1st Street", "Sacramento", "California", "87654", "Paul", "833 palm Street", "Miami", "Florida", "98763", 18.00, 1.05, 8.00); cout