类中
set函数
和
get函数
的结合如何使数据进行查看和更改,请大致写出思路,谢谢帮助
#include
using namespace std;
class Box
{
public:
Box(float = 1, float = 1, float = 1);
virtual ~Box();
void Show();
private:
float length, width, height;
};
#include "Box.h"
using namespace std;
/*
Box::Box()
{
length = 1; width = 1; height = 1;
cout << "Box("<<length<<","<<width<<","<<height<<")";
cout << "is constructed!" << endl;
}
*/
Box::Box(float L,float W,float H)
{
length = L; width = W; height = H;
cout << "Box(" << length << "," << width << "," << height << ")";
cout << "is constructed!" << endl;
}
void Box::Show()
{
cout << "length:" << length << endl;
cout << "width:" << width << endl;
cout << "height:" << height << endl;
cout <<"tiji" << length*width*height << endl;
cout << "mianji" << (2*((length*width)+(width*height)+(length*height))) << endl;
}
Box::~Box()
{
cout << "Box(" << length << "," << width << "," << height << ")";
cout << "is constructed!" << endl;
}
#include
#include "Box.h"
using namespace std;
int main()
{
Box box1;
box1.Show();
box1.~Box();
Box box2(4,2,3);
box2.Show();
system("pause");
}