题目:求3个长方体的体积,请编一个基于对象的程序。数据成员包括length(长)、width(宽)、height(高)。
要求:用成员函数实现以下功能:
- 由键盘分别输入3个长方体的长、宽、高。
- 计算长方体的体积。
- 3.输出3个长方体的体积。
-
#include<iostream> using namespace std; class cuboid { private: int length; int width; int height; int v; public: int sandc() { cin >> length >> width >> height; v= length * width * height; return v; } void getV() { cout << "cuboid volume is" << v << endl; } }; int main() { cuboid c1, c2, c3; c1.sandc(); c2.sandc(); c3.sandc(); c1.getV(); c2.getV(); c3.getV(); }