In: Computer Science
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. Package should also provide the public member function displayShippingDetail which outputs the sender and recipient information (see below for example). 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.
Sample
Package To: Ben Stiller 89 N Brooke Dr Brooklyn, NY 02142 From: Macy Gray 89 Wisconsin Ave Seattle, WA 42512-9031 Total: $11.41 Two Day Package To: Ken Mattingly 7888 Ventura Highway Titusville, FL 32933 From: Dave Letterman 2313 Fairview Way Poughkeepsie, NY 12604 Total: $31.99 Overnight Package To: Toby Zeigler 1600 Pennsylvania Ave NW Washington, DC 20500 From: Joey Lucas 522 N Maple Dr Beverly Hills, CA 90210 Total: $81.12
Hello I need a overnightPackage .cpp file and overnightPackage .h file, package .cpp file and package .h file, main .cpp file, and lastly TwoDayPackage .cpp file and TwoDayPackage .h file.
I need all this code in C++
using System;
public class Package
{
string senderName11;
string senderAddress1;
string senderCity1;
string senderState1;
string senderZip1;
string recipientName1;
string recipientAddress1;
string recipientCity1;
string recipientState1;
string recipientZip1;
decimal weight1;
decimal costPerOunce1;
public string SenderName11
{
get { return senderName11; }
set { senderName11 = value; }
}
public string SenderAddress1
{
get { return senderAddress1; }
set { senderAddress1 = value; }
}
public string SenderCity1
{
get { return senderCity1; }
set { senderCity1 = value; }
}
public string SenderState1
{
get { return senderState1; }
set { senderState1 = value; }
}
public string SenderZip1
{
get { return senderZip1;}
set { senderZip1 = value; }
}
public string RecipientName1
{
get { return recipientName1; }
set { recipientName1 = value; }
}
public string RecipientAddress1
{
get { return recipientAddress1; }
set { recipientAddress1 = value; }
}
public string RecipientCity1
{
get { return recipientCity1; }
set { recipientCity1 = value; }
}
public string RecipientState1
{
get { return recipientState1; }
set { recipientState1 = value; }
}
public string RecipientZip1
{
get { return recipientZip1; }
set { recipientZip1 = value; }
}
public decimal Weight1
{
get { return weight1; }
set
{
if (value > 0)
weight1 = value;
else
Console.WriteLine("Weight1 can't be less tha zero");
}
}
public decimal CostPerOunce1
{
get { return costPerOunce1; }
set
{
if (value > 0)
costPerOunce1 = value;
else
Console.WriteLine("Cost per ounce can't be less than zero");
}
}
public Package
(
string senderName11,
string senderAddress1,
string senderCity1,
string senderState1,
string senderZip1,
string recipientName1,
string recipientAddress1,
string recipientCity1,
string recipientState1,
string recipientZip1,
decimal weight1,
decimal costPerOunce1
)
{
SenderName11 = senderName11;
SenderAddress1 = senderAddress1;
SenderCity1 = senderCity1;
SenderState1 = senderState1;
SenderZip1 = senderZip1;
RecipientName1 = recipientName1;
RecipientAddress1 = recipientAddress1;
RecipientCity1 = recipientCity1;
RecipientState1 = recipientState1;
RecipientZip1 = recipientZip1;
Weight1 = weight1;
CostPerOunce1 = costPerOunce1;
}
public virtual decimal CalculateCost()
{
return weight1 * costPerOunce1;
}
}
public class TwoDayPackage : Package
{
decimal twoDayDeliveryFee;
public decimal TwoDayDeliveryFee
{
get { return twoDayDeliveryFee; }
set { twoDayDeliveryFee = value; }
}
public TwoDayPackage
(
string senderName11,
string senderAddress1,
string senderCity1,
string senderState1,
string senderZip1,
string recipientName1,
string recipientAddress1,
string recipientCity1,
string recipientState1,
string recipientZip1,
decimal weight1,
decimal costPerOunce1,
decimal twoDayDeliveryFee
)
: base
(
senderName11,
senderAddress1,
senderCity1,
senderState1,
senderZip1,
recipientName1,
recipientAddress1,
recipientCity1,
recipientState1,
recipientZip1,
weight1,
costPerOunce1
)
{
TwoDayDeliveryFee = twoDayDeliveryFee;
}
public override decimal CalculateCost()
{
return base.CalculateCost() + TwoDayDeliveryFee;
}
}
public class OvernightPackage : Package
{
decimal overnightDeliveryFeePerOunce;
public decimal OvernightDeliveryFeePerOunce
{
get { return overnightDeliveryFeePerOunce; }
set { overnightDeliveryFeePerOunce = value; }
}
public OvernightPackage
(
string senderName11,
string senderAddress1,
string senderCity1,
string senderState1,
string senderZip1,
string recipientName1,
string recipientAddress1,
string recipientCity1,
string recipientState1,
string recipientZip1,
decimal weight1,
decimal costPerOunce1,
decimal overnightDeliveryFeePerOunce
)
: base
(
senderName11,
senderAddress1,
senderCity1,
senderState1,
senderZip1,
recipientName1,
recipientAddress1,
recipientCity1,
recipientState1,
recipientZip1,
weight1,
costPerOunce1
)
{
OvernightDeliveryFeePerOunce = overnightDeliveryFeePerOunce;
}
public override decimal CalculateCost()
{
return (CostPerOunce1 + OvernightDeliveryFeePerOunce) * Weight1;
}
}
class TestPackages
{
static void Main(string[] args)
{
Package regularPackage = new Package
(
"Peter Anderson",
"123 Main St, Ashville, NC 27111 ",
"Ashville",
"NC 27111",
"MN 55416",
"Mary Brown",
"456 Broad St Benson, NC 27222",
"St. Petersburg",
"Benson",
"NC 27222",
160M,
0.1M
);
Console.WriteLine("\nRegular Package: ");
Console.WriteLine(" Sender's Name: {0}",
regularPackage.SenderName11);
Console.WriteLine(" Sender's Address: {0}",
regularPackage.SenderAddress1);
Console.WriteLine(" Recipient's Name: {0}",
regularPackage.RecipientName1);
Console.WriteLine(" Recipient's Address: {0}",
regularPackage.RecipientAddress1);
Console.WriteLine(" Weight1: {0}"
, regularPackage.Weight1);
Console.WriteLine(" Cost Per Ounce: {0:C}",
regularPackage.CostPerOunce1);
Console.WriteLine("Shipping Cost: {0:C}",
regularPackage.CalculateCost());
Console.WriteLine(regularPackage.CalculateCost());
TwoDayPackage twoDayPackage = new TwoDayPackage
(
"Peter Anderson",
"123 Main St 123 Main St, Ashville, NC 27111",
"Ashville",
"NC 27111",
"MN 55416",
"Mary Brown",
"456 Broad St",
"St. Petersburg",
"Benson",
"NC 27222",
160M,
0.1M,
1.5M
);
Console.WriteLine("\nTwo-Day Package: ");
Console.WriteLine(" Sender's Name: {0}",
twoDayPackage.SenderName11);
Console.WriteLine(" Sender's Address: {0}",
twoDayPackage.SenderAddress1);
Console.WriteLine(" Recipient's Name: {0}",
twoDayPackage.RecipientName1);
Console.WriteLine(" Recipient's Address: {0}",
twoDayPackage.RecipientAddress1);
Console.WriteLine(" Weight1: {0}", twoDayPackage.Weight1);
Console.WriteLine(" Cost Per Ounce: {0:C}",
twoDayPackage.CostPerOunce1);
Console.WriteLine(" Flat Fee: {0:C}",
twoDayPackage.Weight1);
Console.WriteLine(" Shipping Cost: {0:C}",
twoDayPackage.CalculateCost());
OvernightPackage overnightPackage = new OvernightPackage
(
"Peter Anderson",
"123 Main St 123 Main St, Ashville, NC 27111",
"Ashville",
"NC 27111",
"MN 55416",
"Mary Brown",
"456 Broad St Benson, NC 27222",
"St. Petersburg",
"Benson",
"NC 27222",
160M,
0.1M,
1.5M
);
Console.WriteLine("\nOvernight Package: ");
Console.WriteLine(" Sender's Name: {0}",
overnightPackage.SenderName11);
Console.WriteLine(" Sender's Address: {0}",
overnightPackage.SenderAddress1);
Console.WriteLine(" Recipient's Name: {0}",
overnightPackage.RecipientName1);
Console.WriteLine(" Recipient's Address: {0}",
overnightPackage.RecipientAddress1);
Console.WriteLine(" Weight1: {0}",
overnightPackage.Weight1);
Console.WriteLine(" Cost Per Ounce: {0:C}",
overnightPackage.CostPerOunce1);
Console.WriteLine(" Additional Cost Per Ounce: {0:C}",
overnightPackage.OvernightDeliveryFeePerOunce);
Console.WriteLine(" Shipping Cost: {0:C}",
overnightPackage.CalculateCost());
Console.WriteLine(overnightPackage.CalculateCost()); Console.ReadKey();
}
}
Output-