/*带参数的构造函数*/
#include<iostream>
using namespace std;
class Box{
public:
Box(float L,float W,float H)
{length=L;width=W;height=H;}
float volume(){return length*width*height;}
private:
float length;float width;float height;
};
int main()
{
Box box1(1,2,3);
Box box2(5,1,2);
cout<<box1.volume()<<endl;
cout<<box2.volume()<<endl;
return 0;
}
#include<iostream>
using namespace std;
class Box{
public:
Box(float L,float W,float H)
{length=L;width=W;height=H;}
float volume(){return length*width*height;}
private:
float length;float width;float height;
};
int main()
{
Box box1(1,2,3);
Box box2(5,1,2);
cout<<box1.volume()<<endl;
cout<<box2.volume()<<endl;
return 0;
}