In: Computer Science
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
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 repressents 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.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
=================================
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Package {
private :
string senderName;
string senderAddress;
string senderCity;
string senderState;
string senderZIP;
string recipientName;
string recipientAddress;
string recipientCity;
string recipientState;
string recipientZIP;
double weight;
double costperounce;
public: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);
void setsenderName(string sender_n);
string getsenderName();
void setsenderAddress(string sender_addr);
string getsenderAddress();
void setsenderCity(string sender_c);
string getSendCity();
void setsenderState(string sender_s);
string getsenderState();
void setsenderZIP(string sender_Z);
string getsenderZIP();
void setrecipientName(string recipient_n);
string getrecipientName();
void setrecipientAddress(string recipient_addr);
string getrecipientAddress();
void setrecipientCity(string recipient_c);
string getrecipientCity();
void setrecipientState(string recipient_s);
string getrecipientState();
void setrecipientZIP(string recipient_Z);
string getrecipientZIP();
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)
{
senderName = sender_n;
senderAddress = sender_addr;
senderCity = sender_c;
senderState = sender_s;
senderZIP = sender_Z;
recipientName = recipient_n;
recipientAddress = recipient_addr;
recipientCity = recipient_c;
recipientState = recipient_s;
recipientZIP = recipient_Z;
if (wei > 0.0 && cost > 0.0)
{weight = wei;costperounce = cost;}
else
{
weight = 0.0;
costperounce = 0.0;
}
}
void Package::setsenderName(string sender_n)
{
senderName = sender_n;
}
string Package::getsenderName()
{
return senderName;
}
void Package::setsenderAddress(string sender_addr)
{
senderAddress = sender_addr;
}
string Package::getsenderAddress()
{
return senderAddress;
}
void Package::setsenderCity(string sender_c)
{
senderCity = sender_c;
}
string Package::getSendCity()
{
return senderCity;
}
void Package::setsenderState(string sender_s)
{
senderState = sender_s;
}
string Package::getsenderState()
{
return senderState;
}
void Package::setsenderZIP(string sender_Z)
{
senderZIP = sender_Z;
}
string Package::getsenderZIP()
{
return senderZIP;
}
void Package::setrecipientName(string recipient_n)
{
recipientName = recipient_n;
}
string Package::getrecipientName()
{
return recipientName;
}
void Package::setrecipientAddress(string recipient_addr)
{
recipientAddress = recipient_addr;
}
string Package::getrecipientAddress()
{
return recipientAddress;
}
void Package::setrecipientCity(string recipient_c)
{
recipientCity = recipient_c;
}
string Package::getrecipientCity()
{
return recipientCity;
}
void Package::setrecipientState(string recipient_s)
{
recipientState = recipient_s;
}
string Package::getrecipientState()
{
return recipientState;
}
void Package::setrecipientZIP(string recipient_Z)
{
recipientZIP = recipient_Z;
}
string Package::getrecipientZIP()
{
return recipientZIP;
}
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;
}
int main(int argc, char* argv[])
{
OvernightPackage item1("Kane Williams","12,Church
Street","Mumbai","Maharastra","32456","Mike","23,Park
Street","Banglore","Karnataka","53455",15.00,2.50,1.90);
TwoDayPackage item2("Sachin Tendulkar","12,Bandhra
Street","Mumbai","Maharastra","43556","Jimmy","12,Race Course
Road","Banglore","Karnataka","21345",20.00,1.50,9.50);
cout << fixed << setprecision(2);
cout << "======================================\n";
cout << "Overnight Delivery\n";
cout << "Sender " <<item1.getsenderName() <<
"\n";
cout << " " << item1.getsenderAddress() <<
"\n";
cout <<" " << item1.getSendCity() <<"
"<<item1.getsenderState() <<"
"<<item1.getsenderZIP()<<"\n";
cout << "\n";
cout << "Recipient " << item1.getrecipientName()
<< "\n";
cout << " " << item1.getsenderAddress() <<
"\n";
cout << " " << item1.getrecipientCity() << " "
<<
item1.getrecipientState() << " " <<
item1.getrecipientZIP() << "\n";
cout << "Cost $ " << item1.calculateCost() <<
"\n";
cout << "======================================\n";
cout << "\n\n";
cout << "======================================\n";
cout << "Sender " << item2.getsenderName() <<
"\n";
cout << " " << item2.getsenderAddress() <<
"\n";
cout<<" "<< item2.getSendCity()<<"
"<<item2.getsenderState()<<"
"<<item2.getsenderZIP()<< "\n";
cout << "\n";
cout << "Recipient " << item2.getrecipientName()
<< "\n";
cout << " " << item2.getsenderAddress() <<
"\n";
cout<<" "<<item2.getrecipientCity()<<"
"<<item2.getrecipientState()<<" "<<
item2.getrecipientZIP()<<"\n";
cout << "Cost $ " << item2.calculateCost() <<
"\n";
cout << "======================================\n";
system("pause");
return 0;
}
=====================================
output:
===============================Thank You