4950. 编一个基于对象的程序,求长方柱的体积
Constraints
Time Limit: 1 secs, Memory Limit: 256 MB
Description
编一个基于对象的程序,求长方柱的体积 | 长方柱数据成员包括length、width、height,要求用成员函数实现以下功能: |
1,输入3个长方体的长宽高;
2,计算长方柱的体积;
3,输出3个长方体的体积。
Sample Input
4 4 4 1 2 3 7 8 10
Sample Output
64 6 560
考察类,没什么特别的,调用类成员函数的时候别忘了input后面的括号什么的…以后这种题就习惯性用double声明变量吧 好习惯还是要慢慢养成的。
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();
}
//system("pause");
return 0;
}