[计算机类试卷]国家二级C++机试(类和对象)模拟试卷3及答案与解析.doc
《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷3及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷3及答案与解析.doc(22页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(类和对象)模拟试卷 3及答案与解析 一、选择题 1 有如下类声明: class Foo int bar; ; 则 Foo类的成员 bar是 ( )。 ( A)公有数据成员 ( B)公有成员函数 ( C)私有数据成员 ( D)私有成员函数 2 有如下类声明: class SAMPLE int n; public: SAMPLE(int i=0): n(i) void setValue(int n0); ; 下列关于 getValue成员函数的实现中,正确的是 ( )。 ( A) SAMPLE: setValue(int n0)n=n0; ( B) void SAMPLE: s
2、etValue(int n0)n=n0; ( C) void setValue(int n0)n=n0; ( D) (int n0)n=n0; 3 如果派生类以 protected方式继承基类,则原基类的 protected成员和 public成员在派生类中的访问属性分别是 ( )。 ( A) public和 public ( B) public和 protected ( C) protected和 public ( D) protected和 protected 4 有如下程序: #include iostream #include cstring using namespace std;
3、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()return b; ; int main() char *p1=“abcd“, *p2=“weirong“; int d1=6, d2=8; XCD x(p1, d1), y(p2, d2); cout strlen(x Geta()+y Getb() endl; return 0; 运行时的输出结果是 ( )。 ( A) 12 (
4、 B) 16 ( C) 14 ( D) 11 5 若 AA为一个类, a为该类的私有整型数据成员, getA()为该类的一个非静态公有成员函数,功能是返回 a的值。如果 x为该类的一个对象,要在类外访问 x对象中 a的 值,正确的访问格式为 ( )。 ( A) AA getA() ( B) x getA() ( C) x a ( D) AA: a 6 若有如下类声明 class MyClass public: MyClass()cout 1; ; 执行下列语句 MyClass a, b2, *p12: 以后,程序的输出结果是 ( )。 ( A) 11 ( B) 111 ( C) 1111 (
5、D) 11111 7 要定义一个引用变量 p,使之引用类 MyClass的一个对象,正确的定义语句是( )。 ( A) MyClass p=MyClass; ( B) MyClass p=new MyClass; ( C) MyClass &p=new MyClass; ( D) MyClass a, &p=a; 8 有如下类定义: class MyClass int x; public: MyClass(): x(0), y(0) int GetX()return x; void SetX(int xx)x=xx; int y; ; 已知 obj是类 MyClass的对象,下列语句中违反类成
6、员访问控制权限的是 ( )。 ( A) obj x ( B) obj y ( C) obj GetX() ( D) obj SetX(0) 9 有如下类定义: class Point int x_, y_; public: Point(): x_(0), y_(0) Point(int x, hat y=0): x_(x), y_(y) ; 若执行语句 Point a(2), b3, *c4; 则 Point类的构造函数被调用的次数是 ( )。 ( A) 2次 ( B) 3次 ( C) 4次 ( D) 5次 10 有如下程序: #include iostrearn using namespac
7、e 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 constmctor“+endl; test()Cout+“destructor“+endl; ; int main() test A(3); return 0; 运行时输出的结果是 ( )。 ( A) 3 ( B) constructor destmctor ( C) copy constructor destruc
8、tor ( D) 3 destructor 11 有如下程序: #include iostream using namespace std; class Base public: Base(int x=0)cout x; ; class Derived: public Base public: Derived(int x=0)cout x; private: Base val; ; int main() Derived d(1); return 0; 程序的输出结果是 ( )。 ( A) 0 ( B) 1 ( C) 01 ( D) 001 12 有如下程序: include ioStream
9、using namespace std; class Sample public: Sample() Sample()cout *; ; int main() Sample temp2, *pTemp2; return 0; 执行这个程序输出星号 (*)的个数为 ( )。 ( A) 1 ( B) 2 ( C) 3 ( D) 4 13 有如下程序: #include iostream using namespace std; class ONE int c; public: ONE(): c(0)cout 1; ONE(int n): c(n)cout 2; ; class TWO ONE on
10、e1; ONE one2; public: TWO(int m): one2(m)cout 3; ; int main() TWO t(4); return 0; 运行时的输出结果是 ( )。 ( A) 3 ( B) 23 ( C) 123 ( D) 213 14 有如下程序: 撑 include iostream using namespace std; class Name char name20; public: Name() strcpy(name, “); cout ?; Name(char *fname) strepy(name, fname); cout ?; ; int mai
11、n() Name names3=Name(“张三 “), Name(“李四 “); return 0; 运行此程序输出符号 ?的个数是 ( )。 ( A) 0 ( B) 1 ( C) 2 ( D) 3 15 有如下程序: #include iostream using namespace std; class CD public: CD0cout C; private: char name80; ; int main()CD a, *b, d2; return 0; 运行时的输出结果是 ( )。 ( A) CCCC ( B) CCC ( C) CC ( D) C 16 下列关于构造函数的描述中
12、,错误的是 ( )。 ( A)构造函数名与类名相同 ( B)构造函数可以有返回值 ( C)构造函数可以重载 ( D)每个类都有构造函数 17 有如下程序: #include iostream using namespace std; class Monkey public: Monkey()cout M; Monkey(char n)cout n; Monkey()cout Y; ; int main() Monkey p1, *p2; p2=new Monkey(X); delete p2; return 0: 运行这个程序的输出结果是 ( )。 ( A) MYX ( B) MYMY ( C
13、) MXY ( D) MXYY 18 下列关于 this指针的叙述中,正确的是 ( )。 ( A)任何与类相关的函数都有 this指针 ( B)类的成员函数都有 this指针 ( C)类的友元函数都有 this指针 ( D)类的非静态成员函数才有 this指针 19 下列关于 this指针的插述中,正确的是 ( )。 ( A)类的成员函数都有 this指针 ( B)类的友元函数都有 this指针 ( C)任何与类相关的函数都有 this指针 ( D)类的非静态成员函数都有 this指针 20 有如下程序: #include iostream using namespace std; class
14、 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 MyClass; cout MyClass: getCount(); delete ptr; cout MyClass: getCount(); return 0; 程序的输出结果是 ( )。 ( A)
15、121 ( B) 232 ( C) 221 ( D) 122 21 若 AA为一个类, a为该类的非静态数据成员, t在该类的一个成员函数定义中访问 a时,其书写格式为 ( )。 ( A) a ( B) AA a ( C) a ( D) AA: a 22 有如下程序: #include 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
16、 d1 getA()+d2 getA()+XA: b+d1 b endl; return O; 运行这个程序的输出结果是 ( )。 ( A) 9 ( B) 11 ( C) 13 ( D) 15 23 有如下程序: #include iostream using namespace std; class VAC public; int f() constreturn 3; int f()return 5; ; Int main() VAC v1; const VAC v2; cout v1 f() v2 f(); feturn 0; 运行时的输出结果是 ( )。 ( A) 53 ( B) 35
17、( C) 55 ( D) 33 24 有如下程序: include iostream using namespace std; class A public: A(int i): r1(i) void print()cout E r1 -; void print()constcout C r1*r1 -; private: int r1; ; int main() A a1(2); const A a2(4); a1 print(); a2 print(); return 0; 运行时的输出结果是 ( )。 ( A)运行时出错 ( B) E2-C16- ( C) C4-C16- ( D) E2
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 对象 模拟 答案 解析 DOC
