筱羅卜 2015-05-12 08:33 采纳率: 100%
浏览 1710
已采纳

这个程序错在哪了??求大神帮忙改正

#include
#include
using namespace std;
class Point
{
public:
Point(int xx=0,int yy=0)
{
x=xx;
y=yy;

}
Point(Point &p);
int GetX() {return x;}
int GetY() {return y;}
private:
int x,y;
};
Point::Point(Point &p)
{
x=p.x;
y=p.y;
cout<<"实现点的拷贝构造函数"< }
class Line
{
public:
Line()
{
len=0;
cout }
Line(Point &pp1,Point &pp2);
Line(int x1,int y1,int x2,int y2);
Line(Line &l1);
int Getlen() {return len;};
~Line() {}
private:
Point p1,p2;
int len;
};
Line::Line(int x1,int y1,int x2,int y2):p1(x1,y1),p2(x2,y2)
{
cout int x=static_cast(p1.GetX()-p2.GetX());
int y=static_cast(p1.GetY()-p2.GetY());
len=sqrt(x*x+y*y);
}
Line::Line(Line &l1):p1(l1.p1),p2(l1.p2)
{
cout<<"实现线的拷贝构造函数"<<endl;
len=l1.len;
}
int main()
{
Point p1(3,7),p2(9,4);
Line line(p1,p2);
Line line2(line);
cout<<"The length of the line is:";
cout<<line.Getlen()<<endl;
cout<<"The length of the line2 is:";
cout<<line2.Getlen()<<endl;
return 0;
}

  • 写回答

4条回答 默认 最新

  • threenewbee 2015-05-12 14:39
    关注

    len=sqrt(x*x+y*y);
    这里sqrt需要double的参数,你是int
    len=sqrt((double)x*x+(double)y*y);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的