有如下程序: #include #include using std::cout; class Point { public: friend double di

admin2015-07-22  21

问题 有如下程序:
       #include
       #include
       using std::cout;
       class Point {
       public:
           friend double distance(const Point &p1,const Point &p2);
           Point(int xx=0,int yy=0): x(xx), y(yy){}
       private:
           int x, y;
       };
       double distance(const Point &p1,const Point &p2)     {
           return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
       }
       int main(){
           Point p0,p1(3,4);
           cout<           return 0;
       }
运行时的输出结果是

选项 A、0
B、3
C、4
D、5

答案D

解析 本题考查构造函数的应用,题目中定义对象p0时,执行默认构造函数,得出x和y都为0,定义对象p1(3,4),得到x和y分别是3,4,执行distance(p1,p0)后得出5。
转载请注明原文地址:https://kaotiyun.com/show/nANp777K
0

最新回复(0)