阅读以下说明和C++码,将应填入(n)处的字名写在的对应栏内。 [说明] 设计一个普通函数distance (Point &p1,Point &p2),用于计算p1和p2点之间的距离。本程序执行结果如下:(2,2)与(5,5)之间距离=4.24264

admin2013-01-05  15

问题 阅读以下说明和C++码,将应填入(n)处的字名写在的对应栏内。
[说明] 设计一个普通函数distance (Point &p1,Point &p2),用于计算p1和p2点之间的距离。本程序执行结果如下:(2,2)与(5,5)之间距离=4.24264
   # include < iostream. h >
   # include < math. h >
   class Point
   {
       int x, y;
       public:
           Point(int i, int j) {  (1)  
           int getx( ) { return x;}
           int gety( ) { return y; }
           void disp( )
        {
             (2)  
       }
   };
   float distance( Point &p1, Point &p2 )
   {
       float d;
             (3)  
       return d;
   }
   void main( )
   {
             (4)  
        p1. disp ( ); cout < <“与”; p2. diap( );
        cout< <“之间距离=” < <distance (p1,p2) < <end1;
   }

选项

答案x=i; y=j; clout< <"(" < d = sqrt((p1. getx( ) - p2. getx( ) ) *( p1. getx( ) - p2. getx( ) ) +(p1. gety( ) - p2. gety( ) ) *( p1. gety () - p2. gety( ) ); Point p1(2,2) ,p2(5,5);

解析
转载请注明原文地址:https://kaotiyun.com/show/9YDZ777K
0

相关试题推荐
随机试题
最新回复(0)