/*
*copyright (c) 2015, College of Computer Science, Yantai University
*all rights reserved.
* File name: Week 13th (abstract class shared by the stereoscopic group)
* Wangzhong
* Completion Date: 2015.6.02
* Version: v1.0
*
* Description of the problem: Design an abstract class Csolid. Contains two pure virtual functions which are useful for surface area and volume. Design derived classes Ccube, Cball, Ccylinder. represent cubes, spheres, and cylinders, respectively.
In the main () function, define Csolid *p; (P is a pointer to the base class, and the base class is an abstract class).
Requires the use of this P-pointer. The surface area and volume of the object of cube, sphere and cylinder can be obtained.
* Input Descriptive narrative:
* Program output:
#include <iostream>using namespace Std;class csolid{public:virtual Double volume () = 0; Virtual double area () = 0;}; Class Ccube:public Csolid{public:ccube (Double A): B (a) {} double volume () {return b*b*b; } double Area () {return 6*b*b; }protected:double b;}; Class Cball:public Csolid{public:cball (Double A): R1 (a) {} double volume () {return (4*3.14*R1*R1*R1)/3; } double Area () {return 4*3.14*r1*r1; }protected:double R1;}; Class Ccylinder:public Csolid{public:ccylinder (double a,double b): R2 (a), H (b) {} double volume () {return 3 .14*r2*r2*h; } double Area () {return (6.28*R2*H+6.28*R2*R2); }protected:double R2; Double h;}; int main () {csolid *p; Ccube C1 (1); Cball C2 (1); Ccylinder C3 (a); p=&c1; Cout<<p->volume () << ""; Cout<<p->area () <<endl; p=&c2; Cout<<p->volume () << ""; Cout&lT;<p->area () <<endl; p=&c3; Cout<<p->volume () << ""; Cout<<p->area () <<endl; return 0;}
Write your own, one-time success, don't mention how cool!!
!
13th Week (abstract class shared by the three-dimensional group)