[计算机类试卷]国家二级C++机试(类和对象)模拟试卷2及答案与解析.doc

上传人:twoload295 文档编号:497736 上传时间:2018-11-30 格式:DOC 页数:31 大小:73.50KB
下载 相关 举报
[计算机类试卷]国家二级C++机试(类和对象)模拟试卷2及答案与解析.doc_第1页
第1页 / 共31页
[计算机类试卷]国家二级C++机试(类和对象)模拟试卷2及答案与解析.doc_第2页
第2页 / 共31页
[计算机类试卷]国家二级C++机试(类和对象)模拟试卷2及答案与解析.doc_第3页
第3页 / 共31页
[计算机类试卷]国家二级C++机试(类和对象)模拟试卷2及答案与解析.doc_第4页
第4页 / 共31页
[计算机类试卷]国家二级C++机试(类和对象)模拟试卷2及答案与解析.doc_第5页
第5页 / 共31页
点击查看更多>>
资源描述

1、国家二级 C+机试(类和对象)模拟试卷 2及答案与解析 一、选择题 1 有如下程序 #include using namespace std; class Test public: Test() Test(const Test&t)cout using namespace std; class CD public: -CD0cout一 C; ) private: char name80; ); int main()CD a, *b, d2; retum 0; 运行时的输出结果是 ( )。 ( A) CCCC ( B) CCC ( C) CC ( D) C 4 有如下程序: #include u

2、sing namespace std; class XA int a; public: static int b: XA(int aa): a(aa)b+; ) XA() int get0return a; ); int XA: b=0; int main() XA d1(2), d2(3); cout using namespace std; class MyClass public: MyClass 0 cout using namespace std; class Monkey public: Monkey() cout #include using namespace std; cla

3、ss MyString public: char str80; MyString(const char*s)strcpy(str, s); MyString&operator+=(MyString a) strcat(str, a str); return*this; ) ); ostream&operator using namespace std; class Test public: Test() n+=2; ) Test() n一 3; ) static int getNum0return n; private: static int n; ); int Test: n=l; int

4、main() Test*P=new Test; delete p; cout 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; coutgetVal(); delete ob3; cout using namespace std; class MyClass public: MyClass0+count; -MyClass()一 count; static int get

5、Count()return count; private: static int count; ; int MyClass: cOunt=0; int main() MyClass obj; coutgetPl();和 coutgetPl();和 coutgetPl(); ( D) cout using namespace std; class XA int a; public: static int b; XA(int aa): a(aa)b+; int getA0return a; ; int XA: b=0: int main() XA dl(4), d2(5); cout using

6、namespace std; int i=1: class Fun public: static int i; int value()return il; int value()constreturn i+l; ) ); int Fun: i=2; int main() int i=3; Fun funl; const Fun fun2; retum O; ) 若程序的输出结果是: 123 则程序中下划线处遗漏的语句是 ( )。 ( A) cout using namespace std; class VAC public; int f() constreturn 3; int f()retu

7、rn 5; ) ; Int main() VAC vl; const VAC v2; cout using namespace std; class MyClass public: MyClass(int x): Val(x) void Set(int x)val=x; ) void Print()constcout using namespace std; class A public: A(int i): rl(i) void print() cout using namespace std; class A public: A(int i=O): r1(i) void printOcou

8、t using namespace std; class Sample friend long fun(Sample s); Sample(10ng a)x=a; private: long x; ); long fun(Sample S) if(s x()const;,所以对于本题来说无参且无返回值的常成员函数 show,其正确的函数原型是选项 C)。 33 【正确答案】 D 【试题解析】 函数: listen(、 )作为类 IMS的常成员函数,一般对象 obi和常对象obj2都可以调用它,而函数 speak()作为 IMS的一般成员函数,则只有一般对象objl可以调用,而常对象 obi2调

9、用会产生编译错误。 34 【正确答案】 A 【试题解析】 const成员函数表示该成员函数只能读类数据成员,而不能修改类成员数据。定义 const成员函数时,把 const关键字放在函数的参数表和函数体之间。 35 【正确答案】 D 【试题解析】 类 Test中 的常成员函数 h()返回数据成员 a的值。 36 【正确答案】 B 【试题解析】 此题考查了常成员函数和友元函数的概念。选项 A中, getRef()函数的返回值和函数函数类型不符,故错误; C选项中 set()常成员函数改变了数据成员的值,这是不允许的: D选项中 show()函数被同时定义成友元函数和常成员函数是错误的。 37 【

10、正确答案】 C 【试题解析】 此题考查的是友元函数和递归函数。因为 fun函数是 Sample类的友元函数,所以 fun函数可以直接访问 Sample类对象的私有成员 x。主函数调用fun函数,构造参数为 0 5。当 n小于 2时, fun函数返回 l,其余返回值为n*fun(n-1)。 n取 0 5的值时 fun(n)依次为 1, l, 2, 6, 24, 120,累加结果为154。 38 【正确答案】 A 【试题解析】 这段程序是正确的,计算 p距离原点的距离。语句 是类 Point的构造函数,在构造函数中给变量 xx和 yy赋初值 0。语句 是计算点 p距原点的距离的函数 distance。语句 是计算点 p1距离原点的距离并输出。 39 【正确答案】 A 【试题解析】 程序中定义了类 Car和类 Boat,在两个类中分别定义他们的构造函数和友元函数 friend。程序在 VC6 0中编译通过。 40 【正确答案】 C

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试资料 > 职业资格

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1