#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 L = 2*(width + height);
double s = (width * height)/2;
cout << "周长L=" << L << endl;
cout << "面积S=" << s << endl;
}
};
int main()
{
Rect s1; //实例化一个s1对象
s1.init(3,5);
s1.set_w(5);
s1.set_h(6);
s1.show();
return 0;
}
C++day2
于 2024-03-12 19:52:15 首次发布