请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1。其中有线段类Line的定义。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是:
End point 1=(1,8),End point 2=(5,2),length=7.2111。
注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include <iostream>
#include <cmath>
using namespace std;
class Line;
double length(Line);
class Line //线段类
double x1,y1; //线段端点1
double x2,y2; //线段端点2
public:
//ERROR **********found**********
Linedouble x1,double y1,doublex2,double y2)const
this->x1=x1;
this->y1=y1;
this->x2=x2;
this->y2=y2;
double getX1()constreturn x1;
double getY1()constreturn y1;
double getX2()constreturn x2;
double getY2()constreturn y2;
void show () const
cout<<"End point 1=("<<x1<<","<<y1;
cout<<"),End point 2=("<<x2<<","<<y2;
//ERROR ********found********
cout<<"),length="<<length(this)
<<"。"<<endl;
;
double length (Line 1)
//ERROR ********found********
return sqrt((1.x1-1.x2)*(1.x1-1.x2)+(1.y1-1.y2)*(1.y1-1.y2));
int main ()
Line r1(1.0,8.0,5.0,2.0);
r1.show();
return 0;