【计算机类职业资格】二级C++-73 (1)及答案解析.doc
《【计算机类职业资格】二级C++-73 (1)及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++-73 (1)及答案解析.doc(4页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+-73 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,其中包含类 Myaass的定义。程序中位于每个“/ERROR *found*”下的一行语句有错误,请加以更正。更正后程序的输出结果应该是: The value is 5 The value is 10 注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class MyCla
2、ss public: / ERROR * found* voidMyClass() value = 0; / ERROR * found* void setValue(int val) const value=val; int getValue() const return value; private: /ERROR *found* int value=0; ; int main() MyClass obj; obj.setValue(5); cout “The value is“ obj. getValue() endl; obj.setValue(10); cout “The value
3、 is“ obj. getValue() endl; return 0; (分数:30.00)_二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2,其中定义了 vehicle类,并派生出 motorcar类和 bicycle类。然后以 motorcar和 bicycle作为基类,再派生出 motocycle类。要求将vehicle作为虚基类,避免二义性问题。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: A vehicle is running! A vehicle has sto
4、pped! A bicycle is running! A bicycle has stopped! A motorcar is running! A motocycle is running! 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream.h class vehicle private: int MaxSpeed; int Weight; public: vehicle(): MaxSpeed(0), Weight(0) vehicle(int max_speed, int weight): MaxSpe
5、ed (max_speed ), Weight (weight)( /* found* _Run() cout “Avehicle is running!“ endl; /* found* _Stop() cout “A vehicle has stopped!“ endl; ; class bicycle : virtual public vehicle private: int Height; public: bicycle(): Height(0) bicycle(int max_speed, int weight,int height) :vehicle (max_speed, wei
6、ght), Height(height); void Run () cout “A bicycle isrunning!“ endl; void Stop() cout “Abicycle hasstopped!“ endl; ; class motorcar : virtual public vehicle private: int SeatNum; public: motorcar(): SeatNum(0) motorcar (int max_speed, intweight, int seat_num) /* found* :_ void Run() cout “A motorcar
7、isrunning!“ endl; void Stop () cout “A motorcarhas stopped!“ endl; ; /* found* class motorcycle: _ public: motorcycle() motorcycle (int max_speed, int weight, int height, int seet_num):bicycle(max_speed, weight, height), motorcar (max_speed, weight, seet_num); motorcycle () ; void Run () cout “A mot
8、orcycle is running!“ endl; void Stop() cout “A motorcycle has stopped!“ endl; ; int main() vehicle * ptr; vehicle a; bicycle b; motorcar c; motorcycle d; a.Run(); a. Stop(); b.Run(); b. Stop(); ptr = ptr-Run(); ptr = ptr-Run(); return 0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 p
9、roj3下的工程 proj3,其中定义的 IntArray是一个用于表示整型一维数组的类。成员函数 swap可以将数组中的两个指定元素交换位置;成员函数 sort的功能是将数组元素按照升序排序。请编写成员函数 sort。在 main函数中给出了一组测试数据,此时程序运行中应显示: 读取输入文件 -排序前- a1=3 1 2 a2=5 2 7 4 1 6 3 -排序后- a1=1 2 3 a2=1 2 3 4 5 6 7 要求: 补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat中。输出函数 WriteToFile已
10、经编译为 obj文件,并且在本程序中调用。 /IntArray.h #include iostream #include string.h using namespace std; class IntArray public: IntArray(unsigned int n) size = n; data = new intsize; IntArray() delete data; int getSize() const return size; int void swap(int i, int j) int temp = datai; datai = dataj; dataj = temp;
11、 void sort(); friend ostream iarray.getSize (); i+) os arrayi ; return os; private: int * data; unsigned int size; ; void readFromFile ( const char *, IntArray void writeToFile (char*, const IntArray /main.h #include fstream #include “IntArray. h“ void IntArray:sort () /* 333* /* 666* void readFromF
12、ile (const char * f, IntArray if (infile.fail () cerr “打开输入文件失败!“; return; int i=0; while (!infile.eof() infile mi+; int main () IntArray a1(3), a2(7), a3(1000);a10=3, a11=1, a12=2; a20=5, a21=2, a22=7, a23=4, a24=1, a25=6, a26=3; readFromFile (“in.dat“, a3); cout “-排序前-/n“; cout “a1=“ a1 endl; cout
13、 “a2=“ a2 endlendl; al.sort (); a2.sort(); a3.sort(); cout “-排序后- /n“; cout “a1=“ a1endl; cout “a2=“ a2endlendl; writeToFile(“, a3); return 0; (分数:40.00)_二级 C+-73 (1)答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,其中包含类 Myaass的定义。程序中位于每个“/ERROR *found*”下的一
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 C731 答案 解析 DOC
