[计算机类试卷]国家二级C++机试(操作题)模拟试卷488及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷488及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷488及答案与解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 488及答案与解析 一、基本操作题 1 请打开考生文件夹下的解决方案文件 proj1,此工程包含一个源程序文件proj1 cpp。文件中将表示数组元素个数的常量 Size定义为 4,并用 int类型对类模板进行了实例化。文件中位于每个注释 “ ERROR*found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: 1 2 3 4 注意:模板参数名用 T。只修改注释 “ ERROR*found*”的下一行语句,不要改 动程序中的其他内容。 proj1 cpp #include iostream using namespace std; 将数组
2、元素个数 size定义为 4 ERROR*found* const int size; template typename T class MyClasS public: MyClass(T*p) for(int i=0; i Size; i+) arraysi=pj; void Print( ); private: Tarraysize; ; template typename T ERROR*found* void MyClass: Print( ) for(int i=0; i size; i+) cout arrayi t; int main( ) int intArraySize=1
3、, 2, 3, 4; ERROR*found* MyClass double obj(intArray); obj Print( ); cout endl; return0; 二、简单应用题 2 请打开考生文件夹下的解决方案文件 proj2,该工程中包含一个程序文件main cpp,其中有日期类 Date、人员类 Person及排序函数 sortByName和主函数main的定义。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义和函数定义。此程序的正确输出结果应为: 按姓名排序 排序前 张三 男 出生日期: 1978年 4月 20日 王五 女 出生日期: 1965年 8月 3日 杨
4、六 女 出生日期: 1965年 9月 5日 李四 男 出生 日期: 1973年 5月 30日 排序后: 李四 男 出生日期: 1973年 5月 30日 王五 女 出生日期: 1965年 8月 3日 杨六 女 出生日期: 1965年 9月 5日 张三 男 出生日期: 1978年 4月 20日 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动 “ *found*”。 #include iostream using namespace std; class Date日期类 int year, month, day;年、月、日 public: Date(int year,
5、int month, int day): year(year), month(month), day(day) int getYear( )constreturn year; int getMonth( )constreturn month; int getDay( )constreturn day; ; class Person人员类 char name14;姓名 bool is_male;性别,为 true时表示男性 Date birth_date;出生日期 public: Person(char*name, bool is_male, Datebirth_date) *found* :
6、_ strcpy(this- name, name); const char*getName( )constreturn name; bool isMale( )constreturnis male; Date getBirthdate( )constreturn birth date; 利用 strcmp( )函数比较姓名,返回一个正数、 0或负数,分别表示大于、等于、小于 int compareName(const Person&p)const *found* _) void show( ) cout endl; cout name fiSmale?“男 “: “女 “) “出生日期: “
7、 birth date getYear( ) “年 “显示出生年 *found* 显示出生月 birth date getDay( ) “日 “;显示出生日 ; void sortByName(Person ps , int Size) 将人员数组按姓名排列为升序 for(int i=0; i size-1; i+) 采用选择排序算法 int m=i; for(int j=i+1; j size; j+) if(psj compareName(ps m) 0) m=j; if(m i) Person p=psm; psm=psi; Lpsm=psi; psi=p; int main( ) Pe
8、rson staff =f Person(“张三 “, true, Date(1978, 4, 20), Person(“王五 “, false, Date(1965, 8, 3), Person(“杨六 “, false, Date(1965, 9, 5), Person(“李四 “, true, Date(1973, 5, 30) ; const int size=sizeof(staff) sizeof(staff0); int i; cout endl “按姓名排序 “; cout endl “排序前: “; for(i=0; i Size; i+)staffi show( ); So
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 488 答案 解析 DOC
