/** Copyright (c) 2013, School of Computer Science, Yantai University * All Rights Reserved. * file name: test. CPP * Author: Qiu xuewei * Completion Date: July 15, June 2, 2013 * version: V1.0 * input Description: none * Problem description: * program output: * Problem Analysis: * Algorithm Design: * // * design an abstract class csolid, which contains two pure virtual functions to evaluate the surface area and volume. The ccube, cball, and ccylinder classes are designed to represent cubes, sphere, and cylinder. In the main () function, define the base class pointer P (csolid * P;) and use the P pointer to output the surface area and volume of the cube, sphere, and cylindrical objects. */# Include <iostream> using namespace STD; Class csolid // base class {public: Virtual double area () const = 0; // pure virtual function, evaluate the area virtual double volume () const = 0; // pure virtual function, evaluate the volume}; Class ccube: Public csolid // cube {public: ccube (double W ): width (w) {} virtual double area () const // cube surface area {return 6 * width;} virtual double volume () const // cube volume {return width * width;} PRIVATE: double width;}; Class cball: Public csolid // sphere {public: cball (double R0 ): R (R0) {} virtual double area () const // sphere surface area {return 4*3.14 * r;} virtual double volume () const // volume of the sphere {return (4*3.14 * r)/3;} PRIVATE: Double R ;}; class ccylinder: Public csolid {public: ccylinder (double r0, double H): R (R0), height (H) {} virtual double area () const {return 2*(3.14 * r) + height * 3.14 * r * 2;} virtual double volume () const {return height * 3.14 * r;} PRIVATE: Double R, height;}; int main () {csolid * P; double S, V; ccube C1 (30); P = & C1; S = p-> area (); V = p-> volume (); cout <"the cube surface area with a side length of 30 is:" The size of the cube with a side length of 30 <S <Endl; cout <"side length of 30 is: "<v <Endl; cball C2 (5); P = & C2; S = p-> area (); V = p-> volume (); cout <"the surface area of the ball with a radius of 5 is:" The size of the ball with a radius of 5 is: "<v <Endl; ccylinder C3 (5, 4); P = & C3; S = p-> area (); V = p-> volume (); cout <"the surface area of a cylindrical with a radius of 5 and a height of 4 is:" <S <Endl; cout <"the volume of a cylindrical with a radius of 5 and a height of 4 is: "<v <Endl ;}