[计算机类试卷]国家二级C++机试(操作题)模拟试卷504及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷504及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷504及答案与解析.doc(7页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 504及答案与解析 一、基本操作题 1 请打开考生文件夹下的解决方案文件 proj1,此工程中包含程序文件main cpp,其中有类 Score(“成绩 ”)和主函数 main的定义。程序中位于每个 “ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 学号: 12345678课程:英语总评成绩: 85 注意:只修改每个 “ ERROR*found*”下的一行,不要改动程序中的其他内容。 #include iostream using namespace std; Class score public: Score (c
2、onst char*the_course, const char*the_id, int the_normal, int the_midterm,int the end_of_term) : course(the_course), normal(the_normal), midterm(the_midterm),end_of_term(the_end_of_term) ERROR*found* strcpy(the_id, student_id); const char*getCourse( )const(return course; 返回课程名称 ERROR*found* const cha
3、r*getID( )constreturn&student_id; )返回学号 int getNormal( )constreturnnormal; 返回平时成绩 int getMidterm( )constreturn midterm; 返回 期中考试成绩 int getEndOfTerm( )constreturn end_of_term; 返回期末考试成绩 int getFinal( )const;返回总评成绩 private: const char*course;课程名称 char student id12;学号 int normal;平时戍绩 int midterm;期中考试成绩 i
4、nt end of term;期考试成绩 ; 总评成绩中平时成绩占 20,期中考试占 30,期末考试占 50,最后结果四 舍五入为一个整数 ERROR*found* int getFinal( )const return normal*0 2+midterm*0 3+end_of_term*0 5+0 5; int main( ) char English =“英语 “; Score score(English, “12345678“, 68, 83, 92); cout “学号: “ score getID( ) “ “; cout “课程: “ score get-Course( ) “
5、“; cout “总评成绩: “ score getFinal( ) endl; return0; 二、简单应用题 2 请打开考生文件夹下的解决方案文件 proj2,该工程中含有一个源程序文件proj2 cpp,请将堆栈类的定义补充完整。使程序的输出结果为: The element of stack are: 4 3 2 1 注意:请勿修改主函数 main和其他函数中的任何内容,只在横线处编写适当代码,不要改动程序中的其他内容,也不要删除或移动 “ *found*”。 proj2 cpp #include iostream using namespace std; const int Size
6、=5; class Stack; class Item public: *found* Item(const int&val): _构造函数对 item进行初始化 private: int item; Item*next; friend class Stack; ; Class Stack public: Stack( ): top(NULL) Stack( ); int Pop( ); void Push(const int&); private: Item*top; ; Stack: Stack( ) Item*p=top, *q; while(p!=NULL) ( q=p- next;
7、*found* _;释放 p所指向的节点 p=q; int Stack: Pop( ) Item*temp; int ret; *found* _;使 temp指向栈顶节点 ret=top- item; top=top- next; delete temp; return ret; void Stack: Push(const int&val) Item*temp=new Item(val); *found* _; 使新节点的 next指针指向栈顶数据 top=temp; int main( ) Stack s; for(int i=1; i Size; i+) s Push(i); cout
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 504 答案 解析 DOC
