不可以实现double的运算
#include<iostream> #include<cmath>
using namespace std;
class Rectangle
{
private:
double left;
double bottom;
double right;
double top;
public:
void SetPoint(double l,double b,double r,double t)
{
left=l;
bottom=b;
right=r;
top=t;
}
void cal(double left,double bottom,double right,double top)
{
double s,m;
s=abs(left-right)*abs(bottom-top);
m=(abs(left-right)+abs(bottom-top))*2.0;
cout<<"该长方形的面积为:"<<s<<endl;
cout<<"该长方形的周长为:"<<m<<endl;
}
void Getp1(double left,double bottom)
{
cout<<"长方形的左下角坐标是:"<<left<<","<<bottom<<endl;
}
void Getp2(double right, double top)
{
cout<<"长方形的右上角坐标是:"<<right<<","<<top<<endl;
}
};
void main()
{
Rectangle r1;
double l,b,r,t;
cout<<"请输入长方形的左下角的坐标:";
cin>>l>>b;
cout<<"请输入长方形的右上角的坐标:";
cin>>r>>t;
r1.Getp1(l,b);
r1.Getp2(r,t);
r1.cal(l,b,r,t);
}
[ 本帖最后由 面朝大海1994 于 2013-5-10 17:02 编辑 ]