注册 登录
编程论坛 C++教室

不可以实现double的运算

面朝大海1994 发布于 2013-05-10 10:51, 497 次点击
#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 编辑 ]
2 回复
#2
Pirelo2013-05-10 13:06
回复 楼主 面朝大海1994
没搞懂楼主的问题是什么,class的数据成员是double,问的却是不可以实现float的运算?
#3
面朝大海19942013-05-10 17:02
回复 2楼 Pirelo
不可以实现double的功能,呵呵!
1