利用对象数组求长方体的体积

img


#include<iostream>
using namespace std;
class Cube{
    private:
        float length,width,height;
        float volum;
    public:
        Cube();
        void Print();
};
// 定义无参构造函数 
Cube::Cube()
{
    this->length = 3;
    this->width = 4;
    this->height = 5;
    this->volum = length*width*height;
}
//定义输出函数 
void Cube::Print(){
    cout<<"长方体体积为:"<<volum<<endl;
}
int main(){
    // 创建对象
     Cube cube;
     cube.Print();
     return 0;
}