欢迎来到麦多课文档分享! | 帮助中心 海量文档,免费浏览,给你所需,享你所想!
麦多课文档分享
全部分类
  • 标准规范>
  • 教学课件>
  • 考试资料>
  • 办公文档>
  • 学术论文>
  • 行业资料>
  • 易语言源码>
  • ImageVerifierCode 换一换
    首页 麦多课文档分享 > 资源分类 > DOC文档下载
    分享到微信 分享到微博 分享到QQ空间

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

    • 资源ID:497577       资源大小:39KB        全文页数:9页
    • 资源格式: DOC        下载积分:2000积分
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    二维码
    微信扫一扫登录
    下载资源需要2000积分(如需开发票,请勿充值!)
    邮箱/手机:
    温馨提示:
    如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如需开发票,请勿充值!如填写123,账号就是123,密码也是123。
    支付方式: 支付宝扫码支付    微信扫码支付   
    验证码:   换一换

    加入VIP,交流精品资源
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    [计算机类试卷]国家二级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)。


    注意事项

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




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

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

    收起
    展开