第十三周任务(四)
来源:互联网 发布:网络舆论发展的因素 编辑:程序博客网 时间:2024/06/05 17:27
#include <iostream>using namespace std;const double pi = 3.1415926;class CSolid{public:virtual double area() const = 0;virtual double volume() const = 0;};class CCube:public CSolid{public:CCube(double l):len(l){}~CCube();double area() const;double volume() const;private:double len;};class CBall:public CSolid{public:CBall(double r):rang(r){}~CBall();double area() const;double volume() const;private:double rang;};class CCylinder:public CSolid{public:CCylinder(double R,double h):Rang(R),high(h){}~CCylinder();double area() const;double volume() const;private:double Rang;double high;};CCube::~CCube(){}double CCube::area() const{return 6*len*len;}double CCube::volume() const{return len*len*len;}CBall::~CBall(){}double CBall::area() const{return 4*pi*rang*rang;}double CBall::volume() const{return 1.33*pi*rang*rang*rang;}CCylinder::~CCylinder(){}double CCylinder::area() const{return 2*pi*Rang*high+2*pi*Rang*Rang;}double CCylinder::volume() const{return pi*Rang*Rang*high;}int main( ) { CSolid *p; double s,v; CCube x(30); cout<<"立方体边长为30"<<endl; p=&x; s=p->area( ); v=p->volume( ); cout<<"表面积:"<<s<<endl; cout<<"体积:"<<v<<endl; cout<<endl; CBall y(4.5); cout<<"球体半径为4.5"<<endl; p=&y; s=p->area( ); v=p->volume( ); cout<<"表面积:"<<s<<endl; cout<<"体积:"<<v<<endl; cout<<endl; CCylinder z(10,20); cout<<"圆柱体底面半径、高分别为10, 20"<<endl; p=&z; s=p->area( ); v=p->volume( ); cout<<"表面积:"<<s<<endl; cout<<"体积:"<<v<<endl; cout<<endl; system("pause"); return 0; } /*int main(){CCube c1(1);CBall c2(2);CCylinder c3(3,4);CSolid *p;p = &c1;cout << "正方体的表面积是:" << p->area() << "体积是:" << p->volume() <<endl;p = &c2;cout << "球体的表面积是:" << p->area() << "体积是:" << p->volume() << endl;p = &c3;cout << "圆柱体的表面积是:" << p->area() << "体积是:" << p->volume() << endl;system("pause");return 0;}*/
感悟:这个任务其实就是任务三的改变而已,没有什么,就是主函数那的问题了,定义指针类的问题,搞定这一切万事大吉,找到书了,所以OK了,但还是用了老师的主函数,看着比我的好多了,我的就陪衬吧。
- 第十三周任务(四)
- 第十三周 任务四
- 第十三周 任务四
- 第十三周任务四(抽象类CSolid)
- 第十三周实验报告 任务四
- 第十三周任务(1)
- 第十三周任务(一)
- 第十三周任务(二)
- 第十三周任务(二)
- 第十三周任务(三)
- 第十三周任务(三)
- 第十三周任务(二)
- 第十三周任务(1)
- 第十三周任务(三)
- C++程序设计实验报告(七十二)---第十三周任务四
- 第十三周任务四之抽象类CSolid
- 第十三周实验报告(任务一)
- 第十三周实验报告(任务二)
- 使用基站、wifi实现定位
- 在Linux环境下编写和使用静态函数库
- X64 Deep Dive
- 图像处理之浮雕算法
- c 内存小函数
- 第十三周任务(四)
- hduoj 1754 I Hate it
- sprintf用法简介
- DataGrid的数据绑定
- JAVA Comparable 和Comparator用法
- 逻辑地址与物理地址转换 和 字节对齐
- 省赛小结
- 风电预测统计模型和流体场模型
- 嵌入式Linux工程师认证考试大纲