编写一个基于对象的程序,求长方形的体积
2016-04-11 22:26
405 查看
长方柱数据成员包括length、width、height,要求用成员函数实现以下功能:
1,输入3个长方体的长宽高;
2,计算长方柱的体积;
3,输出3个长方体的体积。
Input
1 2 3
3 3 3
10 10 10
Output
6
27
1000
1,输入3个长方体的长宽高;
2,计算长方柱的体积;
3,输出3个长方体的体积。
Input
1 2 3
3 3 3
10 10 10
Output
6
27
1000
#include<iostream> using namespace std; class rectangle{ public: //初始化 rectangle(){ length = width = height = 0; } //输入数据 void input(){ cin >> length >> width >> height; } //输出结果 void output(){ volume = length * width * height; cout << volume << endl; } private: double length; double width; double height; double volume; }; int main() { rectangle a[3]; for(int i = 0; i < 3; i++){ a[i].input(); a[i].output(); } return 0; }
相关文章推荐
- Python动态类型的学习---引用的理解
- 土人系列AS入门教程 -- 对象篇
- C#托管堆对象实例包含内容分析
- C#实现获取不同对象中名称相同属性的方法
- javascript asp教程第十一课--Application 对象
- PowerShell中使用Out-String命令把对象转换成字符串输出的例子
- VBS教程:对象-正则表达式(RegExp)对象
- C#检查指定对象是否存在于ArrayList集合中的方法
- sql2008启动代理未将对象应用到实例解决方案
- C#编程自学之类和对象
- C++中对象的常引用、动态建立和释放相关知识讲解
- php中将一个对象保存到Session中的方法
- php对象和数组相互转换的方法
- PHP中把对象转换为关联数组代码分享
- C#写入对象或集合类型数据到xml文件的方法
- C#利用反射来判断对象是否包含某个属性的实现方法
- ASP.NET中使用Application对象实现简单在线人数统计功能
- asp提示Server 对象 错误 ASP 0178 : 80070005
- Javascript 对象的解释
- JavaScript对象、属性、事件手册集合方便查询