niusouti.com

有以下程序:includeincludeusing namespace std; class point{private:double有以下程序: #include<iostream> #include<math> using namespace std; class point { private: double x; double y; public: point(double a,double B) { x=a; y=b; } friend double distance (point a,poin

题目
有以下程序:includeincludeusing namespace std; class point{private:double

有以下程序: #include<iostream> #include<math> using namespace std; class point { private: double x; double y; public: point(double a,double B) { x=a; y=b; } friend double distance (point a,point B) ;

A.1

B.5

C.4

D.6


相似考题
更多“有以下程序:#include<iostream>#include<math>using namespace std; class point{private:double ”相关问题
  • 第1题:

    有以下程序:includeusing namespace std;class BASE{private: char c;public: BASE(c

    有以下程序: #include <iostream> using namespace std; class BASE { private: char c; public: BASE(char n):c(n);{} virtual~BASE() { cout<<c; } }; class DERIVED:public BASE { char c; p

    A.XY

    B.YX

    C.X

    D.Y


    正确答案:A
    解析:在C++中,由于析构函数不能被继承,因此在执行派生类的析构函数时,基类的析构函数也将被调用。执行顺序是先执行派生类的析构函数,再执行基类的析构函数,其顺序与执行构造函数的顺序正好相反。在此题的程序中,在主函数结束时,派生类DERIVED对象obj将被删除,所以就会调用对象的析构函数。先调用派生类的析构函数,输出X,然后调用基类的析构函数,输出Y。

  • 第2题:

    有以下程序:include include using namespace std;class point{private: doub

    有以下程序: #include <iostream> #include <math> using namespace std; class point { private: double x; double y; public: point(double a,double b) { x=a; y=b; } friend double distance(point a,point b) ; }; double distance(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 pl(1,2); point p2 (5, 2); cout<<distance (pl,p2) <<end1; return 0; } 程序运行后的输出结果是( )。

    A.1

    B.5

    C.4

    D.6


    正确答案:C
    解析:本题考核友元函数的应用。分析程序:①类point中定义了两个私有成员x和y,以及一个友元函数distance()。从而,函数distance可以访问类point中的任何成员。②在函数distance()中,返回值为sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))。由此可知,函数distance()的功能是计算a、b两点之间的距离。③在主函数中,先定义两点:p1(1,2)和p2(5,2)。然后调用函数distance()计算两点之间的距离为4,所以程序最后输出为4。

  • 第3题:

    若有以下程序:include using namespace std;class point{private: int x, y;public:

    若有以下程序: #include <iostream> using namespace std; class point { private: int x, y; public: point ( ) { x=0; y=0; } void setpoint(int x1,int y1) { x=x1; y=y1;

    A.12,12

    B.5,5

    C.12,5

    D.5,12


    正确答案:D
    解析:本题考核对象指针的定义与使用。分析程序:程序首先定义一个类point。类point中有两个私有成员,整型变量x和y,还有两个公有成员函数setpoint(intx1,inty1)和dispoint()。函数setpoint()用来设置私有成员x和y的值,而函数dispoint()用来显示私有成员x和y的值。主函数中,首先定义了类point的指针对象p,并申请了内存空间,然后调用对象p中公有成员setpoint给对象p中的私有成员x和y赋值,然后调用成员函数dispoint显示x和y的值。由此可知,最后输出的值应该是5,12。

  • 第4题:

    有以下程序:include include using namespace std;class point{private:doubl

    有以下程序:#include <iostream>#include <math>using namespace std;class point{private: double x; double y;public: point(double a, double b { x=a; y=b; friend double distance (point a, point b ; };double distance(point a, point b return sqrt((a. x-b. x )*(a. x -b. x )+ (a. x -b. x)*(a. x-b. x));}int main (){ point p1 (1,2); point p2(5,2); cout<<distance (p1, p2)<<end1; return 0;} 程序运行后的输出结果是

    A.1

    B.5

    C.4

    D.6


    正确答案:C
    解析:本题考核友元函数的应用。分析程序:类point中定义了两个私有成员x和y,以及一个友元函数distance。从而,函数distance可以访问类point中的任何成员。在函数distance中,返回值为sqrt ((a. x- b. x)*(a. x-b. x)+(a. y-b. y)*(a. y-b. y))。由此可知,函数distance的功能是计算a、b两点之间的距离。在主函数main中,先定义两点:p1(1,2)和p2(5,2)。然后调用函数distance计算两点之间的距离为4,所以程序最后输出为4。

  • 第5题:

    有以下程序:include using namespace std;define PI 3.14class Point{ private:int

    有以下程序: #include <iostream> using namespace std; #define PI 3.14 class Point { private: int x,y; public: Point(int a,int b) { x=a; y=b; } int getx() { return x; }

    A.314

    B.157

    C.78.5

    D.153.86


    正确答案:A
    解析:本题考核派生类的定义和应用。本程序设计了一个点类Point,包含了横、纵两个坐标数据x和y,由它派生出了圆类Circle,并加入了新的数据成员,即一个半径r和一个求圆面积的函数成员area。在主函数main中,首先定义了一个圆Circle类的对象c1,并通过它的构造函数初始化其数据成员。由此可知,其半径r的值为10,所以其面积为PI*10'10=314,即对象c1的函数成员area的返回值为314。