1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
class Person
{
private:
string Name,
Address,
State,
City,
Zip;
public:
friend istream &operator>> (istream &, Person &);
friend class Package;
friend class TwoDayPackage;
friend class OvernightPackage;
};
class Package
{
protected:
Person Sender;
Person Reciever;
double CostPerOz;
int WeightOz;
static int NumberProcessed;
public:
friend ostream &operator<< (ostream &, Package);
friend istream &operator>> (istream &, Package &);
int getProcessed(){return NumberProcessed;}
void addProcessed(){NumberProcessed++;}
};
/**********************************************
* Start of Package code.h *
* *
* *
* *
**********************************************/
ostream &operator<< (ostream &oParam, Package pParam)
{
oParam << left << "Package #" << pParam.NumberProcessed << endl;
oParam << left << "\nSender:" << endl;
oParam << right << setw(20) << "Name: " << left << pParam.Sender.Name << endl;
oParam << right << setw(20) << "Address: " << left << pParam.Sender.Address << endl;
oParam << right << setw(20) << "City, State, Zip: " << left << pParam.Sender.City
<< ", " << pParam.Sender.State
<< " " << pParam.Sender.Zip << endl;
oParam << "\n" << endl;
oParam << left << "Reciver:" << endl;
oParam << right << setw(20) << "Name: " << left << pParam.Reciever.Name << endl;
oParam << right << setw(20) << "Address: " << left << pParam.Reciever.Address << endl;
oParam << right << setw(20) << "City, State, Zip: " << left << pParam.Reciever.City
<< ", " << pParam.Reciever.State
<< " " << pParam.Reciever.Zip << endl;
oParam << "Shipping Cost for " << pParam.WeightOz << " oz. @$" << fixed << setprecision(2) << pParam.CostPerOz << "/ounce is " << (pParam.CostPerOz * (double)pParam.WeightOz) << endl;
oParam << "\n\n" << endl;
return oParam;
}
istream &operator>> (istream &iParam, Package &pParam)
{
iParam >> pParam.WeightOz;
iParam.ignore(10, '\n');
iParam >> pParam.CostPerOz;
iParam.ignore(10, '\n');
iParam >> pParam.Sender;
iParam >> pParam.Reciever;
return iParam;
}
|