// File: Package.cpp // // Implementation of the Package derived class #include #include "Package.h" using namespace std ; // Default constructor // Package::Package() { #ifndef NDEBUG cerr << "Default Package constructor, Serial Number = " << serial() << endl ; #endif length = height = width = 0.0 ; // sides have length 0.0 by default inside = NULL ; } // Alternate constructor: create a package with specified sides // Package::Package(float len, float ht, float wd) : Box(len, ht, wd) // use member initializer { #ifndef NDEBUG cerr << "Alternate Package constructor, Serial Number = " << serial() << endl ; #endif inside = NULL ; } // Destructor // Package::~Package() { #ifndef NDEBUG cerr << "Package destructor, Serial Number = " << serial() << endl ; #endif // Do nothing } // report vital stats for package // void Package::identify() { cout << "This package has length=" << length << ", height=" << height << " & width=" << width << endl ; if (inside == NULL) { cout << " This package is empty" << endl ; } else { cout << " This package contains the following:" << endl ; inside->identify() ; } } // store item in this package, if the item fits and if this // package is empty. // bool Package::Store (Package *item) { int r ; if (inside != NULL) { return 0 ; } r = compare(*this, *item) ; // "this" means this package if (r > 0) { inside = item ; return true ; } else { return false ; } } // Return contents and set inside to NULL // Package *Package::Empty() { Package *temp ; temp = inside ; inside = NULL ; return temp ; } // Return stored item // Package *Package::Content() { return inside ; }