#include <iostream>
using namespace std;
class Rect
{
private:
int width;
private:
int heigth;
public:
void init(int w,int h)
{
width=w;
heigth=h;
}
public:
void set_w(int w)
{
width=w;
}
public:
void set_h(int h)
{
heigth=h;
}
public:
void show()
{
cout << "矩形周长为:" << 2*width+heigth*2 << endl;
cout << "矩形面积为:" << width*heigth << endl;
}
};
int main()
{
Rect s1;
s1.init(2,3);//初始化函数
cout << "初始化的矩形周长和面积为:" << endl;
s1.show();//
s1.set_w(4);//更改宽度的函数
s1.set_h(5);//更改高度的函数
cout << "修改后的矩形周长和面积为:" << endl;
s1.show();//输出该矩形的周长和面积函数
return 0;
}
c++day2作业
最新推荐文章于 2024-10-07 19:01:55 发布