程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c++-這個程序錯在哪了??求大神幫忙改正

c++-這個程序錯在哪了??求大神幫忙改正

編輯:編程綜合問答
這個程序錯在哪了??求大神幫忙改正

#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;
}

最佳回答:


len=sqrt(x*x+y*y);
這裡sqrt需要double的參數,你是int
len=sqrt((double)x*x+(double)y*y);

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved