(Package Inheritance Hierarchy) Use the Package inheritance hierarchy created in Exercise 12.9 to create a program that displays the address information and calculates the shipping costs for several Packages. The program should contain a vector of Package pointers to objects of classes TwoDayPackage and OvernightPackage. Loop through the vector to process the Packages polymorphically. For each

Package, invoke get functions to obtain the address information of the sender and the recipient, then print the two addresses as they would appear on mailing labels. Also, call each Package’s calculateCost member function and print the result. Keep track of the total shipping cost for all Packages in the vector, and display this total when the loop terminates.

What will be an ideal response?


```
// Definition of base class Package.
#ifndef PACKAGE_H
#define PACKAGE_H

#include
using namespace std;

class Package
{
public:
// constructor initializes data members
Package( const string &, const string &, const string &,
const string &, int, const string &, const string &, const string &,
const string &, int, double, double );

void setSenderName( const string & ); // set sender's name
string getSenderName() const; // return sender's name
void setSenderAddress( const string & ); // set sender's address
string getSenderAddress() const; // return sender's address
void setSenderCity( const string & ); // set sender's city
string getSenderCity() const; // return sender's city
void setSenderState( const string & ); // set sender's state
string getSenderState() const; // return sender's state
void setSenderZIP( int ); // set sender's ZIP code
int getSenderZIP() const; // return sender's ZIP code
void setRecipientName( const string & ); // set recipient's name
string getRecipientName() const; // return recipient's name
void setRecipientAddress( const string & ); // set recipient's address
string getRecipientAddress() const; // return recipient's address
void setRecipientCity( const string & ); // set recipient's city
string getRecipientCity() const; // return recipient's city
void setRecipientState( const string & ); // set recipient's state
string getRecipientState() const; // return recipient's state
void setRecipientZIP( int ); // set recipient's ZIP code
int getRecipientZIP() const; // return recipient's ZIP code
void setWeight( double ); // validate and store weight
double getWeight() const; // return weight of package
void setCostPerOunce( double ); // validate and store cost per ounce
double getCostPerOunce() const; // return cost per ounce

virtual double calculateCost() const; // calculate shipping cost
private:
// data members to store sender and recipient's address information
string senderName;
string senderAddress;
string senderCity;
string senderState;
int senderZIP;
string recipientName;
string recipientAddress;
string recipientCity;
string recipientState;
int recipientZIP;

double weight; // weight of the package
double costPerOunce; // cost per ounce to ship the package
}; // end class Package

#endif
```
```
// Member-function definitions of class Package.

#include "Package.h" // Package class definition

// constructor initializes data members
Package::Package( const string &sName, const string &sAddress,
const string &sCity, const string &sState, int sZIP,
const string &rName, const string &rAddress, const string &rCity,
const string &rState, int rZIP, double w, double cost )
: senderName( sName ), senderAddress( sAddress ), senderCity( sCity ),
senderState( sState ), senderZIP( sZIP ), recipientName( rName ),
recipientAddress( rAddress ), recipientCity( rCity ),
recipientState( rState ), recipientZIP( rZIP )
{
setWeight( w ); // validate and store weight
setCostPerOunce( cost ); // validate and store cost per ounce
} // end Package constructor

// set sender's name
void Package::setSenderName( const string &name )
{
senderName = name;
} // end function setSenderName

// return sender's name
string Package::getSenderName() const
{
return senderName;
} // end function getSenderName

// set sender's address
void Package::setSenderAddress( const string &address )
{
senderAddress = address;
} // end function setSenderAddress

// return sender's address
string Package::getSenderAddress() const
{
return senderAddress;
} // end function getSenderAddress

// set sender's city
void Package::setSenderCity( const string &city )
{
senderCity = city;
} // end function setSenderCity

// return sender's city
string Package::getSenderCity() const
{
return senderCity;
} // end function getSenderCity

// set sender's state
void Package::setSenderState( const string &state )
{
senderState = state;
} // end function setSenderState

// return sender's state
string Package::getSenderState() const
{
return senderState;
} // end function getSenderState

// set sender's ZIP code
void Package::setSenderZIP( int zip )
{
senderZIP = zip;
} // end function setSenderZIP

// return sender's ZIP code
int Package::getSenderZIP() const
{
return senderZIP;
} // end function getSenderZIP

// set recipient's name
void Package::setRecipientName( const string &name )
{
recipientName = name;
} // end function setRecipientName

// return recipient's name
string Package::getRecipientName() const
{
return recipientName;
} // end function getRecipientName

// set recipient's address
void Package::setRecipientAddress( const string &address )
{
recipientAddress = address;
} // end function setRecipientAddress

// return recipient's address
string Package::getRecipientAddress() const
{
return recipientAddress;
} // end function getRecipientAddress

// set recipient's city
void Package::setRecipientCity( const string &city )
{
recipientCity = city;
} // end function setRecipientCity

// return recipient's city
string Package::getRecipientCity() const
{
return recipientCity;
} // end function getRecipientCity

// set recipient's state
void Package::setRecipientState( const string &state )
{
recipientState = state;
} // end function setRecipientState

// return recipient's state
string Package::getRecipientState() const
{
return recipientState;
} // end function getRecipientState

// set recipient's ZIP code
void Package::setRecipientZIP( int zip )
{
recipientZIP = zip;
} // end function setRecipientZIP

// return recipient's ZIP code
int Package::getRecipientZIP() const
{
return recipientZIP;
} // end function getRecipientZIP

// validate and store weight
void Package::setWeight( double w )
{
weight = ( w < 0.0 ) ? 0.0 : w;
} // end function setWeight

// return weight of package
double Package::getWeight() const
{
return weight;
} // end function getWeight

// validate and store cost per ounce
void Package::setCostPerOunce( double cost )
{
costPerOunce = ( cost < 0.0 ) ? 0.0 : cost;
} // end function setCostPerOunce

// return cost per ounce
double Package::getCostPerOunce() const
{
return costPerOunce;
} // end function getCostPerOunce

// calculate shipping cost for package
double Package::calculateCost() const
{
return getWeight() * getCostPerOunce();
} // end function calculateCost
```

Computer Science & Information Technology

You might also like to view...

For a non-profit organization, the only source for funding is from ______________.

a. Grants b. Private contributions c. Collection of fees d. All of the above

Computer Science & Information Technology

Pinterest is driving more traffic to company websites and blogs than YouTube, ________, and LinkedIn combined

Fill in the blank(s) with correct word

Computer Science & Information Technology

What is normalize?

What will be an ideal response?

Computer Science & Information Technology

All software that contains e-PHI must have a tracking or auditing system to report who has viewed a patient's information

Indicate whether the statement is true or false

Computer Science & Information Technology