#include  
							 閱讀以下說(shuō)明和c++代碼,填充代碼中的空缺,將解答填入答題紙的對(duì)應(yīng)欄內(nèi)。人人看人人艹,欧美日在线观看,亚洲欧洲在线观看,国内精品视频饥渴少妇在线播放,国产首页,亚洲色图欧美另类,一区二区a视频
   
【說(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)試題
 
                     10年專注信管,信管教育專注者,信管網(wǎng)優(yōu)勢(shì)
 10年專注信管,信管教育專注者,信管網(wǎng)優(yōu)勢(shì)
                       免費(fèi)試聽信管網(wǎng)信息系統(tǒng)項(xiàng)目管理師課程
 免費(fèi)試聽信管網(wǎng)信息系統(tǒng)項(xiàng)目管理師課程
                        全國(guó)前50名高分學(xué)員訪談:董麗(174)、李思...
 全國(guó)前50名高分學(xué)員訪談:董麗(174)、李思...
                       信息系統(tǒng)項(xiàng)目管理師高端班培訓(xùn)課程
 信息系統(tǒng)項(xiàng)目管理師高端班培訓(xùn)課程
					   信管老師100小時(shí)直播課程
 信管老師100小時(shí)直播課程
					  
					   軟考報(bào)名專題(報(bào)名時(shí)間、入口等)
 軟考報(bào)名專題(報(bào)名時(shí)間、入口等)
					   中級(jí)系統(tǒng)集成項(xiàng)目管理工程師通關(guān)課程
 中級(jí)系統(tǒng)集成項(xiàng)目管理工程師通關(guān)課程
					  
					   系統(tǒng)規(guī)劃與管理師課程(考試介紹與題型分析)
 系統(tǒng)規(guī)劃與管理師課程(考試介紹與題型分析)
					   軟題庫(kù):軟考在線題庫(kù)、支持手機(jī)答題
 軟題庫(kù):軟考在線題庫(kù)、支持手機(jī)答題