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