- #include
-
- using namespace std;
-
- class Rect
- {
- private:
- int width;
- int height;
- public:
- void init(int width,int height);
- void set_w(int width);
- void set_h(int height);
- void show();
- };
-
- void Rect::init(int width,int height)
- {
- this->width=width;
- this->height=height;
- }
-
- void Rect::set_w(int width)
- {
- this->width=width;
- }
-
- void Rect::set_h(int height)
- {
- this->height=height;
- }
-
- void Rect::show()
- {
- cout << "width= " << width << endl;
- cout << "height= " << height << endl;
- cout << "C= " << (width+height)*2 << endl;
- cout << "S= " << width*height << endl;
- }
-
- int main()
- {
- Rect r;
- r.init(20,10);
- r.show();
- cout << endl;
- r.set_w(40);
- r.set_h(30);
- r.show();
-
- return 0;
- }
