😄C++--类的定义

类的定义
#include <iostream>

using namespace std;

class Box {
public :
    double length;
    double breadth;
    double height;
};

int main() {
    Box box1;
    Box box2;
    double volume = 0.0; // 用来存储体积

    box1.height = 5.0;
    box1.length = 6.0;
    box1.breadth = 7.0;

    // box2 
    box2.height = 10.0;
    box2.length = 12.0;
    box2.breadth = 13.0;

    //
    volume = box1.height * box1.length * box1.breadth;
    cout << "Box1:" << volume << endl;

    // box2体积
    volume = box2.height * box2.length * box2.breadth;
    cout << "Box2:" << volume << endl;

    system("pause");
    return 0;

}

结果
result.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。