C++程序设计实验报告(七十二)---第十三周任务四
来源:互联网 发布:win10 ubuntu子系统 编辑:程序博客网 时间:2024/04/28 06:56
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2012, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:抽象类CSolid
* 作 者: 刘镇
* 完成日期: 2012 年 05 月 13 日
* 版 本 号: 1.068
* 对任务及求解方法的描述部分
* 输入描述: ......
* 问题描述: ......
* 程序输出: ......
* 程序头部的注释结束
*/
#include<iostream>using namespace std;const double PI = 3.14159;class CSolid{public:virtual double area() const =0;virtual double volume() const =0;};class CCube: public CSolid{public:CCube(double length);virtual double area() const;virtual double volume() const;void show_area();void show_volume();protected:double length;};class CBall: public CSolid{public:CBall(double radius);virtual double area() const;virtual double volume() const;protected:double radius;};class CCylinder: public CSolid{public:CCylinder(double height, double radius);virtual double area() const;virtual double volume() const;void show_area();void show_volume();protected:double height;double radius;};CCube::CCube(double length){this->length = length;}double CCube::area() const{return (this->length * this->length * 6);}double CCube::volume() const{return (this->length * this->length * this->length);}CBall::CBall(double radius){this->radius = radius;}double CBall::area() const{return (4 * PI * this->radius * this->radius);}double CBall::volume() const{return (PI * this->radius * this->radius * this->radius * 3 / 4);}CCylinder::CCylinder(double height, double radius){this->height = height;this->radius = radius;}double CCylinder::area() const{return (2 * (PI * this->radius * this->radius) + this->height * (2 * PI * this->radius));}double CCylinder::volume() const{return (PI * this->radius * this->radius * this->height);}int main(){CSolid *p;CCube ccube(5);CBall cball(4);CCylinder ccylinder(10, 2);p = &ccube;cout << "正方体的表面积是:" << p->area() << endl;cout << "正方体的体积是:" << p->volume() << endl;p = &cball;cout << "球体的表面积是:" << p->area() << endl;cout << "球体的体积是:" << p->volume() << endl;p = &ccylinder;cout << "圆柱体的表面积是:" << p->area() << endl;cout << "圆柱体的体积是:" << p->volume() << endl;system("pause");return 0;}
运行结果:
- C++程序设计实验报告(七十二)---第十三周任务四
- 第十三周实验报告 任务四
- C++程序设计实验报告(六十九)---第十三周任务一
- C++程序设计实验报告(七十)---第十三周任务二
- C++程序设计实验报告(七十一)---第十三周任务三
- 第十三周实验报告四
- C++程序设计实验报告(三十四)---第三周任务四
- C++程序设计实验报告(四十二)---第五周任务四
- C++程序设计实验报告(四十六)---第六周任务四
- C++程序设计实验报告(五十六)---第八周任务四
- C++程序设计实验报告(六十八)---第十二周任务四
- C++程序设计实验报告(八十三) --- 第十六周任务四
- 第十三周实验报告(任务一)
- 第十三周实验报告(任务二)
- 第十三周实验报告(任务三)
- 《第十三周实验报告任务1》
- 第十三周实验报告 任务一
- 第十三周实验报告 任务三
- C++程序设计实验报告(七十一)---第十三周任务三
- 【动态规划】poj1952 buy low,buy lower
- java useDelimiter的使用
- 解决xcode4.2安装cocos2d-x失败悲剧权限问题 Permissions Issues
- Catalan数——卡特兰数
- C++程序设计实验报告(七十二)---第十三周任务四
- 程序员必会sql28技[百度资深架构师王历继含泪推荐]
- .NET下利用IP地址查询接口来查询IP归属地
- 关于在周末组织团队学习
- tracert 命令(pathping)
- 设计模式之迪米特法则(最少知识原则)学习
- STM32数据位错位问题研究
- 平方根升余弦滤波器
- 关于jquery插件placeholder 1.3在chrome和safari下点击后不消失的解决方法