ImageVerifierCode 换一换
格式:DOC , 页数:9 ,大小:39KB ,
资源ID:497577      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-497577.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文([计算机类试卷]国家二级C++机试(操作题)模拟试卷480及答案与解析.doc)为本站会员(fuellot230)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

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

1、国家二级 C+机试(操作题)模拟试卷 480及答案与解析 一、基本操作题 1 请打开考生文件夹下的解决方案文件 proj1,其中有线段类 Line的定义。程序中位于每个 “ ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: End point1=(1, 8), End point2=(5, 2), length=7 2111。 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #include iostream #include cmath using namespace std; class Line; doubl

2、e length(Line); class Line(线段类 doub2e x1, y1;线段端点 1 double x2, y2;线段端点 2 public: ERROR*found* Line(double x1, double y1, double x2, double y2)const this- x1=x1; this- y1=y1; this- x2=x2; this- y2=y2: double getX1( )constreturn x1; double getY1( )constreturn y1; double getX2( )constreturn x2; double

3、getY2( )constreturn y2; VOid show( )const cout “End point1=(“ x1 “, “ y1; cout “), End point2=(“ x2 “, “ y2; ERROR*found* cout “), length=“ length(this) “。 “ endl; ; double length(Line1) ERROR*found* return sqrt(1 x1-1 x2)*(1 x1-1 x2)+(1 y1-1 y2)*(1 y1-1 y2); int main( ) Line r1(1 0, 8 0, 5 0, 2 0);

4、 r1 show( ); return0; 二、简单应用题 2 请打开考生文件夹下的 解决方案文件 proj2,该工程中包含一个程序文件main cpp,其中有类 AutoMobile(“汽车 ”)及其派生类 Car(“小轿车 ”)、 Truck(“卡车 ”)的定义,还有主函数 main的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 车牌号:冀 ABCl234品牌: ForLand类别:卡车当前档位: 0最大载重量: 12 车牌号:冀 ABC1234品牌: ForLand类别:卡车当前档位: 2最大载重量: 12 车牌号:沪 XYZ5678品牌: QQ

5、类别:小轿车当前档位: 0座位数: 5 车牌号:沪 XYZ5678品牌: QQ类别:小轿车当前档位: -1座位数: 5 注意:只能在横线处填写适当的代码,不要改动 程序中的其他内容,也不要删除或移动 “ *found*”。 #include iostream #include iomanip #include cmath using namespace std; class AutoMobile “汽车 ”类 char*brand;汽车品牌 char*number;车牌号 int speed;档位: 1、 2、 3、 4、 5, 空 档: 0,倒档: -1 public: AutoMobile

6、(const char*the_brand, const char*the_number): speed(0) brand=new charstrlen(the_brand)+1; *found* _; *found* _; strcpy(number, thenumber); AutoMobile( )delete brand; delete number; ) const char*theBrand( )constreturn brand; 返回品牌名称 const char*theNumber( )constreturn number; 返回车牌号 int currentSpeed( )

7、constreturn speed; 返回当前档位 void changeGearTo(int the_speed)换到指定档位 if(speed =-1&speed =5) speed=the_speed; virtual const char*category( )const=0;类别:卡车、小轿车等 virtualVOidshow( )const cout “车牌号: “ theNumber( ) *found* “品牌: “ _ “类别: “ category( ) “当前档位: “ currentSpeed( ); ; class Car: public AutoMobile int

8、 seats;座位数 public: Car(const char*the_brand, const char*the_number, int the_seatS):AutoMobile(the_brand, the_number), seats(the_seats) int numberOfSeat( )constreturn seats; 返回座位数 const char*category( )constreturn“小轿车 “; 返回汽车类别 void show( )const AutoMobile: show( ); cout “座位数: “ numberOfSeat( ) endl;

9、 ; class Truck: public AutoMobile “卡车 ”类 int max_load;最大载重量 public: Truck(const char*the_brand, const char*the_number, int the_max_load):AutoMobile(the_brand, the_number), max_load(the_max_load) int maxLoad( )conSt returnmax_load; )返回最大载重量 *found* const char*category( ) _返回汽车类别 void show( )const Aut

10、oMobile: show( ); cout “最大载重量: “ maxLoad( ) endl; ; int main( ) Truck truck(“ForLand“, “冀 ABC1234“, 12); ttuck show( ); truck changeGearTo(2); truck show( ); Carcar(“QQ“, “沪 XYZ5678”, 5); car show( ); car changeGearTo(-1); car show( ); cout endl; return0; 三、综合应用题 3 请打开考生文件夹下的解决方案文件 proj3,该文件中定义了用于表示

11、日期的类Date、表示人员的类 Person和表示职员的类 Staff;程序应当显示: 张小丽 123456789012345 但程序中有缺失部分,请按以下提示把缺失部分补充完整: (1)在 “ *1* *found*”的下方是析构函数定义中的 语句,它释放两个指针成员所指向的动态空间。 (2)在 “ *2* *found*”的下方是 rename函数中的一个语句,它使指针name指向申请到的足够容纳字符串 new_name的空间。 (3)在 “ *3* *found*”的下方是构造函数定义的一个组成部分,其作用是利用参数表中前几个参数对基类 Person进行初始化。 注意:只在指定位置编写适

