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

admin2021-05-06  26

问题 下面程序的输出结果是(    )。
    #include
    #include
    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分别指pl(1,2)中的1和2。这样容易得到结果是(1-5)-(1-5)+(2-2)*(2-2)=16,再开方得到结果为4。
转载请注明原文地址:https://kaotiyun.com/show/cLfp777K
0

随机试题
最新回复(0)