// File: cubetest.cpp // // Use the Cube class. #include #include "Box.h" #include "Cube.h" using namespace std ; int main() { Cube c1 ; // use default constructor Cube c2(1.2) ; // use alternate constructor Box b ; int r ; cout << "c1: " ; c1.identify() ; cout << "c2: " ; c2.identify() ; cout << "b: " ; b.identify() ; Box::report() ; cout << "\nCompare\n" ; r = compare(c1,c2) ; if (r < 0) { cout << "Cube c1 fits inside cube c2" << endl ; } else if (r > 0) { cout << "Cube c2 fits inside cube c1" << endl ; } else { cout << "Cubes c1 and c2 are incomparable" << endl ; } r = compare(b,c1) ; // can compare cubes and boxes! if (r < 0) { cout << "Box b fits inside cube c1" << endl ; } else if (r > 0) { cout << "Cube c1 fits inside box b" << endl ; } else { cout << "Box b and cube c1 are incomparable" << endl ; } // Members of the Box class are accessible through cubes because // the Cube class is a public derivation of the Box class. // cout << "\nGrow c1" << endl ; c1.grow() ; c1.identify() ; cout << "Volume of c1 is now " << c1.volume() << endl ; cout << "\nShrink c2" << endl ; c2.shrink() ; c2.identify() ; cout << "Volume of c2 is now " << c2.volume() << endl ; Box::report() ; }