[计算机类试卷]国家二级C++机试(类和对象)模拟试卷21及答案与解析.doc
《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷21及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷21及答案与解析.doc(20页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(类和对象)模拟试卷 21及答案与解析 一、选择题 1 有如下类声明: class Fooint 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=0; int
2、flint a)constthis-a=a; static int g ()return a; void h(int b)Test: b=b; ; private: int a; static int b; const int c; ; intTest: b=0; 在标注号码的行中,能被正确编译的是 ( )。 ( A) ( B) ( C) ( D) 4 有如下类声明: class SAMPLE int n; public: SAMPLE(int i=0): n(i) void setValue(int n0); ; VN关于 getValue成员函数的实现中,正确的是 ( )。 ( A) SA
3、MPLE: 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的成员函数的是 ( )。 ( A)
5、 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); b=bb; char*Geta()return a; int Getb()retu
6、rnb; ; int main() char*p1=“abed“, *p2=“weirong“; int d1=6, d2=8; XCD x(p1, d1), y(p2, d2); cout using namespace std; 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 ex, int cy, int r): center(cx, c
7、y), radius(r) int get()return center get()+radius; ; int main() Circle c(3, 4, 5); cout using namespace std; class Pair int m, n; public: Pair(int j, int k): m(j), n(k) int get()return m; int getoconstreturn m+n; ; int main() Pair a(3, 5); const Pair b(3, 5); cout using namespace std; class Point pu
8、blic: static int number; public: Pointonumber+; Point()number-; ; int Point: number-0: void mainO Point*ptr; PointA, B; Point*ptr_point=new Point3; ptx=ptr_point; Point C: Gout+Point: number+endl; deleteptr; 运行时输出的结果是 ( )。 ( A) 3 ( B) 4 ( C) 6 ( D) 7 24 在下列函数原型中,可以作为类 AA构造函数的是 ( )。 ( A) void AA(int)
9、; ( B) int AA(); ( C) AA(int)const; ( D) AA(int); 25 有如下类定义: class Point int x_, y_; public: Point(): x_(0), y_(0) Point(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)将类的一个对象赋
10、值给该类的另一个对象时 ( C)函数的形参是类的对象,调用函数进行形参和实参结合时 ( D)函数的返回值是类的对象,函数执行返回调用时 27 有如下程序 #include #include using namespace std; class MyClass public: MyClass()coutA; MyClass(char c)coutc; MyClass()coutB; ; int main() MyClass p1, *p2; p2=new MyClass(X); delete p2; return 0; 执行这个程序屏幕上将显示输出 ( )。 ( A) ABX ( B) ABXB
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 对象 模拟 21 答案 解析 DOC
