美文网首页Fortran
😄C++--类的定义

😄C++--类的定义

作者: JiehongYOU | 来源:发表于2019-05-27 10:32 被阅读0次
类的定义
#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

相关文章

网友评论

    本文标题:😄C++--类的定义

    本文链接:https://www.haomeiwen.com/subject/chyctctx.html