Code:
#include "stdafx.h"
#include<string>
#include <iostream>
using std::string;
using namespace std;
using std::fixed;
//using std::setprecision; -- this not being recognized for some reason so I commented it out for now
/* This class Package is the base class for two other classes, TwoDayPackage and OverNightPackage.
/ It should contain data members for name, address, city, state, zipcode for both a sender and a recipient.
/ And data members for weight, and ship cost per ounce.
/ The constructor should initialize these members.
/ A public member function to calculateCost should be provided and perform : cost = weight * shipCost. */
class Package // begins class Package
{
public:
Package(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double = 0.0, double = 0.0); // constructor
// set and get functions for sender
void setSenderName(const string &);
string getSenderName() const;
void setSenderAddress(const string &);
string getSenderAddress() const;
void setSenderCity(const string &);
string getSenderCity() const;
void setSenderState(const string &);
string getSenderState() const;
void setSenderZipcode(const string &);
string getSenderZipcode() const;
// set and get functions for recipient
void setRecipientName(const string &);
string getRecipientName() const;
void setRecipientAddress(const string &);
string getRecipientAddress() const;
void setRecipientCity(const string &);
string getRecipientCity() const;
void setRecipientState(const string &);
string getRecipientState() const;
void setRecipientZipcode(const string &);
string getRecipientZipcode() const;
void setWeight(double);
double getWeight() const;
void setShipCost(double);
double getShipCost() const;
double CalculateCost() const;
protected:
string senderName;
string senderAddress;
string senderCity;
string senderState;
string senderZipcode;
string recipientName;
string recipientAddress;
string recipientCity;
string recipientState;
string recipientZipcode;
double weight;
double shipCost;
};
Package::Package(const string &sname, const string &saddress, const string &scity, const string &sstate, const string &szipcode, const string &rname, const string &raddress, const string &rcity, const string &rstate, const string &rzipcode, double weight, double shipCost)
{
senderName = sname;
senderAddress = saddress;
senderCity = scity;
senderState = sstate;
senderZipcode = szipcode;
recipientName = rname;
recipientAddress = raddress;
recipientCity = rcity;
recipientState = rstate;
recipientZipcode = rzipcode;
setWeight(weight);
setShipCost(shipCost);
}
void Package::setSenderName(const string &sname)
{
senderName = sname;
}
string Package::getSenderName() const
{
return senderName;
}
void Package::setSenderAddress(const string &saddress)
{
senderAddress = saddress;
}
string Package::getSenderAddress() const
{
return senderAddress;
}
void Package::setSenderCity(const string &scity)
{
senderCity = scity;
}
string Package::getSenderCity() const
{
return senderCity;
}
void Package::setSenderState(const string &sstate)
{
senderState = sstate;
}
string Package::getSenderState() const
{
return senderState;
}
void Package::setSenderZipcode(const string &szipcode)
{
senderZipcode = szipcode;
}
string Package::getSenderZipcode() const
{
return senderZipcode;
}
void Package::setRecipientName(const string &rname)
{
recipientName = rname;
}
string Package::getRecipientName() const
{
return recipientName;
}
void Package::setRecipientAddress(const string &raddress)
{
recipientAddress = raddress;
}
string Package::getRecipientAddress() const
{
return recipientAddress;
}
void Package::setRecipientCity(const string &rcity)
{
recipientCity = rcity;
}
string Package::getRecipientCity() const
{
return recipientCity;
}
void Package::setRecipientState(const string &rstate)
{
recipientState = rstate;
}
string Package::getRecipientState() const
{
return recipientState;
}
void Package::setRecipientZipcode(const string &rzipcode)
{
recipientZipcode = rzipcode;
}
string Package::getRecipientZipcode() const
{
return recipientZipcode;
}
void Package::setWeight(double weight)
{
weight = (weight < 0.0 ) ? 0.0 : weight;
}
double Package::getWeight() const
{
return weight;
}
void Package::setShipCost(double shipCost)
{
shipCost = ( shipCost < 0.0) ? 0.0 : shipCost;
}
double Package::getShipCost() const
{
return shipCost;
}
double Package::CalculateCost() const
{
return weight * shipCost;
}
/* This class TwoDayPackage is the first derived class from class Package.
/ It should contain a data member flatFee, to reflect an additional cost.
/ The constructor should recieve a value to initialize this fee and redefine the
/ function CalculateCost so that it adds the fee to the function's calculation. */
class TwoDayPackage : public Package
{
public:
TwoDayPackage(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double = 0.0, double = 0.0, double = 0.0); // constructor
void setFlatFee(double);
double getFlatFee() const;
void CalculateCost() const;
private:
double flatFee;
};
/* This class OverNightPackage is the second derived class from class Package.
/ It should contain a data member extraFee, to reflect an additional cost per ounce.
/ The constructor should redefine the function CalculateCost so that
/ it adds the fee to the standard cost per ounce before the function's calculation. */
class OverNightPackage : public Package
{
public:
OverNightPackage(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double, double, double); // constructor
void setExtraFee(double);
double getExtraFee() const;
void CalculateCost() const;
private:
double extraFee;
};
/* This is the test program.
/ It should create objects of each type of Package and test member function CalculateCost. */
int main()
{
//OverNightPackage box("J. Jones", "123 Oak Street", "El Paso", "TX", "12345", "S. Smith", "321 Elm Street", "Tulsa", "OK", "54321", 16.00, 1.00, .60);
//TwoDayPackage parcel("A. Anderson", "456 Maple Street", "Las Vegas", "NV", "67890", "J. Johnson", "654 Ash Street", "Tuscon", "AZ", "09876", 24.00, .75, 4.00);
//cout << fixed << setprecision(2);
cout << "To ship a box with overnight delivery\n";
//cout << "The sender " << box.getSenderName()<< "\n";
//cout << " " << box.getSenderAddress() << "\n";
//cout << " " << box.getSenderCity() << " " << box.getSenderState() << " " << box.getSenderZipcode() << "\n";
//cout << "The recipient " << box.getRecipientName()<< "\n";
//cout << " " << box.getRecipientAddress() << "\n";
//cout << " " << box.getRecipientCity() << " " << box.getRecipientState() << " " << box.getRecipientZipcode() << "\n";
//cout << "The cost is $ " << box.CalculateCost << "\n";
cout << "\n\n";
cout << "To ship a parcel with 2 day delivery\n";
//cout << "The sender " << parcel.getSenderName()<< "\n";
//cout << " " << parcel.getSenderAddress() << "\n";
//cout << " " << parcel.getSenderCity() << " " << parcel.getSenderState() << " " << parcel.getSenderZipcode() << "\n";
//cout << "The recipient " << parcel.getRecipientName()<< "\n";
//cout << " " << parcel.getRecipientAddress() << "\n";
//cout << " " << parcel.getRecipientCity() << " " << parcel.getRecipientState() << " " << parcel.getRecipientZipcode() << "\n";
//cout << "The cost is $ " << parcel.CalculateCost << "\n";
}