思维导图
代码
#include <iostream>
using namespace std;
class Rect
{
private:
int width;
int height;
public:
void init(int w,int h)
{
width = w;
height = h;
}
void set_w(int w)
{
width = w;
}
void set_h(int h)
{
height = h;
}
void show()
{
int zhou = (width + height) * 2;
int mian = width * height;
cout << "矩形宽为:" << width << " 矩形高为:" << height << endl;
cout << "周长为:" << zhou << " 面积为:" << mian << endl;
}
};
int main()
{
Rect a1;
a1.init(6,2);
a1.show();
a1.set_h(10);
a1.set_w(6);
a1.show();
return 0;
}
结果