6.11虚基类
来源:互联网 发布:iphone库存软件 编辑:程序博客网 时间:2024/06/07 23:54
#include<iostream>using namespace std;class shape{ public: virtual void SurfaceArea(){ } virtual void Volume(){ }};class Cube:public shape{ double length; public: Cube(double length):length(length){ } void SurfaceArea(){ cout<<"表面积是:"<<length*length*6<<endl; } void Volume(){ cout<<"体积是:"<<length*length*length<<endl; }};class Cylinder:public shape{ double radius; double heigth; public: Cylinder(double radius,double heigth):radius(radius),heigth(heigth){ } void SurfaceArea(){ cout<<"表面积是:"<<(radius*2*3.14)*heigth+radius*radius*3.14*2<<endl; } void Volume(){ cout<<"体积是:"<<radius*radius*3.14*heigth<<endl; }};class Ball:public shape{ double radius; public: Ball(double radius):radius(radius){ } void SurfaceArea(){ cout<<"表面积是:"<<4*3.14*radius*radius<<endl; } void Volume(){ cout<<"体积是:"<<4.0/3.0*3.14*radius*radius*radius<<endl; }};int main(void){ shape *s; s = new Cube(5); s->SurfaceArea(); s->Volume(); s = new Cylinder(1,1); s->SurfaceArea(); s->Volume(); s = new Ball(2); s->SurfaceArea(); s->Volume(); return 0;}
0 0
- 6.11虚基类
- 6.11
- 6.11
- 6.11
- 6.11
- 6.11
- 虚基类
- 虚基类
- 虚基类
- 虚基类
- 虚基类
- 虚基类
- 虚基类
- 虚基类
- 虚基类
- 虚基类
- 虚基类
- 虚基类
- 多线程问题与double-check小结
- css层叠样式详解
- 代码混淆详解
- swift可选链和类型转换
- Geometry类详解
- 6.11虚基类
- VS2010和QT中编码不一样
- 2014.7.23 内存分析_栈_堆_栈帧
- 一个简单的小程序演示Unity的三种依赖注入方式
- 实现多国语言的几个小知识
- EasyUI常见几种控件动态渲染的示范代码
- 【技♂巧】bzoj1257余数之和
- git忽略对已入库文件的修改
- urllib2.urlopen超时问题