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