c++ 对象
#include <iostream>using namespace std;class Box
{public:double length; // 長度double breadth; // 寬度double height; // 高度
};int main( )
{Box Box1; // 聲明 Box1,類型為 BoxBox Box2; // 聲明 Box2,類型為 Boxdouble volume = 0.0; // 用于存儲體積// box 1 詳述Box1.height = 5.0; Box1.length = 6.0; Box1.breadth = 7.0;// box 2 詳述Box2.height = 10.0;Box2.length = 12.0;Box2.breadth = 13.0;// box 1 的體積volume = Box1.height * Box1.length * Box1.breadth;cout << "Box1 的體積:" << volume <<endl;// box 2 的體積volume = Box2.height * Box2.length * Box2.breadth;cout << "Box2 的體積:" << volume <<endl;return 0;
}
Box1 的體積:210
Box2 的體積:1560
總結(jié)