// File: box1.C // One implementation of class Box. #include #include #include "box1.h" // Initialize new box with random dimensions. // Note: constructors have no return type! not even void Box::Box() { length = random() ; height = random() ; width = random() ; } // Report vital stats void Box::identify() { if (length == 0.0 || height == 0.0 || width == 0.0) { cout << "I am an invisible box\n" ; } else { cout << "I am a box with length=" << length << ", height=" << height << " and width=" << width << "\n" ; } } // Compute box volume float Box::volume() { return length * height * width ; } // Double each dimension void Box::grow() { length = length * 2 ; height = height * 2 ; width = width * 2 ; } // Halve each dimension void Box::shrink() { length = length / 2 ; height = height / 2 ; width = width / 2 ; } // return random value between 1.0 and 10.0 float Box::random() { double r ; r = drand48() * 9.0 + 1.0 ; return (float) r ; }