Question: Separate each class's interface from its implementation. Create a class named Package with the following requirements. a. Create four private data members to store the

Separate each class's interface from its implementation.

Create a class named Package with the following requirements.

a.

Create four private data members to store the package sender, package recipient, weight of package (in ounces) and the cost per ounce to ship. Both the sender and recipient data members must be of type Address. The Address class has been written for you and should not be modified. The weight and cost of the package should be of type double.

b.

Create a constructor to initialize the values of the data members that will receive four arguments, one for each data member in the order of recipient, sender, weight, then cost per ounce to ship.

c.

Create a public member function named getWeight that returns back the value of the weight data member.

d.

Create a public member function named calculateCost that returns a double which represents the cost of shipping the package. The cost of shipping the package is the weight of the package multiplied by the cost per ounce to ship the package. weight of the package * cost per ounce to ship

e.

Create a public member function named print that displays the values for the data members of this class as shown below

 To:  
, From:
, Weight: Cost per ounce to ship:

This print member function should call the print member function of the Address class to display who the package is To and From.

f.

Create a virtual destructor. The destructor does not need to contain any code.

Create a class named TwoDayPackage with the following requirements.

a.

TwoDayPackage should inherit from Package.

b.

Create only one private data member to store a flat fee cost to ship a two day package.

c.

Create a constructor to initialize the value of the flat fee cost data member as well as the data members of the parent class. This constructor will receive five arguments in all using the order of recipient, sender, weight, cost per ounce to ship, then the flat fee cost.

d.

Create a public member function named calculateCost that returns a double which represents the cost of shipping a two day package. The cost of shipping a two day package is

flat fee + (weight of the package * cost per ounce to ship)

This member function must call the parent class's calculateCost to compute what is shown within parentheses above.

e.

Create a public member function named print that displays the following information

 To:  
, From:
, Weight: Cost per ounce to ship: Flat fee:

This print member function should call the parent class's print member function to display everything except the flat fee.

f.

Create a virtual destructor. The destructor does not need to contain any code.

Create a class named OvernightPackage with the following requirements.

a.

OvernightPackage should inherit from Package.

b.

Create only one private data member to store an additional fee per ounce cost to ship an overnight package.

c.

Create a constructor to initialize the value of the additional fee per ounce cost data member as well as the data members of the parent class. This constructor will receive five arguments in all using the order of recipient, sender, weight, cost per ounce to ship, then the additional fee per ounce.

d.

Create a public member function named calculateCost that returns a double which represents the cost of shipping an overnight package. The cost of shipping an overnight package is

(additional fee per ounce * weight of the package) + (weight of the package * cost per ounce to ship)

This member function must call the parent class's calculateCost to compute what is shown within parentheses above on the right hand side of the plus sign.

e.

Create a public member function named print that displays the following information

 To:  
, From:
, Weight: Cost per ounce to ship: Additional fee per ounce:

This print member function should call the parent class's print member function to display everything except the additional fee per ounce.

f.

Create a virtual destructor. The destructor does not need to contain any code.

Based on the following main function for you to use, make the appropriate functions in your classes virtual so the code will polymorphically process the objects in the vector to produce the correct output (see step 8).

Below is the output for this program

