PTA立方体类Box

184 阅读1分钟

定义立方体类Box,数据成员有长宽高且都是整数,构造函数初始化数据成员,成员函数计算体积,主函数中输入长宽高,输出立方体体积。

输入格式:

输入立方体的长宽高,中间用空格分隔。

输出格式:

输出体积并换行。

输入样例:

在这里给出一组输入。例如:

1 2 3
结尾无空行

输出样例:

在这里给出相应的输出。例如:

6
结尾无空行

代码:

#include<iostream>
using namespace std;
class Box{
    private:
        int length,width,height;
    public:
        Box(int a,int b,int c)
        {
            length=a;
            width=b;
            height=c;
        }

        int getVolume()
        {
            return length*width*height;
        }
};
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    Box box(a,b,c);
    cout<<box.getVolume()<<endl;
	return 0;//不要忘了
}

提交结果:

1.png