#include <iostream>
using namespace std;
class Rect
{
private:
int width;
int height;
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)
{
width = w;
height = h;
}
void Rect::set_w(int w)
{
width = w;
}
void Rect::set_h(int h)
{
height = h;
}
void Rect::show()
{
int C = 2 * ( width + height );
int S = width * height;
cout << "周长=" << C << endl;
cout << "面积=" << S << endl;
}
int main()
{
Rect r;
int w , h;
cout << "输入宽和高" << endl;
cin >> w >> h;
r.init(w,h);
r.show();
cout << "输入宽和高" << endl;
cin >> w >> h;
r.init(w,h);
r.show();
return 0;
}
1008hw/
最新推荐文章于 2024-10-08 06:04:53 发布