[计算机类试卷]国家二级C++机试(操作题)模拟试卷477及答案与解析.doc

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

1、国家二级 C+机试(操作题)模拟试卷 477及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,其中在编辑窗口内显示的主程序文件中定义有类 ABC和主函数 main。程序文本中位于每行 “ ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: 21 23 注意:只修改每个 “ ERROR*found*”下面的一行,不要改动程序中的其他任何内容。 #include using namespace std; class ABC public: ERROR *found* ABC()a=0; b=0;

2、C=0; ABC(int aa, int bb, int cc; void Setab()+a, +b; int Sum()return a+b+c; private: int a, b; const int c; ; ABC: ABC(int aa, int bb, int cc): c(cc)a=aa; b=bb; int main() ABC x(1, 2, 3), y(4, 5, 6); ABC z, *w=&z; w-Setab(); ERROR *found* int s1=x Sum()+y-Sum(); cout using namespace std; class Room

3、“房间 ”类 int room no; 房间号 double length; 房间长度 (m) double width; 房间宽度 (m) public: Room(int the_room_no, double the_length, double the_width): room_no(the_room_no), length (the_length), width(the_width) int theRoomNo()constreturn room_no; 返回房间号 double theLength()constreturn length; )返回房间长度 double theWid

4、th()constreturn width; )返回房间宽度 *found* double theArea()const_返回房间面积 (矩形面积 ) ; class Office: public Room “办公室 ”类 char*depart;所属部门 public: Office(int the room no, double the_length, double the_width, const char *the depart) *found* : _ depart=new charstrlen(the depart)+1; *found* strcpy(_); Office()de

5、lete depart; const char*theDepartment() constreturn depart; 返回所属部门 ; int main() *found* Office_; coutA- # A- # A- # exiting inner block exiting outer block 注意:只在函数 Prepend的 “ *333*”和 “*666*”之间填入若干语句,不要改动程序中的其他内容。 sList h Struer sListItem char data; sListItem*next; ; class sList public: sList(): h(0)

6、 0表示空链表 sList(); void Prepend(char c); 在链表前端加入元素 void Del(); 删除链表首元素 sListItem*First()const(return h; 返回链表首元素 void Print()const; 打印链表内容 void Release(); 销毁链表 private: sListItem*h; 链表头 ; void writeToFile(const char* ); main cpp #include #include“sList h“ using namespace std; sList: sList() Release();

7、void sList: Prepend(char c) *333* *666* void sList: Del() sLisstItem*temp=h; h=h-next; delete temp; void sList: Print()const sListItem*temp=h; while(temp!=0) 判断是否到达链表尾部 coutdata“; temp=temp-next; coutPrint(); coutSum(); 【试题解析】 (1)主要考查考生对构造函数的掌握情况,根据私有成员的定义:const int c;可知, c为常变量,因此构造函数必须使用成员列表初始化来给 c

8、赋初始值。 (2)主要考查考生对类的指针的掌握情况,根据主函数的第一条语句: ABC x(1,2, 3), y(4, 5, 6);可知, x和 y都是 ABC类,但不是指针,因此它们调用 ABC类的成员函数要使用标识符 “ ”,而不是 “-”。 (3)主要考查考生对类的指针的掌握情况,根据主函数的第二条语句: ABC z,*w=&z;可知, w是 ABC类的指针,指向 z,因此 w调用 ABC类的成员函数时要使用标识符 “-”,而不是 “ ”。 二、简单应用题 2 【正确答案】 (1)return length*width; (2)Room(the_room_no, the_length, t

9、he_width) (3)depart, the_depart (4)an_office(308, 5 6, 4 8, “会计科 “) 【试题解析】 (1)主要考查考生 对成员函数的掌握,题目要求返回房间面积 (矩形面积 )。由此可知空格部分要填写的是一个 return语句,返回房间面积,也就是length*width,因此可以得出程序 return length*width;。 (2)主要考查考生对派生类的构造函数的掌握,派生类的构造函数要使用成员列表初始法先对基类进行初始化。 (3)考查 strcpy函数,由前一条语句 depart=new charstrlen(the_depart)+1

10、;可知,程序给 depart分配了长度为 the_depart串长加 l的空间, 因此要复制字符串the_depart串到 depart,直接填写 strcpy(depart, the_depart)即可。 (4)主要考查考生对类的掌握,题目要求输出的结果为: 办公室房间号: 308 办公室长度: 5 6 办公室宽度: 4 8 办公室面积: 26 88 办公室所属部门:会计科 由 Office类的构造函数可知要定义的一个 Office类的对象为 an_office(308,5 6, 4 8, “会计科 “)。 三、综合应用题 3 【正确答案】 sListItem*temp=new sListItem; 动态分配空间给结构体 temp的指针 temp-data=c; 把 c赋值于结构体 temp成员 datatemp-next=h; 把 h赋值于结构 temp体成员 nexth=temp; 把 temp赋值给 h,即 h指向 temp指向的空间 【试题解析】 主要考查考生对链表的掌握,成员函数 Prepend的功能是在链表头部加入一个新元素。形参 c是一个 char型变量,因此要定义一个新的结构体指针temp,并给它分配 sListhem类型空间,把形参 c中的值赋给 temp的数据域,并使 temp通过指针链接到链表上。

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

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

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