问题 单项选择题

有以下程序: #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)

答案

参考答案:A

解析: 本题考核对象的定义与使用。程序中定义了一个类Point,在主函数中定义了一个Point类的对象p1,然后通过对象p1调用其成员函数SetPoint()和Move()实现移位的操作。

单项选择题 A1型题
单项选择题