[计算机类试卷]国家二级C++机试(操作题)模拟试卷499及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷499及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷499及答案与解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 499及答案与解析 一、基本操作题 1 请打开考生文件夹下的解决方案文件 proj1,其中在编辑窗口内显示的主程序文件中定义有类 AAA和主函数 main。程序文本中位于每行 “ERROR*found*”下面的一行有错误,请加以改正。改正后程序的输出结果应该是: sum=60 注意:只修改每个 “ ERROR*found*”下面的一行,不要改动程序中的其他任何内容。 #include iostream using namespace std; class AAA int a10; int n; ERROR*found* private: AAA(int a
2、a , int nn): n(nn) ERROR*found* for(int i=0; i rl; i+)aai=ai; int Geta(int i)return ai; ; int main( ) int a6=2, 5, 8, 10, 15, 20; AAA x(a, 6); int sum=0; ERROR*found* for(int i=0; i 6; i+) sum+=x ai; cout “sum=“ sum endl; return0; 二、简单应用题 2 请打开考生文件夹下的解决方案文件 proj2,此工程中包含一个头文件shape h,其中包含了类 Shape、 Poi
3、nt和 Triangle的声明;包含程序文件shape cpp,其中包含了类 Triangle的成员函数和其他函数的定义;还包含程序文件 proj2 cpp,其中包含测试类 Shape、 Point和 Triangle的程序语句。请在程序中的横线处填写适当的代码并删除横线,以实现上述功能。此程序的正确输出结果应为: 此图形是一个抽象图形,周长 =0,面积 =0 此图形是一个三角形,周长 =6 82843,面积 =2 注意:只能在横线处填写适当的代码,不要改动 程序中的其他内容,也不要删除或移动 “ *found*”。 shape h class Shape public: virtual do
4、uble perimeter( ) constreturn0; 返回形状的周长 virtual doublearea( )constreturn0; 返回形状的面积 virtual const char*name( )constreturn“抽象图形 “; 返回形状的名称 ; class Point表示平面坐标系中的点的类 double x; double y; public: *found* Point(double x0, doub2e y0): _用 x0、 y0初始化数据成员 x、 y double getX( )constreturn x; double getY( )constre
5、turn y; ; class Triangle: public Shape *found* _; 定义 3个私有数据成员 public: Triangle(Point p1, Point p2, Point p3): point1(p1), point2(p2), point: 3(p3) double perimeter( )const; double area( )const; const char*narne( )constreturn“三角形 “; ; shape cpp #include“shape h“ include cmath double length(Point p1,
6、Pointp2) return sqrt(p1 getX( )-p2 getX( )*(p1 getX( )-p2 getX( )+(p1 getY( )-p2 getY( )*(p1 getY( )-p2 getY( ); double Triangle: perimeter( )const 一个 return语句,它利用 length函数计算并返回三角形的周长 *found* _; double Triangle: area( )const double s=perimeter( ) 2 0; return sqrt(s*(s-length (point1, point2)* (s-len
7、gth(point2, point3)* (s-length(point3, pointl); proj2 cpp #include“shape h“ #include iostream using namespace std; *found* _ show函数的函数头 (函数体以前的部分 ) cout “此图形是一个 “ shape name( ) “,周长 =“ shape perimeter( ) “,面积: “ shape area( ) endl; int msin( ) Shape s; Triangle tri(Point(0, 2), Point(2, 0), Point(0,
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 499 答案 解析 DOC
