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

admin2021-09-05  33

问题 下面程序的输出结果是(    )。
#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<    retum 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/H65p777K
0

最新回复(0)