代码:
#include <iostream>
using namespace std;
// 定义类
class Box{
public:
double length;
double width;
};
//主函数
int main(){
Box Box1;
Box Box2;
double result;
Box1.length = 2.0;
Box1.width = 2.0;
Box2.length = 3.0;
Box2.width = 3.0;
result = Box1.length * Box1.width;
cout << "Box1面积是:" << result << endl;
result = Box2.length * Box2.width;
cout << "Box1面积是:" << result << endl;
return 0;
}
运行结果:
说明: