#includeusingnamespacestd;classGP..."/>

女人久久久www免费人成看片,国内自拍偷拍网,国产一区二区三区免费在线观看,欧美精品三区四区,91久久国产综合久久91,欧美成人精品第一区二区三区 ,美女成人在线观看

軟題庫 移動APP 掃碼下載APP 隨時隨地移動學(xué)習(xí) 培訓(xùn)課程
試卷名稱 2012年下半年程序員考試下午真題試題(案例分析)
考試中心《2012年下半年程序員考試下午真題試題(案例分析)》在線考試
試卷年份2012年下半年
試題題型【分析簡答題】
試題內(nèi)容

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

【C++代碼】
#include  <iostream>
#include <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 ,numberOfPoints  =  0;
       cout << "輸入點的個數(shù):";
       cin  >>  numberOfpoints;
       (1)points = new GPoint[numberOfPoints]; //創(chuàng)建保存點坐標(biāo)的數(shù)組
         memset(points ,0 ,sizeof(points));
         cout <<  "輸入" <<   numberOfPoints<<  "個點的坐標(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 用于表示距離最近的點對在數(shù)組中的下標(biāo)
      double    shortestDistance    =    computeDistance->distance(points[p1] ,points[p2]);
      //計算每一對點之間的距離
      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 << "距離最近的點對是: (" ;
   cout << points[p1] .getX() << "," << points[pl] .gety()<<")和("  ;
  cout << points [p2].getX () << "," << points [p2].gety () << ")" << endl;
  delete computeDistance;
  return 0;
}


相關(guān)試題

推薦文章
合作網(wǎng)站內(nèi)容