宅男噜噜噜666在线观看,国产1区二区三区,国产日韩欧美大片,国产超碰97,国产自产视频,99久久国产综合精品色伊,亚洲午夜高清

軟題庫(kù) 學(xué)習(xí)課程
當(dāng)前位置:信管網(wǎng) >> 在線考試中心 >> 試題查看
試題題型【分析簡(jiǎn)答題】
試題內(nèi)容

閱讀以下說(shuō)明和c++代碼,填充代碼中的空缺,將解答填入答題紙的對(duì)應(yīng)欄內(nèi)。
【說(shuō)明】
下面的程序用來(lái)計(jì)算并尋找平面坐標(biāo)系中給定點(diǎn)中最近的點(diǎn)對(duì)(若存在多對(duì),則輸出其中的一對(duì)即可)。程序運(yùn)行時(shí),先輸入點(diǎn)的個(gè)數(shù)和一組互異的點(diǎn)的坐標(biāo),通過計(jì)算每對(duì)點(diǎn)之間的距離,從而確定出距離最近的點(diǎn)對(duì)。例如,在圖 5-1 所示的8個(gè)點(diǎn)中,點(diǎn)(1,1) 與(2,0.5)是間距最近的點(diǎn)對(duì)。

【C++代碼】
#include
#include
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 ,numberOfPoints  =  0;
cout << "輸入點(diǎn)的個(gè)數(shù):";
cin  >>  numberOfpoints;
(1)points = new GPoint[numberOfPoints]; //創(chuàng)建保存點(diǎn)坐標(biāo)的數(shù)組
memset(points ,0 ,sizeof(points));
cout << "輸入" << numberOfPoints<< "個(gè)點(diǎn)的坐標(biāo) :";
for  (i  =  0;  i < numberOfPoints; i++) {
double tmpx ,tmpy;
cin>>tmpx>>tmpy;
points[i]  .setX(tmpx);
points[i]  .setY(tmpy);
}
(2)computeDistance = new ComputeDistance();
int p1 = 0 ,p2=1; //p1 和 p2 用于表示距離最近的點(diǎn)對(duì)在數(shù)組中的下標(biāo)
double    shortestDistance    =    computeDistance->distance(points[p1] ,points[p2]);
//計(jì)算每一對(duì)點(diǎn)之間的距離
for (i = 0; i < numberOfPoints; i++) {
for (j = i+1; j  <(3); j++) {
double tmpDistance = computeDistance->(4);
if (       (5)   )      {
p1 =  i; p2 =  j;
shortestDistance  = tmpDistance;
}
}
}
cout << "距離最近的點(diǎn)對(duì)是: (" ;
cout << points[p1] .getX() << "," << points[pl] .gety()<<")和(" ;
cout << points [p2].getX () << "," << points [p2].gety () << ")" << endl;
delete computeDistance;
return 0;
}

查看答案

相關(guān)試題