Created
November 28, 2012 11:37
-
-
Save anonymous/4160639 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Package.h" | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
Package::Package( const string &sname, const string &saddress, const string &scity, const string &sstate, const string &szip, const string &rname, const string &raddress, const string &rcity, const string &rstate, const string &rzip, double weight, double shippingCost ) | |
{ | |
sName = sname; | |
sAddress = saddress; | |
sCity = scity; | |
sState = sstate; | |
sZip = szip; | |
rName = rname; | |
rAddress = raddress; | |
rCity = rcity; | |
rState = rstate; | |
rZip = rzip; | |
setWeight(weight); | |
setShippingCost(shippingCost); | |
} | |
// sender set functions | |
void Package::setSName( const string &sname ) | |
{ | |
sName = sname; | |
} | |
void Package::setSAddress( const string &saddress ) | |
{ | |
sAddress = saddress; | |
} | |
void Package::setSCity( const string &scity ) | |
{ | |
sCity = scity; | |
} | |
void Package::setSState( const string &sstate ) | |
{ | |
sState = sstate; | |
} | |
void Package::setSZip( const string &szip ) | |
{ | |
sZip = szip; | |
} | |
//recipient set functions | |
void Package::setRName( const string &rname ) | |
{ | |
rName = rname; | |
} | |
void Package::setRAddress( const string &raddress ) | |
{ | |
rAddress = raddress; | |
} | |
void Package::setRCity( const string &rcity ) | |
{ | |
rCity = rcity; | |
} | |
void Package::setRState( const string &rstate ) | |
{ | |
rState = rstate; | |
} | |
void Package::setRZip( const string &rzip ) | |
{ | |
rZip = rzip; | |
} | |
//sender get functions | |
string Package::getSName() const | |
{ | |
return sName; | |
} | |
string Package::getSAddress() const | |
{ | |
return sAddress; | |
} | |
string Package::getSCity() const | |
{ | |
return sCity; | |
} | |
string Package::getSState() const | |
{ | |
return sState; | |
} | |
string Package::getSZip() const | |
{ | |
return sZip; | |
} | |
//recipient set functions | |
string Package::getRName() const | |
{ | |
return rName; | |
} | |
string Package::getRAddress() const | |
{ | |
return rAddress; | |
} | |
string Package::getRCity() const | |
{ | |
return rCity; | |
} | |
string Package::getRState() const | |
{ | |
return rState; | |
} | |
string Package::getRZip() const | |
{ | |
return rZip; | |
} | |
//weight and calc functions | |
void Package::setWeight( double w ) | |
{ | |
if ( w > 0) | |
weight = w; | |
else | |
throw invalid_argument( "Number invalid" ); | |
} | |
double Package::getWeight() const | |
{ | |
return weight; | |
} | |
void Package::setShippingCost( double ship ) | |
{ | |
if ( ship > 0) | |
shippingCost = ship; | |
else | |
throw invalid_argument( "Number invalid" ); | |
} | |
double Package::getShippingCost() const | |
{ | |
return shippingCost; | |
} | |
double Package::calculateCost() const | |
{ | |
return ( weight * shippingCost ); | |
} | |
TwoDayPackage::TwoDayPackage ( const string &sname, const string &saddress, const string &scity, const string &sstate, const string &szip, const string &rname, const string &raddress, const string &rcity, const string &rstate, const string &rzip, double weight, double shippingCost, double f ) | |
:Package( sName, sAddress, sCity, sState, sZip, rName, rAddress, rCity, rState, rZip, weight, shippingCost), | |
fee(f) | |
{ | |
} | |
void TwoDayPackage::setFee( double f ) | |
{ | |
fee = f; | |
} | |
double TwoDayPackage::getFee() | |
{ | |
return fee; | |
} | |
double TwoDayPackage::calculateCost(double weight,double shippingCost, double fee) | |
{ | |
return ( weight * shippingCost ) + fee; | |
} | |
OvernightPackage::OvernightPackage ( const string &sname, const string &saddress, const string &scity, const string &sstate, const string &szip, const string &rname, const string &raddress, const string &rcity, const string &rstate, const string &rzip, double weight, double shippingCost, double add ) | |
:Package( sName, sAddress, sCity, sState, sZip, rName, rAddress, rCity, rState, rZip, weight, shippingCost), | |
additionalFee(add) | |
{ | |
} | |
void OvernightPackage::setAdditionalFee( double add ) | |
{ | |
additionalFee = add; | |
} | |
double OvernightPackage::getAdditionalFee() | |
{ | |
return additionalFee; | |
} | |
double OvernightPackage::calculateCost(double weight,double shippingCost, double additionalFee) | |
{ | |
return ( weight * shippingCost ) + ( weight*additionalFee ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
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 ); | |
// sender functions | |
void setSName( const string & ); | |
string getSName() const; | |
void setSAddress( const string & ); | |
string getSAddress() const; | |
void setSCity( const string & ); | |
string getSCity() const; | |
void setSState( const string & ); | |
string getSState() const; | |
void setSZip( const string & ); | |
string getSZip() const; | |
// recipient functions | |
void setRName( const string & ); | |
string getRName() const; | |
void setRAddress( const string & ); | |
string getRAddress() const; | |
void setRCity( const string & ); | |
string getRCity() const; | |
void setRState( const string & ); | |
string getRState() const; | |
void setRZip ( const string & ); | |
string getRZip() const; | |
// weight and calc functions | |
void setWeight( double ); | |
double getWeight() const; | |
void setShippingCost( double ); | |
double getShippingCost() const; | |
double calculateCost() const; | |
protected: | |
string sName; | |
string sAddress; | |
string sCity; | |
string sState; | |
string sZip; | |
string rName; | |
string rAddress; | |
string rCity; | |
string rState; | |
string rZip; | |
double weight; | |
double shippingCost; | |
}; | |
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 ); | |
void setFee( double ); | |
double getFee(); | |
double calculateCost( double ,double, double); | |
private: | |
double fee; | |
}; | |
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 = 0.0, double = 0.0, double = 0.0 ); | |
void setAdditionalFee( double ); | |
double getAdditionalFee(); | |
double calculateCost( double ,double, double); | |
private: | |
double additionalFee; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Package.h" | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main() | |
{ | |
Package package1( "First Last", "Address", "City", "State", "12345", "First Last2", "Address2", "City2", "State2", "54321", 1, 1); | |
TwoDayPackage package2( "First Last", "Address", "City", "State", "12345", "First Last2", "Address2", "City2", "State2", "54321", 1, 1, 1 ); | |
OvernightPackage package3( "First Last", "Address", "City", "State", "12345", "First Last2", "Address2", "City2", "State2", "54321", 1, 1, 1); | |
cout << "Package-delivery calculator, please enter the following information:\nSender's name, address, city, state, and zip code.\n\n"; | |
cout << "Next enter the following information:\nRecipient's name, address, city, state, and zip code."; | |
cin >> package1.setSName; | |
cout << "\n\n"; | |
cout << "Sender's:\nName:" << package1.getSName() << "\nAddress:" << package1.getSAddress() << "\nCity:" << package1.getSCity() << "\nState:" << package1.getSState() << "\nZip Code:" << package1.getSZip(); | |
cout << "\n\n"; | |
cout << "Receiver's:\nName:" << package1.getRName() << "\nAddress:" << package1.getRAddress() << "\nCity:" << package1.getRCity() << "\nState:" << package1.getRState() << "\nZip Code:" << package1.getRZip(); | |
cout << "\n\n"; | |
cout << "Price for Regular Shipping at ?$/ounce: $" << package1.calculateCost(); | |
cout << "\nPrice for Two Day Shipping: $" << package2.TwoDayPackage::calculateCost(5, 5, 5); | |
cout << "\nPrice for Overnight Shipping: $" << package3.OvernightPackage::calculateCost(5, 5, 5) << "\n"; | |
system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment