#includeusingnamespacestd;classGP..."/>

午夜无码中文字幕影院,国产自产第一区c国产,久久久久久夜精品精品免费,国产99久久,夜夜夜夜曰天天天天拍国产,欧美日韩亚洲另类专区,国产精品区一区二区免费

軟題庫(kù) 移動(dòng)APP 掃碼下載APP 隨時(shí)隨地移動(dòng)學(xué)習(xí) 培訓(xùn)課程
試卷名稱(chēng) 2012年下半年程序員考試下午真題試題(案例分析)
考試中心《2012年下半年程序員考試下午真題試題(案例分析)》在線考試
試卷年份2012年下半年
試題題型【分析簡(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),通過(guò)計(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  <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 << "輸入點(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)試題

推薦文章