#include <iostream>
using namespace std;
class Rect
{
private:
int w; // 宽
int h; // 高
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->w = w;
this->h = h;
}
void Rect::set_w(int w)
{
this->w = w;
}
void Rect::set_h(int h)
{
this->h = h;
}
void Rect::show()
{
cout << "S = " << w*h << endl;
cout << "C = " << w*2+2*h << endl;
}
int main()
{
Rect rect;
rect.init(2,3);
rect.show();
rect.set_w(5);
rect.show();
return 0;
}
20240829
于 2024-08-29 17:30:49 首次发布