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

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

1、国家二级 C+机试(操作题)模拟试卷 290及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1。程序中位于每个 “ ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name: Smith Age: 21 ID: 99999 Course Num: 12 Record: 970 注意:只修改每个 “ ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class StudentInfo protecte

2、d: ERROR*found* char Name; int Age; int ID; int CourseNum; float Record, public: StudentInfo(char * name, int Age f int ID, int courseNum, float record); ERROR*found* void StudentInfo() float AverageRecord() return Record CourseNum; void show()const cout “Name: “ Name “ Age: “ Age “ID: “ ID “CourseN

3、um: “ CourseNum “Record: “ Record end1; ; ERROR*found* StudentInfo StudentInfo(char * Name, int Age, int ID, int CourseNum, float Record) Name name; Age age; this ID ID; CourseNum courseNum; Record record; int main() StudentInfo st(“Smith“, 21, 99999, 12, 970); st show(); return 0; 二、简单应用题 2 请使用 VC6

4、或使用【答题】菜单打开考生文件夹 proj2下的工程 proj2,其中定义了 vehicle类,并派生出 motorcar类和 bicycle类。然后以 motorcar和 bicycle作为基类,再派生出 motorcycle类。要求将 vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 80 150 100 1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动 “ *found*”。 #include iostream h class vehicle private: int Max

5、Speed; int Weight; public: *found* vehicle(int maxspeed, int weight): _ vehicle(); int getMaxSpeed() return MaxSpeed; int getWeight() return Weight; ; *found* class bicycle: _public vehicle private: int Height; public: bicycle(int maxspeed, int weight, int height): vehicle (maxspeed, weight), Height

6、 (height) int getHeight() return Height; ; ; *found* class motorcar: _public vehicle private: int SeatNum; public: motorcar(int maxspeed, int weight, int seatnum): vehicle (maxspeed, weight), SeatNum (seatnum) int getSeatNum()return SeatNum; ; ; *found* class motorcycle: _ public: motorcycle(int max

7、speed, int weight, int height): vehicle (maxspeed, weight), bicycle(maxspeed, weight, height), motorcar(maxspeed,weight, 1) ; VOid main() motorcycle a(8 0, 150, 100); cout a getMaxSpeed() end1; cout a getWeight() end1; cout a getHeight() end1; couta getSeatNum() end1; 三、综合应用题 3 请使用 VC6或使用【答题】菜单打开考生文

8、件夹 proj3下的工程 proj3,其中声明的 CDeepCopy是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数operator, 以实现深层复制。 要求: 补充编制的内容写在 “ *333*”与“*666*”之间。不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out dat中。输出函数 writeToFile已经编译为 obj文件,并且在本程序中调用。 CDeepCopy h #include iostream #include string using namespace std; clas s CDeepCopy public: int n; 动态数组的元素个数

9、int *p; 动态数组首地址 CDeepCopy(int); CDeepCopy(); CDeepCopy operator (const CDeepCopy&r);赋值运算符函数 , void writeToFile(char *); main cpp #include“CDeepCopy h“ CDeepCopy CDeepCopy()deletep; CDeepCopy CDeepCopy(int k) n k; P new intn; 构造函数实现 CDeepCopy& CDeepCopy operator (const CDeepCopy r) 赋值运算符函数实现 *333* *6

10、66* int main() CDeepCopy a(2), d(3); a P0 1; d P0 666;对象 a, d数组元素的赋值 CDeepCopy b(3); a P0 88; b a;调用赋值运算符函数 cout b P0;显示内层局部对象的数组元素 cout d P0;显示 d数组元素 a P0的值 cout “d fade away; n“; cout a P0; 显示 a数组元素 a P0的值 writeToFile(“); return 0; 国家二级 C+机试(操作题)模拟试卷 290答案与解析 一、基本操作题 1 【正确答案】 (1)char * Name; (2) S

11、tudentlnfo() (3)StudentInfo Studentlnfo(char * name, int age, int ID, int coumeNum, float record) 二、简单应用题 2 【正确答案】 (1)MaxSpeed(maxspeed), Weight(weight); (2)virtual (3)virtual (4)public bicycle, public motorcar 【试题解析】 (1)主要考查考生对构造函数的掌握,构造函数使 用初始化列表来对私有成员 MaxSpeed和 Weight初始化。 (2)主要考查考生对派生类的掌握,题目要求将 v

12、ehicle作为虚基类,避免二义性问题。因此在这里添加 virtual使 vehicle成为虚基类。 (3)主要考查考生对派生类的掌握,题目要求以 motorcar和 bicycle作为基类,再派生出 motorcycle类。在主函数中可以看到 motorcycle类的实例 a调用getHeight函数和 getSeatNum函数,由此可知这两个基类都是公有继承,因此得出语句: public bicycle, public motorcar。 三、综合应用题 3 【正确答案】 n r n;把对象 r字符长度赋值给 n deletep; 删除动态数组 p p new intn; 给动态数组 P分配空间为 n for(int i 0; i n; i ) 遍历对象 r中的数组 P pi r pi; 把 r pi赋值给 pi return*this;返回被赋值的对象

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

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

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