[计算机类试卷]国家二级C++机试(类和对象)模拟试卷1及答案与解析.doc
《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷1及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷1及答案与解析.doc(29页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(类和对象)模拟试卷 1及答案与解析 一、选择题 1 有如下类声明: class Fooint bar; ; 则 Foo类的成员 bar是 ( )。 ( A)公有数据成员 ( B)公有成员函数 ( C)私有数据成员 ( D)私有成员函数 2 有如下类定义: class Foo public: Foo(int v): value(v) Foo() private: F000 int value=0; ); 其中存在语法错误的行是 ( )。 ( A) ( B) ( C) ( D) 3 有如下类定义: class Test public: Test()a=0; C=0; int f
2、(int 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; ); 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 nO)n=nO; ) ( B) void SAMPLE: setValue(int nO)n=n0; ( C) void setValue(int nO)n=nO; ( D) (int nO)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); b=bb; char*GetaOreturn a; ) int G
6、etb0return b; ; int main) char*pl=“abcd”, *p2=”weirong”; int dl=6, d2=8; XCD x(pl, d1), y(p2, d2); cout strlen(x Geta0)+y Getb0 endl; return 0; ) 运行时的输出结果是 ( )。 ( A) 12 ( B) 16 ( C) 14 ( D) 1 1 11 有如下两个类定义 : class AA); class BB AA vl, *v2; BB v3: int*v4; ); 其中有一个成员变量的定义是错误的,这个变量是 ( )。 ( A) vl ( B) v
7、2 ( C) v3 ( D) v4 12 有如下程序: #include using namespace std; class Point int X, y; public: Point(int xl=0, int yl=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 get0retum center get0+radius; ); int
8、 main() Circle c(3, 4, 5); cout c get() endl; return 0: ) 运行时的输出结果是 ( )。 ( A) 5 ( B) 7 ( C) 9 ( D) 12 13 若 AA为一个类, a为该类的私有整型数据成员, getA0为该类的一个非静态公有成员函数,功能是返回 a的值。如果 X为该类的一个对象,要在类外访问 X对象中 a的值,正确的访问格式为 ( )。 ( A) AA getA() ( B) x。 getA() ( C) x a ( D) AA: a 14 有如下类定 义: class MyClass int b; char a; doubl
9、e c; public: MyClass0: c(0 0), b(O), a(, )() ; 创建这个类的对象时,数据成员的初始化顺序是 ( )。 ( A) a,b, C ( B) c,b, a ( C) b, a, c ( D) c,a, b 15 下列关于类和对象的叙述中,错误的是 ( )。 ( A)一个类只能有一个对象 ( B)对象是类的具体实例 ( C)类是对某一类对象的抽象 ( D)类和 对象的关系是一种数据类型与变量的关系 16 若有如下类声明 class MyClass public: MyClass()cout using namespace std; class Pair i
10、nt m, n; public: Pair(intj, int k): m(j), n(k) int get()return m; int getoconstretum m+n; ; int main() Pair a(3, 5); const Pair b(3, 5); cout a get() b get(); retum 0; ) 运行时的输出结果是 ( )。 ( A) 33 ( B) 38 ( C) 83 ( D) 88 22 有如下类定义: class MyClass int x; public: MyClass(): x(0), y(0) int GetX()return x; )
11、 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 main0 Point*ptr
12、; 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); ( B) intAA(); ( C) AA(int)const; ( D) AA(int); 25 有如下类定义: class Point int X一, y; public: Point(): x一
13、(O), Y一 (O) 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)将类的一个对象赋值给该类的另一个对象时 ( C)函数的形参是类的对象,调用函数进行形参和实参结合时 ( D)函数的返回值是类的对象,函数执行返回调用时 27 有如下程序 #include #include using
14、 namespace std; class MyClass public: MyClass()cout A; ) MyClass(char c)cout using namespace std; class test private: int a: public: test0cout+”constructor”+endl; test(int a)cout+a+endl; ) test(const test&test) a=test a: cout+“copy constructor”+endl; ) test()Cout+”destructor”+endl; ) ); int main() t
15、est A(3); return 0: 运行时输出的结果是 ( )。 ( A) 3 ( B) constructor destructor ( C) copy constructor destructor ( D) 3 destructor 29 对于一个类定义,下列叙述中错误的是 ( )。 ( A)如果没有定义拷贝构造函数,编译器将生成一个拷贝构造函数 ( B)如果没有定义缺省的构造函 数,编译器将一定生成一个缺省的构造函数 ( C)如果没有定义构造函数,编译器将生成一个缺省的构造函数和一个拷贝构造函数 ( D)如果已经定义了构造函数和拷贝构造函数,编译器不会生成任何构造函数 30 有如下程
16、序: #include using namespace std; class Part public: Part(int x=0): val(x)cout val; -Part()cout val; ) private: int val; ); class Whole public: Whole(int x, int y, int z=O): p2(x), pl(y), val(z)cout using namespace std; class Base public: Base(int x=0)cout x; ) ; class Derived: public Base public: De
17、rived(int x=0)cout x; ) private: Base val; ); int main() Derived d(1); return 0: 程序的输出结果是 ( )。 ( A) 0 ( B) 1 ( C) 01 ( D) 001 32 有如下类定义: class MyClass Int value; public; MyClass(int n): value(n) int gerValueoconstreturn value; ) ; 则类 MyClass的构造函数的个数是 ( )。 ( A) 1个 ( B) 2个 ( C) 3个 ( D) 4个 33 在 C+中,编译系
18、统自动为一个类生成缺省构造函数的条件是 ( )。 ( A)该类没有定义任何有参构造函数 ( B)该类没有定义任何无参构造函数 ( C)该类没有定义任何构造函数 ( D)该类没有定义任何成员函数 34 有如下程序: #include using namespace std; class Sample public: Sample() -Sample()cout using namespace std; class MyClass public: MyClass(int i=0)cout l; ) MyClass(const MyClass&x)cout 2; MyClass&operator=(
19、const MyClass&x)cout #include using namespace std; class XCF int a; public: XCF(int aa=0): a(aa)cout ”1”; ) XCF(XCF&X)a=x a; cout ”2”; ) -XCFOcout using namespace std; class ONE int c; public: ONE(): c(0)cout using namespace std; class Toy public: Toy(char*一 n)strcpy(name,一 n); count+; ) Toy0count一;
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 对象 模拟 答案 解析 DOC
