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

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

1、国家二级 C+机试(操作题)模拟试卷 329及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹 projl下的工程 pmjl,其中有 “沙发 ”类 Sofa和主函数main的定义。程序中位于每个, ERROR*found*下的语句行有错误,请加以更正。更正后程序的输出应该是: 座位数: 3 颜色:红色 注意:只能修改每爪 ERROR*found*下的那一行,不要改动程序中的其他内容。 #include us ing namespace std; class Sofa “沙发 ”类 int seats; 座位数 char color10;颜色 public: ERROR*found*

2、Sofa(int S, const char*CO) ERROR*found* if(CO=NULL) color0= 0; elSe strcpy(color, CO); ERROR*found* const char*getSeats()constreturn seats; ) const chars getColor()constreturn color; ) ; int main() Sofa safa(3); cout #include #include using namespace std; class AutoMobile “汽车 ”类 char*brand; 汽车品牌 cha

3、r*number; 车牌号 int speed; 档位: 1、 2、 3、 4、 5,空档: 0, 倒档:一 1 public: AutoMobile(const char*the brand, const char*the_number): speed(0) brand=new charstrlen(the brand)+1 ; *found* _; *found* _; strcpy(number, the number); AutoMobile()deletebrand; deletenumber; ) const char*theBrand()constreturn brand; 返回

4、品牌名称 const char*theNumber()constreturn number; ) 返回车牌号 int currentSpeed()const return speed; 返回当前档位 void changeGearTo(int the_speed) 换到指定档位 if(speed=一 1 speed #include using namespace std; class CDeepCopy public: int n; 动态数组的元素个数 int *p; 动态数组首地址 CDeepCopy(int); CDeepCopy(); CDeepCopy ) 【试题解析】 程序定义 S

5、ofa类,它包含两个数据成员:字符数组 color和整型变量 seats;还包含一个构造函数,两个公有成员函数, getSeats()函数返回成员 seats的值, getColor()函数返回字符数组 color的地址 Sofa类的定义体中,有三个错误: (1)Sofa类的构造函数错误:由 main()函数中定义 Sofa类对象 时可知:构造函数虽然有两个参数,但是可以只传人一个整型变量,所以另一个参数 co需要提供一个默认值,由题意可知程序运行结果输出颜色是红色,所以 co的默认字符串值为“红色 ”;另外程序需要输出座位数: 3,所以成员 seats需要使用形参 s完成初始化,构造函数体中

6、并未对 seats进行赋值。 (2)sofa类的构造函数中,需要根据形参 co的值是否为空,完成 color的赋值,此处的 if判断需要使用相等关系运算符,而不是赋值运算符。 (3)成员函数 getSeats()返回的是 seats的值,所以返回值应该是 int类型,而不是const char*类型。 二、简单应用题 2 【正确答案】 (1)strcpy(brand, the_brand) (2)number=new charstrlen(the_number)+1 (3)theBrand() (4)constreturn”卡车 ”; 【试题解析】 (1)主要考查考生对 strcpy函数的掌握

7、情况,在上一条语句程序给brand指针分配了空间,在这里要复制字符串 the_brand,即 strepy(brand, thebrand);。 (2)主要考查考生对动态分配的掌握情况,参考 brand指针的复制过程完成该语句,先给指针 number分配空间,通过 new来完成: number=new charstrlen(the_number)+1;。 (3)主要考查考生对成员函数的掌握,由程序可知这里要输出的是品牌,因此调用成员函数 theBrand()来输出品牌。 (4)主要考查考生对纯虚函数的掌握,根据纯虚函数的定义: virtual const char*category()cons

8、t=0;,可知在这里要填写: constreturn”卡车 ”; 。 三、综合应用题 3 【正确答案】 n=r n; 把对象 r字符长度赋值给 n deletep; 删除动态数组 p p=new intn; 给动态数组 p分配空间为 n for(int i=0; in; i+) 遍历对象 r中的数组 p pi =r pi; 把 r pi赋值给 pi return*this; 返回被赋值的对象 【试题解析】 主要考查考生对运算符重载的掌握,由注释可知此处要实现赋值运算符函数。要重载的运算符是 “=”, 该类的成员是动态数组 p,数组元素个数为n,因此先释放原来的动态数组,再分配空间,然后逐个复制元素即可。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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