举一反三
- 有如下类定义: class Point{ int x,y; public: Point():x(0),y(0){} Point( int xx, int yy =0) x(xx), y(yy){} }; 若执行语句: Point(2),b[3],*c[4] 则 Point类的构造函数被调用的次数是() A: 2次 B: 3次 C: 4次 D: 5次
- 设通常Point类的数据成员为intx,y,则构造函数可以定义为Point(int yy,int xx=0):x(xx),y(yy){}
- 有如下类定义:classPoint{intxx,yy;public:Point():xx(0),yy(0){}Point(intx,inty=0):xx(x),yy(y){}};若执行语句Pointa(2),b[3],*c[4];则Point类的构造函数被调用的次数是()。 A: 2次 B: 3次 C: 4次 D: 5次
- 若程序中定义了3个函数xx、yy和zz,并且函数xx调用yy、yy调用zz,那么,在程序运行时不出现异常的情况下,函数的返回方式为 (31) 。 A: 先从yy返回zz,然后从zz返回xx B: 先从xx返回yy,然后从yy返回zz C: 先从zz返回yy,然后从yy返回xx D: 先从况返回xx,然后从xx返回yy
- 有以下程序: #include <iostream> #include <cmath> using namespace std; class Distance; class point { public: friend class Distance; Point(int a,int B) { x=a; Y=b; } void Print() { cout<<"X= "<<X<<end1; cout<<"Y= "<<Y<<end1; } private: float X,Y; }; class Distance { public: float Dis(Point &p,Point &q); }; float Distance :: Dis(Point &p,Point &q) { float result; result=sqrt((p.X-q.X)*(p.X-q.X)+(p.Y-q.Y)*(p.Y-q.Y)); cout<<result<<end1; retUrn result; } int main() { Point p(10,10),q(10,30); Distance d; d.Dis(p,q); return 0; } 运行后的输出结果是( )。 A: 10 B: 30 C: 0 D: 20
内容
- 0
下面为一个点类,重载了负号运算符,将原来点改为其关于原点的对称点。 请填空补充完整程序。 #include [iostream.h][br][/br] class Point{ private: float x; float y; public: Point(){ x = 0; y = 0; } Point(float a, float b){ x = a; y = b; } // 显示坐标 void display() { cout << "X: " << x << " Y:" << y <<endl; } // 重载负运算符 -,取对称点 friend Point operator-(Point a) { Point r; (1) ; (2) ; return r; } }; void main() { Point p1(5, 6); ; // 取对称点 p1.display(); //p1中的x和y值分别为-5和-6 }
- 1
有如下类定义:class XX{int XX;public:xx():xx(0){tout<<A;}XX(int n):xx(n){cout<<B;}};class Y:Y:public XX{int YY;public:YY():YV(O){cout<<YY;)YY(int n):xx(n+1),YY(n){cout<<YY;}YY(int m,int n):XX(m),YY(n){cout<<yy;)};下列选项中,输出结果为A0的语句是 A: YY yl(0,0); B: YY 72(1); C: YY y3(0); D: YY y4;
- 2
有如下类定义:()class()XX{()int()xx;()public:()XX():()xx(0){cout<<'()A';}()XX(int()n):()xx()(()n){tout<<'()B';}()};()class()YY:public()XX{()int()yy;()public:()YY():()yy()(0){cout()<<yy;}()YY(int()n):()XX(n+1),()yy(n){cout<<yy;}()YY()(int()m,()int()n):()XX()(m),()yy(n){cout<<yy;}()};()下列选项中,输出结果为A0的语句是()。A.()YY y1(0,0);()B.()YY y2(1);()C.()YY y3(0);()D.()YY y4;
- 3
已知:Point x(3,4); 则下列声明中能定义p指针变量并使其初值指向x的是( ) 。 A: int &p=x; B: Point *p=&x; C: Point p=x; D: float *p=&x;
- 4
有如下程序: #include<iostream> using namespace std; class XX{ int x; public: XX(int XX=0):x(xx){} int getX(){return x;} }; class YY:public XX{ int y; public: YY(int xx,int yy):XX(xx),y(yy){} int getV(){return getX()+y;} }; int main(){ YY c(3,4); cout<<c.getV()+c.getX()<<endl; return 0; } 运行这个程序的输出结果是______。 A: 3 B: 4 C: 7 D: 10