#include <bits/stdc++.h>
using namespace std;
class Rect
{
private:
double Length, Width;
public:
Rect(double l = 0, double w = 0)
{
if(l >= 0 && w >= 0)
{
Length = l;
Width = w;
}
else
{
Length = 0;
Width = 0;
}
}
Rect(const Rect &r)/*拷贝构造函数*/
{
Length = r.Length;
Width = r.Width;
}
void show(const char *name)
{
cout<<"the length and width of "<<name<<" is:"<<Length<<","<<Width<<endl;
cout<<"the perimeter of "<<name<<" is:"<<(2 * (Length + Width))<<endl;
cout<<"the area of "<<name<<" is:"<<(Width * Length)<<endl;
}
};
int main()
{
double l, w;
cin>>l>>w;
Rect a(l, w);
Rect b(a);
a.show("r1");
b.show("r2");
return 0;
}
2673-计算长方形的周长和面积
最新推荐文章于 2023-05-09 22:12:38 发布