[计算机类试卷]国家二级(C++)机试模拟试卷79及答案与解析.doc
《[计算机类试卷]国家二级(C++)机试模拟试卷79及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级(C++)机试模拟试卷79及答案与解析.doc(32页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级( C+)机试模拟试卷 79及答案与解析 一、选择题 1 有如下类定义: class MyClass public: private: int data; ; 若要为 MyClass类重载流输入运算符 “,使得程序中可以 “cin obj;“的形式改变 MyClass类的对象 obj中数据成员 data的值,则横线处的声明语句应为 ( )。 ( A) friendistream ( B) friendistream ( C) istream ( D) istream 2 有如下程序: #include using namespace std; class A public: virtu
2、al void func1() coutfunc1(); p-func2(); delete p; return 0; 执行这个程序的输出结果是 ( )。 ( A) B1B2 ( B) A1A2 ( C) B1A2 ( D) A1B2 3 则关系 T是由关系 R和 S通过某种操作得到 ,该操作为 ( )。( A)选择 ( B)投影 ( C)交 ( D)并 4 有如下类定义: class Point private: static int how_many; ; how_many=0; 要初始化 Point类的静态成员 how_many,下画线处应填入的内容是 ( )。 ( A) int ( B
3、) staticint ( C) intPoint: ( D) staticintPoint: 5 下列模板声明中,有语法错误的是 ( A) templateTfun(Tx)returnx; ( B) templateTfun(Tx,intn)returnx*n; ( C) templateTfun(T*p)return*p; ( D) templateTclassATn; 6 下列枚举类型的定义中,包含枚举值 3的是 ( A) enumtestLEFT,UP,RIGHT,DOWN; ( B) enumtestLEFT,UP=5,RIGHT,DOWN; ( C) enumtestLEFT=-1
4、,UP,RIGHT,DOWN; ( D) enumtestLEFT,UP,RIGHT=6,DOWN; 7 如果派生类以 protected方式继承基类,则原基类的 protected成员和 public成员在派生类中的访问属性分别是 ( A) public和 public ( B) public和 protected ( C) protected和 public ( D) protected和 protected 8 已知一程序运行后执行的第一个输出操作是 cout using namespace std; class Cup public: Cup(double val=5.8):price
5、(val) void SetPrice(double val) price=val; double GetPrice() const return price; private: double price; ; int main() const Cup c1(4.5); Cup c2(29.8); c1.SetPrice(5.8); / c2.SetPrice(12.8); / c1.GetPrice(); / c2.GetPrice(); / return 0; 在标注号码的语句行中存在语法错误的是 ( A) ( B) ( C) ( D) 11 下列关于算法的描述中错误的是 ( A)算法强调
6、动态的执行过程,不同于静态的计算公式 ( B)算法必须能在有限个步骤之后终止 ( C)算法设计必须考虑算法的复杂度 ( D)算法的优劣取决于运行算法程序的环境 12 有如下程序: #include using namespace std; void fun(int i) cout using namespace std; int main() void function(double val); double val; function(val); cout using namespace std; int main() void function(double val); double va
7、l; function(val); cout T square(T x) return x * x; 其中 T是 ( )。 ( A)函数形参 ( B)函数实参 ( C)模板形 参 ( D)模板实参 22 有如下定义: int a 5 =1,3,5,7,9,*p=a; 下列表达式中不能得到数值 5的是 ( )。 ( A) a 2 ( B) a 3 ( C) *(p+2) ( D) *p+4 23 有如下程序: #include #include using namespace std; class MyBag public: MyBag(string br,string cr):brand(br
8、),color(cr) +count; MyBag() -count; static int GetCount() return count; private: string brand,color; static int count; ; _ int main() MyBag one(“CityLife“,“Gray“),two(“Micky“,“Red“); cout using namespace std; void f(int x, int x=y; y=z; int main() int x=0,y=1; f(x,y); cout T1 sum(T2, T3); double d1,
9、d2; 则下列调用中,错误的是 ( A) sum(d1,d2); ( B) sum(d1,d2); ( C) sum(d1,d2); ( D) sum(d1,d2); 27 有如下语句序列: int x=10, cout using namespace std; class Base public: void fun1() cout using namespace std; class Part public: Part(int x=0):val(x) cout usingnamespacestd; clasSClock public: Clock(unsignedlongi=0); void
10、set(unsignedlongi=0); voidprint()const; voidtick();时间前进一秒 Clockoperator+(); private: unsignedlongtotal_sec, seconds, minutes, hours, days; ; Clock: Clock(unsignedlongi) : totalsec(i), seconds(i 60), minutes(i 60) 60), hours(i 3600) 24), days(i 86400) voidClock: set(unsignedlongi) totalsec=i; seconds
11、: i 60; minutes=(i 60) 60; hours=(i 3600) 60; days=i 86400; ERROR*found* voidClock: print() cout usingnamespacestd; classString private: intsize;缓冲区大小 char*buf;缓冲区 public: String(intbufsize); voidStrcpy(char*s);将字符串 s复制到 bur中 voidPrint()const; String() if(bur!=NULL)deletebur; ; String: String(intbur
12、size) size=bursize; bur=newcharsize; *buf= 0; voidString: Strcpy(char*s) char*p*, *q; intlen=strlen(s); if(len+1size)缓冲区空间不够,须安排更大空间 size=len+1; p=q=newcharsize; *found* while(*q=*s)!=0)_ TODO:添加代码将字符串 s复制到字符指针 q中 deletebur; buf=p; else *found* for(p=bur; _; p+, s+); TODO:添加代码将字符串 s复制到 buf中 voidStri
13、ng: Print()const cout usingstd: ostream; usingstd: cout; usingstd: end1; claSSMyVector表示二维向量的类 doublex; x坐标值 doubley; y坐标值 public: MyVector(doublei=0 0, double; 0 0);构造函数 MyVectoroperator+(MyVectorj); 重载运算符 + friendMyVectoroperator-(MyVectori, MyVectorj);重载运算符 - friendostream&operator“,根据重载规则,本题答案为
14、A。 2 【正确答案】 C 【试题解析】 本题考查虚函数。虚函数指在基类中声明为 virtual 并在一个或多个派生类中被重新定义的成员函数。题中定义了一个派生类对象 B,并使用类 A的对象指针指向 B,由于基类 A中的 func1 为虚函数,所以会执行派生类的func1,输出 B1,而基类中的 func2不是虚函数,所以 p-func2()会执行基类的func2,输出 A2。故答案为 C。 3 【正确答案】 D 【试题解析】 在关系 T 中包含了关系 R与 S中的所有元组,所以进行的是并的运算。 4 【正确答案】 C 【试题解析】 本题考查静态数据成员,静态数据成员可以初始化,但只能在类体外
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 模拟 79 答案 解析 DOC
