cpp
#include <iostream>
using namespace std;
class Rect
{
int width;
int height;
public:
void init(int w,int h);
void set_w(int w);
void set_h(int h);
void show();
};
void Rect::init(int w,int h)
{
this->width = w;
this->height = h;
}
void Rect::set_w(int w)
{
this->width = w;
}
void Rect::set_h(int h)
{
this->height = h;
}
void Rect::show()
{
cout << "周长为 " << width*2+height*2 << endl;
cout << "面积为 " << width*height << endl;
}
int main()
{
Rect s1;
s1.init(1,2);
s1.set_w(2);
s1.set_h(4);
s1.show();
return 0;
}