[计算机类试卷]国家二级C++机试(类和对象)模拟试卷5及答案与解析.doc
《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷5及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷5及答案与解析.doc(22页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(类和对象)模拟试卷 5及答案与解析 一、选择题 1 有如下类定义: class Test public: Test()a=0; C=0; int font 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) 2 下列关于类定义的说法中,正确的是 ( )。 ( A)类定义中包括数据成员和
2、函数成员的声明 ( B)类成员的缺省访问权限是保护的 ( C)数据成员必须被声明为私有的 ( D)成员函数只能在类体外进行定义 3 下列运算符函数中,肯定不属于类 Value的成员函数的是 ( )。 ( A) Value operator+(Value); ( B) Value operator-(Value, Value); ( C) Value operator*(int); ( D) Value operator (Value); 4 有如下程序: #include iostream using namespace std; class Point int x, y; public: P
3、oint(int x1=0, int y1=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 get()return center get()+radius; ; int main() Circle c(3, 4, 5); cout c get() endl; return 0; 运行时的输出结果是 ( )。 ( A) 5 ( B) 7 ( C) 9
4、( D) 12 5 下列关于类和对象的叙述中,错误的是 ( )。 ( A)一个类只能有一个对象 ( B)对象是类的具体实例 ( C)类是对某一类对象的抽象 ( D)类 和对象的关系是一种数据类型与变量的关系 6 若 MyClass是一个类名,且有如下语句序列 MyClass c1, *c2; MyClass *c3=new MyClass; MyClass &c4=c1; 上面的语句序列所定义的类对象的个数是 ( )。 ( A) 1 ( B) 2 ( C) 3 ( D) 4 7 有如下程序: #include iostream using namespace std; class Pair i
5、nt m, n; public: Pair(int j, int k): m(j), n(k) int get()return m; int get()constreturn m+n; ; int main() Pair a(3, 5); const Pair b(3, 5); cout a get() b get(); return 0; 运行时的输出结果是 ( )。 ( A) 33 ( B) 38 ( C) 83 ( D) 88 8 在下列函数原型中,可以作为类 AA构造函数的是 (。 ( A) void AA(int); ( B) int AA(); ( C) AA(int)const;
6、 ( D) AA(int); 9 有如下程序 #include iostream #include iomanip using namespace std; class MyClass public: MyClass()cout A MyClass(char c)cout c; MyClass()cout B; ; int main() MyClass p1, *p2; p2=new MyClass(X); delete p2; return 0; 执行这个程序屏幕上将显示输出 ( )。 ( A) ABX ( B) ABXB ( C) AXB ( D) AXBB 10 有如下程序: #incl
7、ude iostream 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=0): p2(x), p1(y), val(z)cout val; Whole()cout val; private: Part p1, p2; int val; ; int main() Whole obj(1, 2, 3); return 0; 程序的输出结果是
8、( )。 ( A) 123321 ( B) 213312 ( C) 213 ( D) 123123 11 在 C+中,编译系统自动为一个类生成缺省构造函数的条件是 ( )。 ( A)该类没有定义任何有参构造函数 ( B)该类没有定义任何无参构造 函数 ( C)该类没有定义任何构造函数 ( D)该类没有定义任何成员函数 12 有如下程序: #include iostream #include cstring using namespace std; class XCF int a: public: XCF(int aa=0): a(aa)cout “1“; XCF(XCF&x)a=x a; co
9、ut “2“; XCFOcout a; int Geta()return a; ; int main() XCF d1(5), d2(d1); XCF *pd=new XCF(8); cout pd- Geta(); delete pd; return 0; 运行时的输出结果是 ( )。 ( A) 1215588 ( B) 1218855 ( C) 12185 ( D) 128512 13 有如下程序: include iostream using namespace std; class Toy public: Toy(char*_n)strcpy(nnine, _n); count+; T
10、oy()count-; char* GetName()return name; static int getCountOreturn count; private: char name10; static int count; ; int Toy: Count=0; int main() Toy t1(“Snoopy“), ta(“Mickey“), t3(“Barbie“); eout t1 getCount() endl; return 0; 运行时的输出结果是 ( )。 ( A) 1 ( B) 2 ( C) 3 ( D)运行时出错 14 若 MyClass为一个类,执行 “MyClass
11、 a4, *p5; ”语句时会自动调用该类构造函数的次数是 ( )。 ( A) 2 ( B) 5 ( C) 4 ( D) 9 15 下列关于析构函数的描述中,错误的是 ( )。 ( A)析构函数可以重载 ( B)析构函数由系统自动调用 ( C)每个对象的析构函数只被调用一次 ( D)每个类都有析构函数 16 有如下程序: #include iostream using namespace std; class MyClass public: MyClass ()cout *; MyClass (MyClass& a)cout ; MyClass ()cout ; ; int main(); M
12、yClass a; Myclass b(a); return 0; 运行时的输出结果是 ( )。 ( A) * ( B) * ( C) * ( D) * 17 有如下程序: #include iostream #include cstring using namespace std; class MyString public: char str80; MyString(const char* s)strcpy(str, s); MyString& operator+=(MyString a) strcat(str, a str); return *this; ; ostream& opera
13、tor (ostream& s,const MyString& z)return s z str; int main() MyString x(“abc“), y(“cde“); cout (x+=y) endl; return 0; 运行这个程序的输出结果是 ( )。 ( A) abc ( B) cde ( C) abcde ( D) abccde 18 下列程序段中包含 4个函数。其中具有隐含 this指针的是 ( )。 int fun1(); class Test public: int fun2(); friend int fun3(): static int fun4(); ( A)
14、 fun1 ( B) fun2 ( C) fun3 ( D) fun4 19 有如下程序: 撑 include 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
15、: getVal(); return 0; 程序的输出结果是 ( )。 ( A) 232 ( B) 231 ( C) 222 ( D) 221 20 有如下类和对象的定义: class Constants public; static double getPI()return3 1416; ; Constants constants; 下列各组语句中,能输出 3 1416的是 ( )。 ( A) cout constants- getPI();和 cout Constants: gerPI(); ( B) cout constants getPI();和 cout Constants getP
16、I(); ( C) cout constants- getPI();和 cout Constants- getPI(); ( D) cout constants getPI();和 cout Constants: getPI(); 21 已知类 Myclass的定义如下 class MyClass public: void function1(MyClass& c)cout c data; static void function2(MyClass& c)cout c data; void function3()cout data; staric void function4()cout da
17、ta; private: int data; ; 其中有编译错误的函数是 ( )。 ( A) function1 ( B) function2 ( C) function3 ( D) function4 22 有如下程序 #include iostream using namespace std; int i=1; class Fun public: static int i; int value()return i-1; int value()constreturn i+1; ; int Fun: i=2; int main() int i=3: Fun fun1; const Fun fu
18、n2; return ; 若程序的输出结果是: 123 则程序中下划线处遗漏的语句是 ( )。 ( 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(); 23 有如下类定义和变量定义: class A public: A()data=0; A() int GetData() constreturn dat
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 对象 模拟 答案 解析 DOC
