首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using std::cout; class Point { public: friend double di
有如下程序: #include #include using std::cout; class Point { public: friend double di
admin
2015-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
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
数据独立性分为逻辑独立性与物理独立性。当数据的存储结构改变时,其逻辑结构可以不变,所以,基于逻辑结构的应用程序不必修改,称为【】。
以下程序的输出结果是#include<iostream.h>voidmain(){intx=1,y=3;cout<<x++<<",";{intx
类ostream的成员函数______用于执行无格式输出,成员函数______用于输出单个字符。
若调用一个函数,且此函数中没有return语句,则正确的说法是该函数()。
带有虚基类的多层次派生类构造函数的成员初始化列表中都要列出虚基类的构造函数,这样对虚基类的子对象初始化
在关系模型中,
下列叙述中正确的是
在一个容量为25的循环队列中,若头指针front=16,尾指针rear=9,则该循环队列中共有【】个元素。
设在主函数中有以下定义和函数调用语句,且fun()函数为void类型,请写出fun()函数的首部【】。intmain(){doubles[10][22];intn;fun(s);re
运算符重载是对已有的运算符赋予多重含义,因此
随机试题
关于白喉棒状杆菌,下列说法正确的是
给单台X线机供电的专用变压器的容量可按计算容量的多少取值
地下管线探测按具体对象可分为()。
下列合同订立情形中,属于《合同法》规定的合同无效的情形的是()。
下列会计科目,不属于资产类的是()。
股东在公司设立时未履行或者未全面履行出资义务的,公司相关权利人的下列请求中,不会得到人民法院支持的是()。
图文声像导游能否在将来取代实地口语导游?为什么?
附属内驱力是一种内部动机。
ALetterofAcknowledgement确认信Writealetterofacknowledgementofabout100wordsbasedonthefollowingsituation:Youaret
A、Shethoughtitwasasoccergame.B、She’dliketosharetheman’shobby.C、Shewasexcitedaboutthegamegoingon.D、Shewant
最新回复
(
0
)