A: 10
B: 30
C: 0
D: 20
举一反三
- 下面为一个点类,重载了负号运算符,将原来点改为其关于原点的对称点。 请填空补充完整程序。 #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 }
- 若有定义int x, *p ; float y , *q ; 则下面赋值语句正确的是______。 A: p=&x ; B: p=&y ; C: q=&x ; D: q = p ;
- 有以下程序 #include void fun( int *a,int *b) {int *c; c=a;a=b;b=c; } main() {int x=3,y= 5 ,*P=&x,*q=&y; fun(p,q);printf(“%d,%d,”,*p,*q); fun(&x,&y);printf(“%d,%d\n”,*p,*q); } 程序运行后的输出结果是
- 下面程序输出的结果是( )。 #include<iostream> using namespace std; class A int X; public: A(int x):x(++x) ~A()cout<<x; ; class B:public A int y; public: B(int y):A(y),y(y) ~B()cout<<y;; ; void main() B b(3); A: 34 B: 43 C: 33 D: 44
- 中国大学MOOC: 有以下类定义class Point {public: Point(int x = 0, int y = 0) { _.x = x; _.y = y; } void Move(int xOff, int yOff) { _x += xOff; _.y += yOff; } void Print() const { cout << ( << _x << , << _y << ) << endl; }private: int _x, _y;};下列语句中会发生编译错误的是
内容
- 0
有以下程序 void f(int *x,int *y) { int t; t=*x;*x=*y;*y=t; } main() { int a[8]={1,2,3,4,5,6,7,8},i,*p,*q; p=a;q=&a[7]; while(*p!=*q){f(p,q);p++;q--;} for(i=0;i<8;i++) printf("%d,",a[i]); } 程序运行后的输出结果是______。
- 1
已知 Point类,要求在该类中完成+,- 两种操作符的重载。(重写Point类)class Point{ public: Point(float x=0, float y=0, float z=0): xx(x), yy(y), zz(z){} Point(const Point& p): xx(p.xx), yy(p.yy), zz(p.zz){ } private: float xx, yy, zz;}……
- 2
下列代码中: class Point{ int x,y; public: Point(int a, int b=0); //① Point(Point &aPoint); //②Point(Point *p); //③ 默认的构造函数是 A: ① B: ② C: ③ D: 没有
- 3
写出下列程序的运行结果。 #include<iostream. h> class X{ public: virtual void disp(){cout<<”X类的disp函数<<”end1;} }; class Y:public X{ public: void disp(){cout<<”Y类的disp函数<<”end1;} }; void main(){ X a, *p=&a; Y b; p->disp(); p=&b; p->disp(); } 运行结果为: [14] [15]
- 4
把 "x ( P( x )®$ y Q( x ,y ))化为前束范式,推导过程正确吗? "x ( P( x )®$y Q( x ,y )) Û"x (¬ P( x ) ∨ $y Q( x ,y )) Û"x$y (¬ P( x ) ∨ Q( x ,y )) Û" x $y ( P( x ) ®Q ( x ,y ))