[计算机类试卷]国家二级C++机试(操作题)模拟试卷480及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷480及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷480及答案与解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
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,该文件中定义了用于表示
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 480 答案 解析 DOC
