[计算机类试卷]国家二级(C++)机试模拟试卷109及答案与解析.doc
《[计算机类试卷]国家二级(C++)机试模拟试卷109及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级(C++)机试模拟试卷109及答案与解析.doc(32页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级( C+)机试模拟试卷 109及答案与解析 一、选择题 1 有如下程序: #include using namespace std; class Base public: void fun1() cout double 由此可知 ( )。 ( A)这可能是一个函数模板的声明 ( B)这 可能是一个类模板的声明 ( C)这既可能是一个函数模板的声明,也可能是一个类模板的声明 ( D)这肯定是一个错误的模板声明 5 有如下程序段: int i=2;int j=3; int main() int i=9, j=i; coutdata;“中, cin是 ( A) C+的关键字 ( B)类名 (
2、 C)对象名 ( D)函数名 8 有如下程序: #include using namespace std; int main() int a10; for(int* p=a;p using namespace std; class Point int x,y; public: Point(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
3、) int get() return center.get()+radius; ; int main() Circle c(3,4,5); cout using namespace std; class AA public: virtual void disp() cout using namespace std; class Base private: void fun1() const cout using namespace std; void fun(int a,_) int c; c=a; a=*b; *b=c; int main() int x,y; x=1; y=2; fun(x
4、, cout using namespace std; class A public: virtual void func1() coutfunc1(); p-func2(); delete p; return 0; 执行这个程序的输出结果是 ( )。 ( A) B1B2 ( B) A1A2 ( C) B1A2 ( D) A1B2 21 必须用一对大括号括起来的程序段是 ( )。 ( A) switch语句中的 case标号语句 ( B) if语句的分支 ( C)循环语句的循环体 ( D)函数的函数体 22 有如下两个类定义: class XX private: double x1; prot
5、ected: double x2; public: double x3; ; class YY: protected XX private: double y1; protected: double y2; public: double y3; ; 在类 YY中保护成员变量的个数是 ( )。 ( A) 1 ( B) 2 ( C) 3 ( D) 4 23 在满足实体完整性约束的条件下 ( )。 ( A)一个关系中应该有一个或多个候选关键字 ( B)一个关系中只能有一个候选关键字 ( C)一个关系中必须有多关键字个候选 ( D)一个关系中可以没有候选关键字 24 下列关于运算符重载的叙述中,错误的
6、是 ( A)不能通过 运算符重载在 C+中创建新的运算符 ( B)赋值运算符只能重载为成员函数 ( C)运算符函数重载为类的成员函数时,第一操作数是该类对象 ( D)重载类型转换运算符时,应声明返回类型为 void 25 有如下程序: #include #include using namespace std; class Instrument public: Instrument(string t=“乐器 “,string n=“无名 “):type(t),name(n) string GetType() const return “乐器 “; string GetName() const
7、return “无名 “; protected: string type,name; ; class Piano:public Instrument public: Piano(string 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; 运行时的输出
8、结果是 ( A)乐器 -星空 ( B)乐器 -无名 ( C)钢琴 -星空 ( D)钢琴 -无名 26 有如下程序: #include using namespace std; int main() int f,f1=1,f2=1; for(int i=0;i using namespace std; class Point int x,y; public: Point(int x1=0, int y1=0):x(x1),y(y1) int get() return x+y; ; class Circle Point center; int radius; public: Circle(int
9、cx, int cy, int r):center(cx,cy),radius(r) int get() return center.get()+radius; ; int main() Circle c(3,4,5); cout using namespace std; void fun(int c=a; a=b; b=c; int main() int x,y; x=1; y=2; fun(x,y); coutbark() ( D) (*p).bark() 33 有如下说明: int a 10 =1,2,3,4,5,6,7,8,9,10,*p=a; 则数值为 9的表达式是 ( )。 ( A
10、) *p+9 ( B) *(p+8) ( C) *p+=9 ( D) p+8 34 若有如下类声明: class MyClass public: MyClass() cout using namespace std; class Sample public: Sample() Sample() cout usingnamespacestd; 狗的颜色:黑、白、黄、褐、花、其他 enLlmDOGCOLORBLACK, WHTTE, YELLOW, BRONN, PIEBALD, OTHER); classDog 狗类 DOGCOLORcolor; charname20; staticintcou
11、nt; public: Dog(char lame, DOGCOLORcolor) strcpy(this-flame, Flame); EERR*found* strcpy(this-color, color); DOGCOLORget: Color()constreturn color; ERROR*found* constchar*get; Name()constreturn*name; constchar*getColorString() const switch(color) caseBLACK: return“black“; caseWHITE: return“white“; ca
12、seYELLOW: return“yellow“; caseBROWN: return“brown“; casePrEBALD: return“piebald“; return”motley”; voidshow()const tout usingnamespacestd; classCPolygon public: *found* _纯虚函数 area声明 voidprintarea(void) *found* coutprintarea(); ppoly2-printarea(); return0; 四、综合应用题 43 请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程
13、proj3,其中声明了 SortedList类,是一个用于表示有序数据表的类。其成员函数 insert的 功能是将一个数据插入到一个有序表中,使得该数据表仍然保持有序。请编写这个 insert函数。程序的正确输出应为: 插入前: 1, 2, 4, 5, 7, 8, 10 插入 6和 3后: 1, 2, 3, 4, 5, 6, 7, 8, 10 要求: 补充编制的内容写在 “ *333*”与 “*666*”之间。不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out dat中。输出函数 writeToFile已经编译为0bj文件,并且在本程序中调用。 SortedList h #inc
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
本资源只提供5页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 模拟 109 答案 解析 DOC
