您的位置:首页 > 其它

编写一个基于对象的程序,求长方形的体积

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

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  对象