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

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

1、国家二级 C+机试(操作题)模拟试卷 392及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹下的源程序文件 modil cpp,该程序运行时有错,请改正其中的错误,使程序正常运行,并使程序输出的结果为: TestClass2 TestClass3 注意:不要改动 main函数,不能增行或删行,也不能更改程序的结构, 错误的语句在 *error*的下面。 #include Class TestClass1 public: virtual Void fun()=0; ; class TestClass2: public TestClassl *error* int fun() usin

2、g namespace std; coutfun(); obj 2 fun(); return; 二、简单应用题 2 使用 VC6打开考生文件夹下的源程序文件 modi2 epp。阅读下列函数说明和代码。函数 sort(int&m, int&n, mt&1)实现将三个整数 m、 n、 1由大到小输出。 m最大, 1最小。 程序分析:程序实现时,可以把最大的数放到 m上,先将 m与 n进行比较,如果 m void sort(int m, int n, int 1) int main() int=9 ; int y=13; int z=一 3; sort(x, y, z); cout #inclu

3、de #include #include using namespace std; void WriteFile(int c) 0fstream out1; out1 open(“modi 3 txt”, ios base: app); out1c : out1 close(); void WriteFile(char*str) ofstream out1; out1 open(“modi3 txt”, ios base: app); outlstr; out1 close(); void ClearFiie() ofstream out1; out1 open(“modi3 txt”); o

4、ut1 close(); cass Date public: Date(int y, int m, int d) *2* void print()const; *3* month+=m; int i=month 1 2; int j=month 12; if(j=0) year+=(i一 1); month=12; else year+=i; month=j; return*this; private: *1* ; void Date: print()const *4* WriteFile(year); WriteFile(“年 ”); WriteFile(month); WriteFile(

5、“月 ”); WriteFile(day); WriteFile(“日 ”); int msin() ClearFile(); Date Olyday(2 0 0 8, 8, 8); Oly day+=3; Olyday print(); return 0; 国家二级 C+机试(操作题)模拟试卷 392答案与解析 一、基本操作题 1 【正确答案】 (1)void fun() (2)添加语句: public: (3) std: cout“TestClass3”std: endl;或者添加 using namespace std; 【试题解析】 本题 程序中的功能为输出字符串 TestClass2

6、和 TestClass3。从已定源程序的 main主函数开始入手,可以看出程序通过定义类的对象,利用类中定义的成员函数完成题目中要求的输出。 二、简单应用题 2 【正确答案】 Int t; if(mn) t=m; m=n; n=t; ) *交换 x, y的值 * if(m1) t=mj m=1 ; 1=t; ) *交换 x, z的值 * if(n1) t=n; n=1; 1=t; *交换 x, y的值 * 【试题解析】 sort函数实现 3个参数的从大到小的排序,可以 采用很多方法来排序,比如选择法排序、冒泡法排序等,这里要求采用比较的方法来实现排序,由于需要排序的数据较少,只有 3个,逐个比较就可以找到最大最值小进行排序。 三、综合应用题 3 【正确答案】 (1)添加语句: int year, month, day; (2)添加语句: year=y; month=m; day=d; (3)添加语句: Date operator+=(int m) (4)添加语句: coutyear“年 ”month”月 ”day”日 ”endl; 【试题解析】 在 VC环境下打开程序,根据题干给出的几条功能要求,对程序中给出注释下的内容逐个补全或修改。从已给定源程序的 main主函数开始入手,可以看出程序通过调用类 Date和函数 print实现各种输出操作。

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

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

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