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