
- #include
-
- using namespace std;
-
- class Rect
- {
- private:
- int width;
- int height;
- public:
- void init(int width,int height);
- void set_w();
- void set_h();
- void show();
- };
-
- void Rect::init(int width,int height)
- {
- this->width=width;
- this->height=height;
- }
-
- void Rect::set_w()
- {
- cout << "需要更改的宽度:";
- cin >> width;
- }
-
- void Rect::set_h()
- {
- cout << "需要更改的高度:";
- cin >> height;
- }
-
- void Rect::show()
- {
- cout << "面积为:" << width*height << endl;
- }
-
- int main()
- {
- Rect rec;
- rec.init(5,5);
- rec.show();
- rec.set_h();
- rec.show();
- rec.set_w();
- rec.show();
- return 0;
- }
