原代码:
(1)公有成员:
Segment(float xx1=0.0,float yy1=0.0,float xx2=1.0,float yy2=1.0) // 构造函数,初始化线段起点坐标(xx1, yy1),终点坐标(xx2, yy2),长度length
Segment(Segment &) // 复制构造函数,初始化线段起点坐标(xx1, yy1),终点坐标(xx2, yy2),长度length
void moveTo(float newX, float newY) // 将线段起点平移到(newX, newY)
float getx1(){} // 返回x1
float gety1(){} // 返回y1
float getx2(){} // 返回x2
float gety2(){} // 返回y2
double getLen() // 返回线段的长度
bool isEqual(Segment &s) // 判断与另一条线段的长度是否相等
int show() // 显示目前已创建的Point对象数
(2)私有成员:
float x1, y1, x2, y2 // 线段起点坐标(x1, y1)和终点坐标(x2, y2)
double length // 线段的长度
主函数如下:
int main() {
Segment s1(1,1,4,4),s2;
s2.show();
cout<<"the length of s1:"<<s1.getLen()<<endl;
cout<<"the length of s2:"<<s2.getLen()<<endl;
cout<<"s1.length==s2.length?"<<s2.isEqual(s1)<<endl;
s1.moveTo(3,3);
cout<<"the length of s1:"<<s1.getLen()<<endl;
cout<<"the length of s2:"<<s2.getLen()<<endl;
cout<<"s1.length==s2.length?"<<s2.isEqual(s1)<<endl;
Segment s3(s1);
s3.show();
for(int i=0;i<4;i++){
Segment tmp(s1);
tmp.show();
}
return 0;
}
请根据上述说明,完成Segment类的定义,补全相关代码,使得代码最终运行结果为:
count=2
the length of s1:4.24264
the length of s2:1.41421
s1.length==s2.length?0
the length of s1:1.41421
the length of s2:1.41421
s1.length==s2.length?1
count=3
count=4
count=5
count=6
count=7