长方体继承自矩形
2015-06-25 21:59
246 查看
问题及代码:
运行结果:
/*。 *Copyright(c)2014,烟台大学计算机学院 *All right reserved, *文件名:test.cpp *作者:liu_feng_zi_ *完成日期:2015年6月25日 *版本号:v1.0 *问题描述:长方体继承自矩形 *输入描述: *程序输出: */ #include <iostream> using namespace std; class Rectangle //矩形类 { private: int length; //矩形的长和宽 int width; public: Rectangle(); Rectangle(int l,int w); //构造函数,l、w分别代表长和宽 int getArea(); //求面积 }; class Bulk: public Rectangle //立方体类 { public: Bulk(); //默认构造函数 Bulk(int l, int w,int h); //带参数的构造函数 int getVolume(); private: int height; //高,长、宽继承自基类 }; Rectangle::Rectangle():length(0),width(0) {} Rectangle::Rectangle(int l,int w):length(l),width(w) {} int Rectangle::getArea() { return length*width; } //Bulk类的成员函数 Bulk::Bulk():Rectangle(),height(0) {} Bulk::Bulk(int l, int w,int h):Rectangle(l,w),height(h) {} int Bulk::getVolume() { return (getArea()*height); }; int main() { int x,y,z; cin>>x>>y>>z; Bulk b(x,y,z); cout<<b.getVolume()<<endl; return 0; }
运行结果:
相关文章推荐
- 手斧Linux – 从LFS到Funtoo (48)
- 逻辑与&&的小陷阱
- "XX cannot be resolved to a type "eclipse报错及解决说明
- 用友T6-ERP系统技术解析(三)销售发货单(一)
- 回答自己的问题
- sass 学习
- OpenGLES2.0着色器语言教程
- 手斧Linux – 从LFS到Funtoo (47)
- Android存储数据的5种方式
- MyISAM与InnoDB两者之间区别与选择,详细总结,性能对比
- 问题:eclipse xml文件中按alt+/没有提示信息?
- 体验CSDN-Markdown
- 正则表达式
- Android greenDAO入门
- 分布式设计与开发 memcached分布式
- 手斧Linux – 从LFS到Funtoo (46)
- 关于undo log格式中事务ID和undo_no
- Alt+/ 提示不管用?
- Oracle备份基本名词
- 黑马程序员——Java基础:集合类、泛型