阅读以下说明和C++代码,填充代码中的空缺。 [说明] 下面的程序用来计算并寻找平面坐标系中给定点中最近的点对(若存在多对,则输出其中的一对即可)。程序运行时,先输入点的个数和一组互异的点的坐标,通过计算每对点之间的距离,从而确定出距离最近的点对。例如,在图所示的8个点中,点(1,1)与(2,0.5)是间距最近的点对。
[C++代码] #include <iostream> #inc lude <cmath> using namespace std; class GPoint private: double x,y; public: void setX(double x)this->x=x; void setY(double Y)this->y=Y; double getX( )return this->x; double getY( )return this->y; ; class ComputeDistance public: double distance(GPoint a,GPoint b) return sqrt((a.getX( )-b.getX( ))*(a.getX( )-b.getx( ))+(a.getY( )-b.getY( ))*(a.getY( )-b.getY( ))); ; int main( ) int i,j, numberofP0ints=0; cout<<"输入点的个数:"; cin>>numberOfPOints; ______ points=new GPoint[numberOfPoints];//创建保存点坐标的数组 memset(points,0,sizeof(points)); cout<<"输入"<<numberOfPoints<<"个点的坐标:"; for(i=0;i<numberOfPoints;i++) double tmpx,tmpy; Cin>>tmpx>>tmpy; points[i].setX(tmpx); points[i].setY(tmpy); ______ computeDistance=new ComputeDistance( ); int p1=0,p2=1;//p1和p2用于表示距离最近的点对在数组中的下标 double shortestDistance=computeDistance->distance(points[p1],points[p2]); //计算每一对点之间的距离 for(i=0;i<numberOfPoints;i++) for(j=i+1;j<______;j++) double tmpDistance=computeDistance->______; if(______) p1=i;p2=j; shortestDiStance=tmpDistance; cout<<"距离最近的点对是:("; cout"points[p1].getX( )<<", ”<<points[p1].getY( )<<")和("; cout<<points[p2].getX( )<<","<<points[p2].getY( )<<")"<<endl; delete computeDiStance; return 0;
题库:初级程序员
类型:填空题
时间:2021-07-10 11:18:05
免费下载:《填空集》Word试卷
阅读以下说明和C++代码,填充代码中的空缺。 [说明] 下面的程序用来计算并寻找平面坐标系中给定点中最近的点对(若存在多对,则输出其中的一对即可)。程序运行时,先输入点的个数和一组互异的点的坐标,通过计算每对点之间的距离,从而确定出距离最近的点对。例如,在图所示的8个点中,点(1,1)与(2,0.5)是间距最近的点对。
[C++代码] #include <iostream> #inc lude <cmath> using namespace std; class GPoint private: double x,y; public: void setX(double x)this->x=x; void setY(double Y)this->y=Y; double getX( )return this->x; double getY( )return this->y; ; class ComputeDistance public: double distance(GPoint a,GPoint b) return sqrt((a.getX( )-b.getX( ))*(a.getX( )-b.getx( ))+(a.getY( )-b.getY( ))*(a.getY( )-b.getY( ))); ; int main( ) int i,j, numberofP0ints=0; cout<<"输入点的个数:"; cin>>numberOfPOints; ______ points=new GPoint[numberOfPoints];//创建保存点坐标的数组 memset(points,0,sizeof(points)); cout<<"输入"<<numberOfPoints<<"个点的坐标:"; for(i=0;i<numberOfPoints;i++) double tmpx,tmpy; Cin>>tmpx>>tmpy; points[i].setX(tmpx); points[i].setY(tmpy); ______ computeDistance=new ComputeDistance( ); int p1=0,p2=1;//p1和p2用于表示距离最近的点对在数组中的下标 double shortestDistance=computeDistance->distance(points[p1],points[p2]); //计算每一对点之间的距离 for(i=0;i<numberOfPoints;i++) for(j=i+1;j<______;j++) double tmpDistance=computeDistance->______; if(______) p1=i;p2=j; shortestDiStance=tmpDistance; cout<<"距离最近的点对是:("; cout"points[p1].getX( )<<", ”<<points[p1].getY( )<<")和("; cout<<points[p2].getX( )<<","<<points[p2].getY( )<<")"<<endl; delete computeDiStance; return 0;
本题关键词:中药说明书,中文警示说明,工程说明,金标数码定量阅读仪,说明,招标说明书,明代,设计总说明,新斯的明中毒,说明书;