12、当代码,不要改动程序中的其他内容,也不要删除或移动 “*found*”。填写的内容必须在一行中完成,否则评分将产生错误。 proj3 cpp #include iostream using namespace std; class Petson char*idcardno; 用动态空间存储的身份证号 char*name;用动态空间存储的姓名 bool ismale;性别: true为男, false为女 public: Person(const char*pid, const char*pname, bool pmale); Person( ) *1* *found* _; const cha

13、r*getIDCardNO( )constreturn idcardno; const char*getName( )constreturn name; void rename(const char*new_name); bool isMale( )constreturn ismale; : class Staff: public Person char*department; double salary; public: Staff(const char*id_card_no, const char*p_name, bool is_male, const char*dept,double s

14、al); Staff( )delete department; ) const char *getDepartment( )constreturn department; void setDepartment(const char*d); double getSalary( )constreturn salary; void setSalary(double s)salary=s; ; Person: Person(const char*id_card_no, const char*p_name, bool is_male):ismale(is_male) idcardno=new chars

15、trlen(id_card_no)+1; strcpy(idcardno, id_card_no); name=new charstrlen(p_name)+1; strcpy(name, p_name); void Person: rename(constchar*new_name) delete name; *2* *found* _; Strcpy(name, new_name); Staff: Staff(const char*id_card_no, const char*p_name, bool is_male, *3* *found* const char*dept, double

16、 sal): _ department=new charstrlen(dept)+1; strcpy(department, dept); salary=sal; void Staff: setDepartment(const char*dept) delete department; department=newcharstrlen(dept)+1; strcpy(department, dept); int main( ) Staff Zhangsan(“123456789012345“, “张三 “, false, “人事部 “, 1234 56); Zhangsan rename(“张

17、小丽 “); cout Zhangsan getName( ) Zhangsan getIDCardNO( ) endl; return0; 国家二级 C+机试(操作题)模拟试卷 480答案与解析 一、基本操作题 1 【正确答案】 (1)Line(double x1, double y1, double x2, double y2) (2)cout “), length=“ length(*this) “。 “ endl; (3)return sqrt(1 getX1( )-1 getX2( )*(1 getX1( )-1 getX2( )+(1 getY1( )-1 getY2( )*(1

18、getY1( )-1 getY2( ); 【试题解析】 (1)主要考查考生对构造函数的掌握,构造函数要给私有成员赋初始值,因此不能使用 const来限制。 (2)主要考查考生对 this指针的掌握,由函数 length的声明 double length(Line);可知, length函数的形参是 Line类,在 void show( )const函数里, this指针指向的是当前 Line类,因此可以用 *this表示当前 Line类。 (3)主要考查考生对成员函数的掌握, length函数是类外函数,不能直接调用类的私有成员,因此要通过成员函数取得对应的值。 二、简单应用题 2 【正确答案

19、】 (1)strcpy(brand, the_brand) (2)number=new charstrlen(the_number)+1 (3)theBrand() (4)constreturn“卡车 “; 【试题解析】 (1)主要考查考生对 strcpy函数的掌握情况,在上一条语句程序给brand指针分配了空间,在这里要复制字符串 the_brand,即 strcpy(brand,the_brand);。 (2)主要考查考生对动态分配的掌握情况,参考 brand指针的复制过程完成该语句,先给指针 number分配空间,通过 new来完成: number=new charstrlen(the_

20、number)+1;。 (3)主要考查考生对成员函数的掌握,由程序可知这里要输出的是品牌,因此调用成员函数 theBrand( )来输出品牌。 (4)主要考查考生对纯虚函数的掌握,根据纯虚函数的定义: virtual const char*category( )const=0;,可知在这里要填写: constreturn“卡车 “; 。 三、综合应用题 3 【正确答案】 (1)delete ideardno, name (2)name=new charstrlen(new_name)+1 (3)Person(id_card_no, p_name, is_male) 【试题解析】 (1)主要考查

21、考生对析构函数的掌握,题目要求释放两个指针成员所指向的动态空间。释放动态空间应使用 delete语句,因为要释放两个指 针,使用语句: delete idcardno, name;实现。注意当释放多个指针时,中间用逗号隔开。 (2)考查动态数组分配空间,题目要求指针 name指向申请到的足够容纳字符串new_name的空间。使用 strlen(new_name)得到字符串 new_name的长度,但是这里要注意加 1。 (3)主要考查考生对派生类构造函数的掌握,题目要求利用参数表中前几个参数对基类 Person进行初始化。派生类的构造函数要使用成员列表初始化法对基类初始化,因此为 const char*dept, double sal): Person(id_card_no, p_name,is_male)。

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