1> 思维导图
2>
自己封装一个矩形类(Rect),拥有私有属性:宽度(width)、高度(height),
定义公有成员函数:
初始化函数:void init(int w, int h)
更改宽度的函数:set_w(int w)
更改高度的函数:set_h(int h)
#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()
{
cout << "周长:" << (width+height)*2 << endl;
cout << "面积:" << width*height << endl;
}
};
int main()
{
rect s1;
int w, h;
s1.init(5, 5);
s1.show();
cout << "请输入宽:";
cin >> w;
s1.set_w(w);
cout << "请输入高:";
cin >> h;
s1.set_h(h);
s1.show();
return 0;
}