/** Copyright and version declaration section of the Program * Copyright (c) 2013, student * All rightsreserved from computer College of Yantai University. * Prepared by: Li Yang * completed on: July 15, May 31, 2013 * version: v1.0 * input Description: none * Problem description: Output surface area and volume */# include <iostream> using namespace std; # define PI 3.1415926 class CSolid // declare the abstract base class shape {public: virtual double area () = 0; // The pure virtual function virtual double volume () = 0; // pure virtual function}; class CCube: public CSolid // declare CCube class {public: CCube (double l): length (l) {} virtual double area () // area {return 6 * length;} virtual double volume () // volume {return length * length;} private: double length ;}; class CBall: public CSolid // declare the CBall class {public: CBall (double r): radius (r) {} virtual double area () // area {return 4 * PI * radius;} virtual double volume () // volume {return PI * radius * 4/3;} private: double radius ;}; class CCylinder: public CSolid // declare CCylinder class {public: CCylinder (double r, double h): radius (r), heigth (h) {} virtual double area () // area {return 2*2 * PI * radius + 2 * PI * radius * heigth;} virtual double volume () // volume {return PI * radius * heigth;} private: double radius, heigth;}; int main () {CSolid * p; CCube a (3 ); cout <"cube length: 3" <endl; p = & a; cout <"surface area of the cube:" <p-> area () <endl; cout <"volume of the cube:" <p-> volume () <endl; cout <endl; CBall B (4 ); cout <"sphere radius is 4" <endl; p = & B; cout <"surface area of the sphere:" <p-> area () <endl; cout <"volume of the sphere:" <p-> volume () <endl; cout <endl; CCylinder c (1.5, 4 ); cout <"the bottom radius and height of the cylinder are 1.5, 4 respectively." <endl; p = & c; cout <"surface area of the cylinder: "<p-> area () <endl; cout <" volume of the cylinder: "<p-> volume () <endl; return 0 ;}