资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
编写程序,计算圆柱体、球体、正方体和长方体的表面积和体积。#include stdafx.h#includeiostream.hclass Shapeprotected:int x,y,h;public:void set(int i=0,int j=0,int z=0)x=i;y=j;h=z;virtual void area()=0;virtual void volume()=0;class Cylinder:public Shapepublic:void area()cout圆柱体的表面积为:2*3.14*x*x+2*3.14*x*yendl;void volume()cout圆柱体的体积为:3.14*x*x*yendl;class Globe:public Shapepublic:void area()cout球体的表面积为:4*3.14*x*xendl;void volume()cout球体的体积为:4/3*3.14*x*x*xendl;class Cuboid:public Shapepublic:void area()cout长方体的表面积为:2*x*y+2*x*h+2*y*hendl;void volume()cout长方体的体积为:x*y*hendl;class Cube:public Shapepublic:void area()cout正方体的表面积为:6*x*xendl;void volume()cout正方体的体积为:x*x*xset(5,2);p-area();p-volume();Globe g;p=&g; p-set(3);p-area();p-volume();Cuboid l;p=&l;p-set(2,3,5);p-area();p-volume();Cube f;p=&f;p-set(5);p-area();p-volume();return 0;
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号