#include <iostream>
using namespace std;
class Rect
{
private:
int write;
int high;
public:
void set_W(int w)
{
write = w;
}
void set_h(int h)
{
high = h;
}
void init (int w, int h)
{
write = w;
high = h;
}
void show()
{
cout << "周长" << write*2+high*2 << endl;
cout << "面积" << write*high << endl;
}
};
int main()
{
Rect t;
t.init(18,25);
cout << "当前宽18,高25" << endl;
t.show();
cout << "如果要修改宽,高请输入1,不修改按任意键退出" << endl;
int a,b,c;
cin >> a;
if(a == 1)
{
cout << "请输入宽" << endl;
cin >> b;
t.set_W(b);
cout << "请输入长" << endl;
cin >> c;
t.set_h(c);
t.show();
}
else
{
system("pause");
}
return 0;
}
5.30作业
于 2024-05-30 19:36:50 首次发布