SlideShare a Scribd company logo
1 of 9
Download to read offline
C++ 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 caculateCost 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 caculateCost 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. In your main method, ask the user what type of package they want, then
ask the user for the appropriate information for that package. Add that package to your vector of
Packages. Once the user is done entering packages, then loop through your vector and print out
mailing labels for each package (address information for sender and recipient). Also, print out
each packages cost. After your loop ends, print out the total cost for all the packages, and the
average package cost. Also, print out how many of each type of package was entered.
Solution
#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:
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 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;
}
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 << fixed << setprecision(2);
cout <<
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ";
cout << "Overnight Delivery ";
cout << "Sender " << item1.getsender_name()<< " ";
cout << " " << item1.getsender_address() << " ";
cout << " " << item1.getSendCity() << " " <<
item1.getsender_state() << " " << item1.getsender_ZIP() << " ";
cout << " ";
cout << "Recipient " << item1.getrecipient_name()<< " ";
cout << " " << item1.getsender_address() << " ";
cout << " " << item1.getrecipient_city() << " " <<
item1.getrecipient_state() << " " << item1.getrecipient_ZIP() << " ";
cout << "Cost $ " <

More Related Content

More from arihantelectronics

Cloning has been seen in the news and as a major topic of debate.B.pdf
Cloning has been seen in the news and as a major topic of debate.B.pdfCloning has been seen in the news and as a major topic of debate.B.pdf
Cloning has been seen in the news and as a major topic of debate.B.pdf
arihantelectronics
 
Balance of Payments Accounting Describe how each of the following t.pdf
Balance of Payments Accounting Describe how each of the following t.pdfBalance of Payments Accounting Describe how each of the following t.pdf
Balance of Payments Accounting Describe how each of the following t.pdf
arihantelectronics
 
1. One of the things Alexis enjoys about her teams _______ is that.pdf
1. One of the things Alexis enjoys about her teams _______ is that.pdf1. One of the things Alexis enjoys about her teams _______ is that.pdf
1. One of the things Alexis enjoys about her teams _______ is that.pdf
arihantelectronics
 
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdfOption #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
arihantelectronics
 

More from arihantelectronics (20)

Given a linked list, write a function to determine if the list is sym.pdf
Given a linked list, write a function to determine if the list is sym.pdfGiven a linked list, write a function to determine if the list is sym.pdf
Given a linked list, write a function to determine if the list is sym.pdf
 
Describe International Accounting and provide exampleSolutionI.pdf
Describe International Accounting and provide exampleSolutionI.pdfDescribe International Accounting and provide exampleSolutionI.pdf
Describe International Accounting and provide exampleSolutionI.pdf
 
Cloning has been seen in the news and as a major topic of debate.B.pdf
Cloning has been seen in the news and as a major topic of debate.B.pdfCloning has been seen in the news and as a major topic of debate.B.pdf
Cloning has been seen in the news and as a major topic of debate.B.pdf
 
Ascocarps (mark all that true statements) contain asci that produce.pdf
Ascocarps (mark all that true statements)  contain asci that produce.pdfAscocarps (mark all that true statements)  contain asci that produce.pdf
Ascocarps (mark all that true statements) contain asci that produce.pdf
 
and prokaryotes differ. Drag and drop each phrase onto the image of.pdf
and prokaryotes differ. Drag and drop each phrase onto the image of.pdfand prokaryotes differ. Drag and drop each phrase onto the image of.pdf
and prokaryotes differ. Drag and drop each phrase onto the image of.pdf
 
Chemoautotrophs TripleDot make their food using chemical energy .pdf
Chemoautotrophs TripleDot  make their food using chemical energy .pdfChemoautotrophs TripleDot  make their food using chemical energy .pdf
Chemoautotrophs TripleDot make their food using chemical energy .pdf
 
Why is scab formation important in wound healingSolutionWhen .pdf
Why is scab formation important in wound healingSolutionWhen .pdfWhy is scab formation important in wound healingSolutionWhen .pdf
Why is scab formation important in wound healingSolutionWhen .pdf
 
Balance of Payments Accounting Describe how each of the following t.pdf
Balance of Payments Accounting Describe how each of the following t.pdfBalance of Payments Accounting Describe how each of the following t.pdf
Balance of Payments Accounting Describe how each of the following t.pdf
 
