/* File: package.C Implementation of the Package derived class */ #include #include #include "package.h" /* default constructor */ Package::Package() { length = height = width = 0.0 ; /* sides have length 0.0 by default */ inside = NULL ; } /* create a package with specified sides */ Package::Package(float len, float ht, float wd) { length = len ; height = ht ; width = wd ; inside = NULL ; } /* report vital stats for package */ void Package::identify() { printf("This package has length=%f, height=%f & width=%f\n", length, height, width) ; if (inside == NULL) { printf(" This package is empty\n") ; } else { printf(" This package contains the following:\n") ; inside->identify() ; } } /* store item in this package, if the item fits and if this package is empty. return 1 if item fits 0 otherwise */ int 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 1 ; } else { return 0 ; } } /* 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 ; }