[计算机类试卷]国家二级C++机试(类和对象)模拟试卷8及答案与解析.doc
《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷8及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷8及答案与解析.doc(24页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(类和对象)模拟试卷 8及答案与解析 一、选择题 1 下列程序段中包含 4个函数。其中具有隐含 this指针的是 ( )。 int funl(); class Test public: int fun2(); friend int fun3(); static int fun4(); ( A) funl ( B) fun2 ( C) fun3 ( D) fun4 2 下列关于 this指针的描述中,正确的是 ( )。 ( A)类的成员函数都有 this指针 ( B)类的友元函数都有 this指针 ( C)任何与类相关的函数都有 this指针 ( D)类的非静态成员函数都有 t
2、his指针 3 有如下程序: #inc1ude iostream using namespace std; class Test public: Test() n+=2; Test() n =3; static int getNum() return n; private: static int n; ; int Test: n=1; int main() Test* p=new Test; delete p; cout “n=“ Test: getNum() endl; return 0; 执行后的输出结果是 ( )。 ( A) n=0 ( B) n=1 ( C) n=2 ( D) n=3
3、4 有如下程序: #inc1ude iostream using namespace std; class Obj static int i; public: Obj()i+; ) 一 Obj()i一一; ) static int getVal()return i; ) ; int Obj: i=0; void f()Obj ob2; cout ob2 getVal(); int main() Obj obl; f(); Obj *ob3=new Obj; cout ob3一 getVal(); delete ob3; cout Obj: getVal(); return 0; 程序的输出结果
4、是 ( )。 ( A) 232 ( B) 231 ( C) 222 ( D) 221 5 有如下程序: #inc1ude iostream using namespace std; class Myclass public: Myclass() +count; Myclass()一一 count; static int getCount() return count, private: static int count, ; int Myclass: count=0; int main() Myclass obj; cout obj getCount(); Myclass*ptr=new My
5、class; cout Myclass: getCount(); delete ptr; cout Myclass: getCount(); return 0; 程序的输出结果是 ( )。 ( A) 121 ( B) 232 ( C) 221 ( D) 122 6 有如下类定义: class Point private; static int how_many; ; _how_many=0; 要初始化 Point类的静态成员 how_many,下划线处应填入的内 容是 ( )。 ( A) ing ( B) staticint ( C) int Point: ( D) static int Po
6、int: 7 有如下类和对象的定义: class Constants public; static double getPI() return 3 1416; ; Constants constants, 下列各组语句中,能输出 3 1416的是 ( )。 ( A) cout constants一 getPI();和 cout Constants: gerPI(); ( B) cout constants getPI();和 cout Constants, getPI(); ( C) cout constants一 getPI();和 cout Constants一 getPI(); ( D)
7、 cout constants getPIO;和 cout Constants: getPI(); 8 若 AA为一个类, a为该类的非静态数据成员,在该类的一个成员函数定义中访问 a时,其书写格式为 ( )。 ( A) a ( B) AA, a ( C) a ( D) AA: a 9 有如下类定义: class Sample public; Sample(int x): ref(x) private: Sample(): ref(0) static int val=5; const int ref; ; 上述程序段中,错误的语句是 ( )。 ( A) ( B) ( C) ( D) 10 己知
8、类 Myclass的定义如下 class Myclass public: void functionl (Myclass c)cout c data; ) static void function2(Myclass&c)cout c data; void function3() cout data; staric void function4()cout data; private: int data; ; 其中有编译错误的函数是 ( )。 ( A) functionl ( B) function2 ( C) function3 ( D) function4 11 有如下程序: #inc1ud
9、e iostream using namespace std; class XA int a: public: static int b: XA(int aa): a(aa)b+; ) int getA() return a, ) ; int XA: b=0; int main() XA d1(4), d2(5); cout dl getA()+d2 getA()+XA: b+d1 b endl; return 0; 运行这个程序的输出结果是 ( )。 ( A) 9 ( B) 11 ( C) 13 ( D) 15 12 由于常对象不能被更新,因此 ( )。 ( A)通过常对象只能调用它的常成员
10、函数 ( B)通过常对象只能调用静态成员函数 ( C)常对象的成员 都是常成员 ( D)通过常对象可以调用任何不改变对象值的成员函数 13 有如下程序 #inc1ude iostream using namespace std; int i=1; class Fun public: static int i: int value()return i一 1; int value( )const return i+1; ; int Fun: i=2; int main() int i=3; Fun funl; const Fun fun2; return 0; 若程序的输出结果是: 123 则程序
11、中下划线处遗漏的语句是 ( )。 ( A) cout fun1 value() Fun: i fun2 value(); ( B) cout Fun: i fun1 value() fun2 value(); ( C) cout fun1 value() fun2 value() Fun: i; ( D) cout fun2 value() Fun: i fun1, value(); 14 有如下程序: #inc1ude iostream using namespace std; class VAC public; int f() constreturn 3; int f() return 5
12、; ); Int main() VAC vl; const VAC v2; cout V1 f() V2 fi(); feturn 0; ) 运行时的输出结果是 ( )。 ( A) 53 ( B) 35 ( C) 55 ( D) 33 15 有如下程序: #inc1ude iostream using namespace std; class Myclass public: Myclass(int x): val(x) void Set(int x)val=x; void Print()constcont “Val=“ Val t; ) private: int val, ; int main
13、() const Myclass obj1(10); Myclass obj2(20); obj 1 Print(); 语句 1 obj 2 Print(); 语句 2 obj1 Set(20);语句 3 obj2 Set(30); 语句 4 return 0; 其主函数中错误的语句是 ( )。 ( A)语句 1 ( B)语句 2 ( C)语句 3 ( D)语句 4 16 有如下类定义和变量定义: class A public: A()data=0; A() int GetData() const retum data; void SetData (int n) data=n; private
14、: int data; ; const A a; A b; 下列 函数调用中错误的是 ( )。 ( A) a GetData(); ( B) a SetData(10); ( C) b GetData(); ( D) b SetData(10); 17 有如下程序: #inc1ude iostream using namespace std; class A public: A(int i): rl(i) yoid print() cout E r1 _; void print() const cout C r1*rl 一 ; private: int r1, ; int main() A a
15、1(2); const A a2(4); a1 print(); a2 print(); return 0; 运行时的输出结果是 ( )。 ( A)运行时出错 ( B) E2一 C16一 ( C) C4一 C16一 ( D) E2一 E4一 18 有如下程序: #inc1ude iostream using namespace std; class A public: A(int i=0): rl(i) void print()cout E rl 一 ; voidprint() constcout C r1*rl 一 ; void print(int x)cout p r1*r 1*r1 一
16、; private: int r1, ; int main() A a1; const A a2(4); al print(2); a2 print(); rcturn 0; 运行时的输出结果是 ( )。 ( A) P8一 E4 ( B) P8一 C16一 ( C) P0一 E4一 ( D) P0一 C16一 19 某类中有一个无参且无返回值的常成员函数 Show,则正确的 Show函数原型是( )。 ( A) const void Show(); ( B) void const Show(); ( C) void Show() const; ( D) void Show(const); 20
17、 已知类 IMS中两个成员函数的声明为 “void listen() const; ”与 “void speak(); ”,另有两个对象的定义为 “IMS objl; ”与 “const IMS obj2;: ”,则下列语句中,产生编译错误的是 ( )。 ( A) objl listen(); ( B) objl speak(); ( C), obj2 listen(); ( D) obj2 speak(); 21 已知函数 print()没有返回值,如果在类中将之声明为常成员函数,正确的是( )。 ( A) void print() const; ( B) const void print(
18、); ( C) void const print(); ( D) voidprint(const); 22 有如下类定义: class Test char a; const char b; public: Test(char c)a=c; b=c; ) 第 1行 void f(char a)constthis一 a=a; ) 第 2行 void g(char b)this一 b=b; ) 第 3行 char ho constreturn a; 第 4行 ; 编译时没有错误的行是 ( )。 ( A)第 3行 ( B)第 4行 ( C)第 1行 ( D)第 2行 23 有如下类定义: class
19、AA int a; public: int getRef()const return &a, ) int getValue()const return a; ) void set(int n)const a=n; ) friend一 void show(AA aa)const cout a, ; 其中的四个函数定义中正确的是 ( )。 ( A) ( B) ( C) ( D) 24 有如下程序: #inc1ude iostream using namespace std; class Sample friend long fun (Sample s); public: Sample (long
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 对象 模拟 答案 解析 DOC
