#ifndef __cube #define __cube #include "body.h" class cube : public body { public: cube (float); char* identify(); float GetVolume(); float GetSurface(); protected: // a cube has just one length to fully describe it... float length; }; #endif
#include <iostream.h> #include "cube.h" char* cube::identify() { return "Cube"; }; float cube::GetVolume() { // volume is length**3 return length*length*length; } float cube::GetSurface() { // 6 square sides of length return 6.*length*length; } cube::cube(float x) { length = x; }