#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 << "周长:" << (h+w)*2 << endl;
cout << "面积:" << h*w << endl;
}
int main()
{
Rect rect1;
rect1.init(2, 4);
rect1.show();
rect1.set_w(6);
rect1.set_h(7);
rect1.show();
return 0;
}
20240829 作业
于 2024-08-29 18:55:33 首次发布