下面程序的输出结果是( )。 #include #inc!ude using namespace std; class point { private: doubl

admin2012-12-29  20

问题 下面程序的输出结果是(             )。
    #include
    #inc!ude
    using namespace std;
    class point
    {
       private:
       double x;
       double y;
       public:
       point(double a,double b)
       {
           x=a:
           y=b;
       }
       friend double distances(point a,point b);
    };
    double distances(point a,point b)
    {
    return sqrt((a.x-b.x)*(a.x-b.x)+(a,y-b.y)*(a.y-b.y));
    }
    int main()
    {
       point p1(1,2);
       point p2(5,2);
       cout<       return 0;
    }

选项 A、2
B、4
C、8
D、16

答案B

解析 分析题目,此题最终要实现的结果是sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)),其中的a.x和a.y分别指p1(1,2冲的1和2。这样容易得到结果是(1-5)*(1-5)+(2-2)*(2-2)=16,再开方得到结果为4。
转载请注明原文地址:https://jikaoti.com/ti/qcL0FFFM
0

最新回复(0)