#ifndef ADDRESS_H #define ADDRESS_H #include  class Address { public: // constructor initializes data members Address( const std::string &, const std::string &, const std::string &, const std::string &, int ); virtual ~Address() { } // virtual destructor void setName( const std::string & ); // set name std::string getName() const; // return name void setAddress( const std::string & ); // set street address std::string getAddress() const; // return street address void setCity( const std::string & ); // set city std::string getCity() const; // return city void setState( const std::string & ); // set state std::string getState() const; // return state void setZIP( int ); // set sZIP code int getZIP() const; // return ZIP code void print() const; //print the data members private: // data members to store sender and recipient's address information std::string name; std::string streetAddress; std::string city; std::string state; int ZIP; }; // end class Address #endif
-------------------------------------------------------------------
// Address.cpp // Member-function definitions of class Address. #include "Address.h" // Address class definition #include  using namespace std; // constructor initializes data members Address::Address( const string &sName, const string &sAddress, const string &sCity, const string &sState, int sZIP ) { setName(sName); setAddress(sAddress); setCity(sCity); setState(sState); setZIP(sZIP); } // end Address constructor // set sender's name void Address::setName( const string &name ) { this->name = name; } // end function setName // return sender's name string Address::getName() const { return name; } // end function getSenderName // set sender's address void Address::setAddress( const string &address ) { streetAddress = address; } // end function setSenderAddress // return sender's address string Address::getAddress() const { return streetAddress; } // end function getSenderAddress // set sender's city void Address::setCity( const string &city ) { this->city = city; } // end function setSenderCity // return sender's city string Address::getCity() const { return city; } // end function getSenderCity // set sender's state void Address::setState( const string &state ) { this->state = state; } // end function setSenderState // return sender's state string Address::getState() const { return state; } // end function getSenderState // set sender's ZIP code void Address::setZIP( int zip ) { ZIP = zip; } // end function setSenderZIP // return sender's ZIP code int Address::getZIP() const { return ZIP; } // end function getSenderZIP //display the data members void Address::print() const { cout  
-----------------------------------------------------------------
// Assign3.cpp // Processing Packages polymorphically. #include  #include  #include  #include "Package.h" // Package class definition #include "TwoDayPackage.h" // TwoDayPackage class definition #include "OvernightPackage.h" // OvernightPackage class definition #include "Address.h" // Address class definition using namespace std; int main() { // create vector packages vector  packages( 3 ); //create to and from address for the three objects Address add1To("Lou Brown", "1 Main St", "Boston", "MA", 11111); Address add1From("Mary Smith", "7 Elm St", "New York", "NY", 22222); Address add2To("Lisa Klein", "5 Broadway Rd", "Indianapolis", "IN", 33333); Address add2From("Bob George", "21 Pine Rd", "Miami", "FL", 44444); Address add3to("Ed Lewis", "2 Oak St", "Boston", "MA", 55555); Address add3From("Don Kelly", "9 Main St", "Denver", "CO", 66666); // initialize vector with Packages packages[ 0 ] = new Package(add1To, add1From, 8.5, .5 ); //to, from, weight, cost per ounce packages[ 1 ] = new TwoDayPackage(add2To , add2From, 10.5, .65, 2.0 ); //to, from, weight, cost per ounce, flat fee packages[ 2 ] = new OvernightPackage(add3to , add3From, 12.25, .7, .25 ); //to, from, weight, cost per ounce, additional fee per ounce cout print(); //display information for each object double cost = packages[ i ]->calculateCost(); cout   exe PACKAGE 1 To: Lou Brown 1 Main St From Mary Smith 7 Elm St New York, NY 22222 eight: 8.50 Cost per ounce to ship: 0.50 Shipping Cost: 4 PACKAGE 2 To: Lisa Klein 5 Broadway Rd Indianapolis, IN 33333 From Bob George 21 Pine Rd Miami, FL 44444 eight: 10.50 Cost per ounce to ship: 0.65 Flat fee: 2.00 Shipping Cost: $8 .82 PACKAGE 3 To: Ed Lewis 2 Oak St Boston, MA 55555 From Don Kelly 9 Main St Denver, CO 66666 eight: 12.25 Cost per ounce to ship: 0.70 Additional fee per ounce: 0.25 Shipping Cost: $11.64  exe PACKAGE 1 To: Lou Brown 1 Main St From Mary Smith 7 Elm St New York, NY 22222 eight: 8.50 Cost per ounce to ship: 0.50 Shipping Cost: 4 PACKAGE 2 To: Lisa Klein 5 Broadway Rd Indianapolis, IN 33333 From Bob George 21 Pine Rd Miami, FL 44444 eight: 10.50 Cost per ounce to ship: 0.65 Flat fee: 2.00 Shipping Cost: $8 .82 PACKAGE 3 To: Ed Lewis 2 Oak St Boston, MA 55555 From Don Kelly 9 Main St Denver, CO 66666 eight: 12.25 Cost per ounce to ship: 0.70 Additional fee per ounce: 0.25 Shipping Cost: $11.64

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!