有以下类定义 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<<')' << end1;} private: int_x,_y; }; 下列语句中会发生编译错误的是
A.Point pt;pt.Print();
B.const Point pt;pt.Print();
C.Point pt;pt.Move(1, 2);
D.const Point pt;pt.Move(1, 2)
第1题:
有以下类定义 classPoint{ 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; }; 下列语句中会发生编译错误的是
A.Pointpt;pt;Print();
B.const Point pt;pt.Print();
C.Pointpt;pt.Move(1,2);
D.const Point pt;pt.Move(1,2);
第2题:
分析以下程序的执行结果【 】。
include<iostream.h>
class Sample
{
int x, y;
public:
Sample() {x=y=0; }
Sample(int a, int b) { x=a; y=b;}
~Sample()
{
if(x==y)
cout<<"x=y"<<end1;
else
cout<<"x!=y" <<end1;
}
void disp()
{
cout<<"x="<<x<<",y="<<y<<end1;
}
};
void main()
{
Sample s 1 (2,3);
s1.disp();
}
第3题:
有如下类定义:
class Point
{
int x_, y_;
public:
Point():x_(0), y_(0){}
Point(int x, int y = 0):x_(x),y_(y){}
};
若执行语句
Point a(2), b[3] , *c[4];
则 Point 类的构造函数被调用的次数是
A . 2 次
B . 3 次
C . 4 次
D . 5 次
第4题:
有以下程序: #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; } int gety() { return y; } }; class Circle : public Point { private: int r; public: Circle(int a,int b,int c):Point(a,b) { r=c; } int getr() { return r; } double area() { return PI*r*r; } }; int main() { Circle c1(5,7,10); cout<<cl.area()<<endl; return 0; } 程序执行后的输出结果是
A.314
B.157
C.78.5
D.153.86
第5题:
有以下程序: #include <iostream> using namespace std; class Point' { public: void SetPoint(int x,int y); void Move(int xOff,int yOff); int GetX() { return X; } int GetY() { return Y; } private: int X,Y; }; void Point::SetPoint(int x, int y) { X=x; Y=y; } void Point: :Move(int xOff, int yOff) X+=xOff; Y+=yOff; } int main () { Point p1; p1.SetPoint(1,2); p1.Move (5, 6); cout<<"Point1 is ("<<p1.GetX()<<','<<p1.GetY()<<")"<<end1; return 0; } 执行后的输出结果是( )。
A.Point1 is (6,8)
B.Point1 is (1,2)
C.Point1 is (5,6)
D.Point1 is (4,4)
第6题:
有如下类定义:
class Point{
public:
Point(int xx=0,int yy=0):x(xx),y(yy) { }
private:
int x,y;
};
class Circle:public Point{
public:
Circle(int r):radius(r) { }
private:
int radius;
};
派生类Circle中数据成员的个数是( )。
A、3
B、1
C、5
D、2
答案:A
解析:本题考查默认构造函数和带参数的构造函数,题目中定义一个对象a(2)以及对象数组b[3],共执行3次构造函数,对象指针不调用构造函数。
第7题:
如下的类定义,括号里应填( )。 class Myclass { public: MyClass(int a =0,int b =0) { X=a; Y=b; void Change ( ) const { X- =10; Y+ =10; public: ( )int X,Y;
A.static
B.const
C.mutable
D.可以不添内容
第8题:
下列函数原型声明中错误的是
A.void Fun(int x=O,int y=0);
B.void Fun(int x,int y);
C.void Fun(int x,int y=0);
D.void Fun(int x=0,int y);
第9题:
下面是类MyClass的定义,对定义中各种语句描述正确的是( )。
class MyClass { publiC: void MyClass(int a) //①
{ x=a; ) int func(int a,int b) //②
{ x=a; y=b; } int func(int a,int b,int c=0) //③
{ x=a; y=b; z=c; } static void resetValue() //④
{ x=0; } private: int X,y,Z; };
A.语句①是类MyClass的构造函数定义
B.语句②和语句③实现类成员函数的重载
C.语句④实现对类成员变量x的清零操作
D.语句①、②、③和④都不正确
第10题:
下列程序的输出结果是 #include<iostream.h> class Myclass{ public : Myclass( int i=0,int j=0) {x=i; y=j; } void show( ){cout<<"x="<<x<<" "<"y="<<y<<endl;} void show( )const{cout<<"x="<
A.x=4,y=3;x=7,y=8
B.x=3,y=4;x=7,y=8
C.x=7,y=8;x=4,y=3
D.x=8,y=7;x=7,y=8