【计算机类职业资格】计算机二级(C++)上机考试16及答案解析.doc

上传人:fatcommittee260 文档编号:1337834 上传时间:2019-10-17 格式:DOC 页数:2 大小:30.50KB
下载 相关 举报
【计算机类职业资格】计算机二级(C++)上机考试16及答案解析.doc_第1页
第1页 / 共2页
【计算机类职业资格】计算机二级(C++)上机考试16及答案解析.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

1、计算机二级(C+)上机考试 16 及答案解析(总分:-3.00,做题时间:90 分钟)1.改错题 使用 VC6 打开考生文件夹下的工程 test6_1,此工程包含一个源程序文件 test6_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下: Constructor2 Constructor1 i=0 i=10 Destructor 源程序文件 test6_1.cpp 清单如下: #include class CSample int i; public: CSample()coutdisp(); (分数:-1.00)_2.简单应用题 请编写一个函数 void swap(i

2、nt *x,int *y),用来交换两个数的值。 注意:部分源程序已存在文件 test14_2.cpp 中。 请勿修改主函数 main 和其他函数中的任何内容,仅在函数 swap 的花括号中填写若干语句。 文件 test14_2.cpp 的内容如下: #include void swap(int *x,int *y); void main() int a=1,b=3; swap( coutdisp(); (分数:-1.00)_正确答案:((1)错误:void disp() 正确:void CSample:disp() (2)错误:a-disp(); 正确:a=new CSample; a-di

3、sp(); (3)错误:b-disp(); 正确:b.disp(); )解析:(1)主要考查考生对于类的成员函数定义格式的熟练掌握,对于类体外函数的实现,应该使用作用域符“:“,按照返回值类型 类名:函数名(参数列表)的形式进行说明; (2)主要考查考生对于动态存储分配的掌握,根据前面的定义,a 是一个指针类型的变量,指向一个对象,但是并没有被初始化,此时 a 中的数据无任何意义,应该使用动态存储分配 new 生成一个新的对象,并将返回的指针赋值给 a; (3)主要考查对象指针与对象在调用成员函数时格式的不同,b 是一个对象变量,使用 b 调用成员函数应该用“.“运算符。 2.简单应用题 请编

4、写一个函数 void swap(int *x,int *y),用来交换两个数的值。 注意:部分源程序已存在文件 test14_2.cpp 中。 请勿修改主函数 main 和其他函数中的任何内容,仅在函数 swap 的花括号中填写若干语句。 文件 test14_2.cpp 的内容如下: #include void swap(int *x,int *y); void main() int a=1,b=3; swap( cout“a=“a“ “b=“b_正确答案:(void swap(int *x,int *y) int temp; temp=*x; *x=*y; *y=temp; )解析:本题考查

