您好,欢迎访问三七文档
#includeiostreamusingnamespacestd;classshape{public:virtualdoublearea()=0;};classRectangle:publicshape{private:doubleW,H;public:Rectangle(doublew,doubleh){W=w;H=h;}doublearea(){returnW*H;}};constPI=3.14159;classCircle:publicshape{private:doubleX,Y,R;public:Circle(doublex,doubley,doubler){X=x;Y=y;R=r;}doublearea(){returnPI*R*R;}};voidmain(){RectangleW(3,5);shape*P;P=&W;coutP-area()endl;CircleC(3,4,5);shape&U=C;coutU.area()endl;}
本文标题:定义一个shape抽象类-派生出Rectangle类和Circle类-计算各派生类对象的面积area
链接地址:https://www.777doc.com/doc-5822919 .html