[计算机类试卷]国家二级(C++)机试模拟试卷84及答案与解析.doc
《[计算机类试卷]国家二级(C++)机试模拟试卷84及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级(C++)机试模拟试卷84及答案与解析.doc(30页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级( C+)机试模拟试卷 84及答案与解析 一、选择题 1 有如下类声明: class SAMPLE int n; public: SAMPLE(int i=0):n(i) void setValue(int n0); ; 下列关于 getValue成员函数的定义中,正确的是 ( )。 ( A) SAMPLE:setValue(intn0)n=n0; ( B) voidSAMPLE:setValue(intn0)n=n0; ( C) voidsetValue(intn0)n=n0; ( D) setValue(intn0)n=n0; 2 下面叙述中错误的是 ( )。 ( A)软件测试的目
2、的是发现错误并改正错误 ( B)对被调试的程序进行 “错误定位 “是程序调试的必要步骤 ( C)程序调试通常也称为 Debug ( D)软件测试应严格执行测试计划,排除测试的随意性 3 关于函数重载,下列叙述中错误的是 ( )。 ( A)重载函数的函数名必须相同 ( B)重载函数必须在参数个数或类型上有所不同 ( C)重载函数的返回值类型必须相同 ( D)重载函数的函数体可以有 所不同 4 有如下程序: #include using namespace std; class AA int k; protected: int n; void setK(int k) this-k=k; publi
3、c: void setN(int n) this-n=n; ; class BB: public AA /*类体略 */ ; int main() BB x; x.n=1; /1 x.setN(2); /2 x.k=3; /3 x.setK(4); /4 return 0; 在标注号码的四条语句中正确的是 ( )。 ( A) 1 ( B) 2 ( C) 3 ( D) 4 5 下面不属于需求分析阶段任务的是 ( )。 ( A)确定软件系统的功能需求 ( B)确定软件系统的性能需求 ( C)需求规格说明书评审 ( D)制定软件集成测试计划 6 下列运算符中,不能被重载的是 ( A) | ( B)
4、+= ( C) . ( D) - 7 有如 下程序: #include #include using namespace std; class Instrument public: Instrument(string t=“乐器 “,string n=“无名 “):type(t),name(n) string GetType() const return “乐器 “; string GetName() const return “无名 “; protected: string type,name; ; class Piano:public Instrument public: Piano(st
5、ring n,string t=“钢琴 “):Instrument(t,n) string GetType() const return “钢 琴 “; string GetName() const return name; ; int main() Instrument *pi=new Piano(“星空 “); coutGetType()GetName(); delete pi; return 0; 运行时的输出结果是 ( A)乐器 -星空 ( B)乐器 -无名 ( C)钢琴 -星空 ( D)钢琴 -无名 8 有三个关系 R, S和 T如下:则由关系 R和 S得到关系 T的操作是 ( A)
6、选择 ( B)投影 ( C)交 ( D)并 9 有如下类定义: class Sample public: Sample(int x):ref(x) / Sample():ref(0) / private: static int val=5; / const int ref; / ; 上述程序段中,错误的语句是 ( A) ( B) ( C) ( D) 10 在下列表述中,用来正确表示 “相对于当前位置 “文件定位方式的是 ( A) ios_base:cur ( B) ios_base:beg ( C) ios_base:out ( D) ios_base:end 11 下列字符中,可以出现在合法
7、的 C+标识符中的是 ( A) : ( B) ( C) public: Point() : xx(0), yy(0) Point(int x, int y =0) : xx(x), yy(y) ; 若执行语句 Point a(2), b 3 , *c 4 ; 则 Point类的构造函数被调用的次数是 ( )。 ( A) 2次 ( B) 3次 ( C) 4次 ( D) 5次 16 在线性表的顺序存储结构中,其存储空间连续,各个元素所占的字节数 ( A)相同,元素的存储顺序与逻辑顺序一致 ( B)相同,但其元素的存储顺序可以与逻辑顺序不一致 ( C)不同,但元素的存储顺序与逻辑顺序一致 ( D)不
8、同,且其元素的存储顺序可以与逻辑顺序不一致 17 p是指向 ClassA类型对象的指针。执行 deletep;时,系统自动调用 ( A)析构函数 ( B)构造 函数 ( C)静态函数 ( D)友元函数 18 有如下函数模板: template T square(T x) return x * x; 其中的 参数 T是 ( A)函数形参 ( B)函数实参 ( C)模板实参 ( D)模板形参 19 下列运算符中,不能重载为类的友元函数的运算符是 ( A) + ( B) ( C) new ( D) class Pair int m,n; public: Pair(int j,int k):m(j),
9、n(k) int get() return m; int get() const return m+n; ; int main() Pair a(3,5); const Pair b(3,5); cout #include using namespace std; class TV public: TV(int s=41):size(s) cout ( D) 38 下列有关运算符重载的表述中,正确的是 ( A)通过重载运算符时可以改变运算符的结合性 ( B)通过运算符重载可以创造新的运算符 ( C) C+中所有运算符都可以重载为非成员 函数 ( D)运算符重载是多态性的一种表现 39 有如下程
10、序: #include #include using namespace std; class Animal public: virtual string GetType() const return “Animal“; virtual string GetVoice() const return “Voice“; ; class Dog:public Animal public: string GetType() const return “Dog“; string GetVoice() const return “Woof“; ; class Cat:public Animal publi
11、c: string GetType() const return “Cat“; string GetVoice() const return “Miaow“; ; void Type(Animal void fun(int i) cout usingnamespacestd; classMyClass public: MyClass(intvalue) ERROR*found* this value=value; count+; ERROR*found* voidMyClass() Count-; staticintgetCount()return count; intgetValue()re
12、turnvalue; private: intvalue; staticintcount; ; ERROR*found* staticintMyClass: count=0; intmain() MyClass*p=newMyClass(5); MyClass*q=newMyClass(10); cout getValue() getValue() #include usingnamespacestd; classPoint坐标点类 public: constdoublex, y; Point(doublex=0 0, doubley=0 0): x(x), y(y) doubledistan
13、ceTo(PointP)const 到指定点的距离 *found* returnsqrt(x-p x)*(xp x)+_); ; constdoublePI=3 1415926535;圆周率 classCirclef圆类 Pointcentre;圆心 doubleradius;半径 public: Circle(PointC, doubler): centre (c), radius(r) doubleperimeter()圆的周长 return2*PI*radius; doublearea()圆的面积 *found* _; ; classCylinder圆柱体 Circlebottom;圆柱
14、体圆形底部 doubleheight;圆柱体高 public: Cylinder(Circleb, doubleh): bottom(b), height(h) doublearea()圆柱体表面积 *found* returnbottom area()*2 +_; doublevolume()圆柱体体积 *found* _; ; intmain() Cylindercy(Circle(Point(2 0, 3 0), 5 0), 8 0); cout usingnamespacestd; classDate日期类 intyear, month, day;年、月、日 public: Date(
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 模拟 84 答案 解析 DOC