Which of the following molecules can diffuse through the membrane fa.pdf
Which of the following molecules can diffuse through the membrane fa.pdfWhich of the following molecules can diffuse through the membrane fa.pdf
Which of the following molecules can diffuse through the membrane fa.pdf
 
2. A germ population has a growth curve of Aet At what value of i doe.pdf
2. A germ population has a growth curve of Aet At what value of i doe.pdf2. A germ population has a growth curve of Aet At what value of i doe.pdf
2. A germ population has a growth curve of Aet At what value of i doe.pdf
 
What are transferred in costs When do they occurSolution T.pdf
What are transferred in costs When do they occurSolution    T.pdfWhat are transferred in costs When do they occurSolution    T.pdf
What are transferred in costs When do they occurSolution T.pdf
 
We are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdf
We are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdfWe are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdf
We are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdf
 
what is the function of CaCl2 on E coli cellsSolutionCalcium .pdf
what is the function of CaCl2 on E coli cellsSolutionCalcium .pdfwhat is the function of CaCl2 on E coli cellsSolutionCalcium .pdf
what is the function of CaCl2 on E coli cellsSolutionCalcium .pdf
 
1. One of the things Alexis enjoys about her teams _______ is that.pdf
1. One of the things Alexis enjoys about her teams _______ is that.pdf1. One of the things Alexis enjoys about her teams _______ is that.pdf
1. One of the things Alexis enjoys about her teams _______ is that.pdf
 
Social media marketing1.How linkedin is best used for business.pdf
Social media marketing1.How linkedin is best used for business.pdfSocial media marketing1.How linkedin is best used for business.pdf
Social media marketing1.How linkedin is best used for business.pdf
 
A diploid organism has 8 pairs of homologous chromosomes. How many p.pdf
A diploid organism has 8 pairs of homologous chromosomes. How many p.pdfA diploid organism has 8 pairs of homologous chromosomes. How many p.pdf
A diploid organism has 8 pairs of homologous chromosomes. How many p.pdf
 
Stamens, sepals, petals, and carpels are ________.1. Modified leav.pdf
Stamens, sepals, petals, and carpels are ________.1. Modified leav.pdfStamens, sepals, petals, and carpels are ________.1. Modified leav.pdf
Stamens, sepals, petals, and carpels are ________.1. Modified leav.pdf
 
Prove that the only nonnegative superharmonic functions in R are the.pdf
Prove that the only nonnegative superharmonic functions in R are the.pdfProve that the only nonnegative superharmonic functions in R are the.pdf
Prove that the only nonnegative superharmonic functions in R are the.pdf
 
Problem 5.21The increase or decrease in the price of a stock betwe.pdf
Problem 5.21The increase or decrease in the price of a stock betwe.pdfProblem 5.21The increase or decrease in the price of a stock betwe.pdf
Problem 5.21The increase or decrease in the price of a stock betwe.pdf
 
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdfOption #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 

C++ Inheritance Hierarchy! Package-delivery services, such as FedEx.pdf

  • 1. C++ 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 caculateCost 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 caculateCost 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. In your main method, ask the user what type of package they want, then ask the user for the appropriate information for that package. Add that package to your vector of Packages. Once the user is done entering packages, then loop through your vector and print out mailing labels for each package (address information for sender and recipient). Also, print out each packages cost. After your loop ends, print out the total cost for all the packages, and the average package cost. Also, print out how many of each type of package was entered. Solution #include #include #include using namespace std; class Package
  • 2. { 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: 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 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);
  • 3. 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 {
  • 4. 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() {
  • 5. 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)
  • 6. { 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;
  • 7. 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()
  • 8. { 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) {
  • 9. 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("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 << fixed << setprecision(2); cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ "; cout << "Overnight Delivery "; cout << "Sender " << item1.getsender_name()<< " "; cout << " " << item1.getsender_address() << " "; cout << " " << item1.getSendCity() << " " << item1.getsender_state() << " " << item1.getsender_ZIP() << " "; cout << " "; cout << "Recipient " << item1.getrecipient_name()<< " "; cout << " " << item1.getsender_address() << " "; cout << " " << item1.getrecipient_city() << " " << item1.getrecipient_state() << " " << item1.getrecipient_ZIP() << " "; cout << "Cost $ " <