#include <iostream>
using namespace std;
class Box
{
public:
Box(int x = 0, int y = 0, int z = 0); //声明构造函数时指定默认参数
void area();
void volume();
private:
int height;
int width;
int lendth;
};
Box::Box(int x, int y, int z) //定义构造函数时可以不指定参数
{
height = x;
width = y; //给私有成员变量赋值
lendth = z;
}
void Box::area()
{
int s;
s = height * width * lendth;
cout << "s="<< s << endl;
}
void Box::volume()
{
int v;
v = 2 * (height * width) + 2 * (height * lendth) + 2 * (width * lendth);
cout << "v=" << v << endl;
}
int main()
{
Box box1(0, 0, 0);
int x, y, z;
x = 0; y = 0; z = 0;
cout << "x=" << x << " " << "y = " << y << " " << "z = " << z << endl;
box1.area();
box1.volume();
Box box2(10, 0, 0);
x = 10; y = 0; z = 0;
cout << "x=" << x << " " << "y = " << y << " " << "z = " << z << endl;
box2.area();
box2.volume();
Box box3;
x = 10; y = 20; z = 0;
cout << "x=" << x << " " << "y = " << y << " " << "z = " << z << endl;
box3.area();
box3.volume();
Box box4(10, 20, 30);
x = 10; y = 20; z = 30;
cout << "x=" << x << " " << "y = " << y << " " << "z = " << z << endl;
box4.area();
box4.volume();
return 0;
}