5、的是考生利用基本控制语句解决实际问题的能力。swap 函数可以交换两个数的值。利用指针来交换变量的值是必须掌握的。 3.综合应用题 使用 VC6 打开考生文件夹下的工程 test8_3,此工程包含一个源程序文件 test8_3.cpp,该文件设计了用于输出乘法九九表的类。请认真阅读已有的代码,按要求完成下列操作,将程序补充完整。 (1)定义类 Table 的私有数据成员 x 和 y,分别用于表示九九表中的两个乘数(x*y),它们都是 int 型的数据。请在注释“/*1*“之后添加适当的语句; (2)完成类 Table 的成员函数 print()的定义,该函数以“x*y=z“的格式打印出九九表中

6、的一个乘法算式,请使用格式化输出函数 printf 实现,在注释“/*2*“之后添加适当的语句; (3)完成类 Table9 的成员函数 print()的定义,该函数调用基类Table 的 print()函数,将九九表输出到屏幕,请在注释“/*3*“之后添加适当的语句; (4)补充主函数,在屏幕上输出九九表,以便测试所定义的类的正确性。请在注释“/*4*“之后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 源程序文件 test8_3.cpp 清单如下: #include #include class Table /*1* int z; public: void

7、print(int x,int y,int z); ; void Table:print (int x,int y,int z) /*2* class Table9:public Table public: void print(); ; void Table9:print() /*3* int x,y,z; for (i=1;i_正确答案:((1) int x; int y; (2) printf( “%d*%d=%d “,x,y,z); if(z解析:主要考查考生将具体问题抽象为类,将类的定义补充完整,并进行类定义测试的能力。注意(2)中格式化输出函数 printf 的使用格式,%d 代表输出的为整型。

展开阅读全文
相关资源
猜你喜欢
  • EN 12289-2005 en Advanced technical ceramics - Mechanical properties of ceramic composites at ambient temperature - Determination of in-plane shear properties《高级工业陶瓷 环境温度下陶瓷组分的机械特性.pdf EN 12289-2005 en Advanced technical ceramics - Mechanical properties of ceramic composites at ambient temperature - Determination of in-plane shear properties《高级工业陶瓷 环境温度下陶瓷组分的机械特性.pdf
  • EN 1229-1996 en Plastics Piping Systems - Glass-Reinforced Thermosetting Plastics (GRP) Pipes and Fittings - Test Methods to Prove the Leaktightness of the Wall Under Short-Term In.pdf EN 1229-1996 en Plastics Piping Systems - Glass-Reinforced Thermosetting Plastics (GRP) Pipes and Fittings - Test Methods to Prove the Leaktightness of the Wall Under Short-Term In.pdf
  • EN 12291-2003 Advanced technical ceramics - Mechanical properties of ceramic composites at high temperature in air at atmospheric pressure - Determination of compression properties.pdf EN 12291-2003 Advanced technical ceramics - Mechanical properties of ceramic composites at high temperature in air at atmospheric pressure - Determination of compression properties.pdf
  • EN 12293-1999 en Plastics Piping Systems - Thermoplastics Pipes and Fittings for Hot and Cold Water - Test Method for the Resistance of Mounted Assemblies to Temperature Cycling《塑料.pdf EN 12293-1999 en Plastics Piping Systems - Thermoplastics Pipes and Fittings for Hot and Cold Water - Test Method for the Resistance of Mounted Assemblies to Temperature Cycling《塑料.pdf
  • EN 12294-1999 en Plastics Piping Systems - Systems for Hot and Cold Water - Test Method for Leaktightness under Vacuum《塑料管道系统 热水和冷水系统 真空密封性的检验方法》.pdf EN 12294-1999 en Plastics Piping Systems - Systems for Hot and Cold Water - Test Method for Leaktightness under Vacuum《塑料管道系统 热水和冷水系统 真空密封性的检验方法》.pdf
  • EN 12295-1999 en Plastics Piping Systems - Thermoplastics Pipes and Associated Fittings for Hot and Cold Water - Test Method for Resistance of Joints to Pressure Cycling《塑料管道系统 热水和.pdf EN 12295-1999 en Plastics Piping Systems - Thermoplastics Pipes and Associated Fittings for Hot and Cold Water - Test Method for Resistance of Joints to Pressure Cycling《塑料管道系统 热水和.pdf
  • EN 12296-1998 en Biotechnology - Equipment - Guidance on Testing Procedures for Cleanability《生物技术 设备 清洁处理试验程序指南》.pdf EN 12296-1998 en Biotechnology - Equipment - Guidance on Testing Procedures for Cleanability《生物技术 设备 清洁处理试验程序指南》.pdf
  • EN 12297-1998 en Biotechnology - Equipment - Guidance on Testing Procedures for Sterilizability《生物技术 设备 灭菌试验程序指南》.pdf EN 12297-1998 en Biotechnology - Equipment - Guidance on Testing Procedures for Sterilizability《生物技术 设备 灭菌试验程序指南》.pdf
  • EN 12298-1998 en Biotechnology - Equipment - Guidance on Testing Procedures for Leaktightness《生物技术 设备 泄漏安全性检验法指南》.pdf EN 12298-1998 en Biotechnology - Equipment - Guidance on Testing Procedures for Leaktightness《生物技术 设备 泄漏安全性检验法指南》.pdf
  • 相关搜索

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

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