[计算机类试卷]国家二级C++机试(选择题)模拟试卷106及答案与解析.doc
《[计算机类试卷]国家二级C++机试(选择题)模拟试卷106及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(选择题)模拟试卷106及答案与解析.doc(18页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C机试(选择题)模拟试卷 106及答案与解析 一、选择题 1 有如下类声明: class Foo int bar; ; 则 Foo类的成员 bar是 ( )。 ( A)公有数据成员 ( B)公有成员函数 ( C)私有数据成员 ( D)私有成员函数 2 有如下类定义: class Foo public: Foo(int v): value(v) / Foo() / private: Foo() / int value 0: / ; 其中存在语法错误的行是 ( )。 ( A) ( B) ( C) ( D) 3 有如下类定义: class Test public: Test()a 0; c
2、 0; / int f(int a)coastthis- a a; / static int g ()return a; / void h(int b)Test b b; ; / private: int a; static intb; const int c; ; int Test b 0; 在标注号码的行中,能被正确编译的是 ( )。 ( A) ( B) ( C) ( D) 4 有如下类声明: class SAMPLE int n; public: SAMPLE(int i 0): n(i) void setvalue(int n0); ; 下列关于 getValue成员函数的实现中,正确
3、的是 ( )。 ( A) SAMPLE setValue(int n0)n n0; ( B) void SAMPLE setValue(int n0)n n0; ( C) void setvalue(int n0)n n0; ( D) (int n0)n n0; 5 以下关键字不能用来声明类的访问权限 的是 ( )。 ( A) Public ( B) static ( C) protected ( D) private 6 下列关于类定义的说法中,正确的是 ( )。 ( A)类定义中包括数据成员和函数成员的声明 ( B)类成员的缺省访问权限是保护的 ( C)数据成员必须被声明为私有的 ( D)
4、成员函数只能在类体外进行定义 7 如果派生类以 protected方式继承基类,则原基类的 protected成员和 public成员在派生类中的访问属性分别是 ( )。 ( A) public和 public ( B) public和 protected ( C) protected和 public ( D) protected和 protected 8 下列有关类成员的叙述中,正确的是 ( )。 ( A)友元函数是类的成员函数 ( B)类成员的默认访问权限是私有的 ( C)类成员函数必须声明为公有的 ( D)类的静态数据成员不能是常成员 9 下列运算符函数中,肯定不属于类 Value的成员
5、函数的是 ( )。 ( A) Value operator (Value); ( B) Value operator (Value, Value); ( C) Value operator*(int); ( D) Value operator (Value); 10 有如下程序: #include #include using namespace std; class XCD char*a; int b; public: XCD(char*aa, int bb) a new charstrlen(aa) 1; strcpy(a, aa); bbb; char*Geta()return a; i
6、nt Getb()return b; ; int main() char*p1“abed“,*p2 “weirong“; int d1 6, d2 8; XCD x(p1, d1), y(p2, d2); cout ( A) 12 ( B) 16 ( C) 14 ( D) 11 11 有如下两个类定义: classAA; class BB AA v1, *v2; BB v3; int*v4; ; 其中有一个成员变量的定义是错误的,这个变量是 ( )。 ( A) v1 ( B) v2 ( C) v3 ( D) v4 12 有如下程序: #include using namespace std;
7、class Point int x, y; public: Point(int x1 0, int y1 0): x(x1), y(y1) int get()return x y; ; class Circle Point center; int radius; public: Circle(int CX, int cy, int r): center(cx, cy), radius(r) int get()return center get() radius; ; int main() Circle c(3, 4, 5); cout using namespace std; class Pa
8、ir int m, n; public: Pair(int j, int k): m(j), n(k) int get()retum m; int get()constretum m n; ; int main() Pair a(3, 5); const Pair b(3, 5); couta get()b get(); return 0; 运行时的输出结果是 ( )。 ( A) 33 ( B) 38 ( C) 83 ( D) 88 22 有如下类定义: class MyClass int x; public: MyClass(): x(0), y(0) int GetX()return x;
9、 void SetX(int xx)x xx; int y; ; 已知 obj是类 MyClass的对象,下列语句中违反类成员访问控制权限的是 ( )。 ( A) obj x ( B) obj y ( C) obj GetX() ( D) obj SetX(0) 23 有如下程序: #include using namespace std; class Point public: static int number; public: Pointonumber; Point()number-; ; int Point number-0: void mainO Point*ptr; PointA,
10、 B; Point*ptr_point new Point3; ptx ptr_point; Point C: Gout Point number end1; deleteptr; 运行时输出的结果是 ( )。 ( A) 3 ( B) 4 ( C) 6 ( D) 7 24 在下列函数原型中,可以作为类 AA构造函数的是 ( )。 ( A) void AA(int); ( B) int AA(); ( C) AA(int)const; ( D)从 (int); 25 有如下类定义: class Point int x_, y_; public: Point(): x_(0), y_(0) Poi
11、nt(int X, int Y 0): x_(x), y_(y) ; 若执行语句 Point a(2), b3, *c4; 则Point类的构造函数被调用的次数是 ( )。 ( A) 2次 ( B) 3次 ( C) 4次 ( D) 5次 26 下列情况中,不会调用拷贝构造函数的是 ( )。 ( A)用一个对象去初始化同一类的另一个新对象时 ( B)将类的一个对象赋值给该 类的另一个对象时 ( C)函数的形参是类的对象,调用函数进行形参和实参结合时 ( D)函数的返回值是类的对象,函数执行返回调用时 27 有如下程序 #include #include using namespace std;
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 选择题 模拟 106 答案 解析 DOC
