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

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

1、国家二级 C+机试(操作题)模拟试卷 294及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,该工程中包含程序文件 main cpp,其中有类 Foo和主函数 main的定义。程序中位于每个 “ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: X a Y 42 注意:只修改每个 “ ERROR *found*”下的那一行,不要改动程序中的其他内容 。 #include iostream using namespace std; class Foo public: Foo(char x)x

2、 x; char getX()constreturn x; public: static int y_; private: char x; ; ERROR *found* int Foo y_ 42; int: main(int argc, char * argV ) ERROR *found* Foo f; ERROR *found* cout; “X “ f x_ end1; cout; “ “ f y_ end1; return 0; 二、简单应用题 2 请使用 VC6或使用【答题】菜单打开考生文件夹 proj2下的工程 proj2。其中有类 Point(“点 ”)、 Rectangl

3、e(“矩形 ”)和 Circle(“圆 ”)的定义。在程序所使用的平面坐标系统中, 轴的正方向是水平向右的, y轴的正方向是 竖直向下的。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应该是: 一一圆形 圆心 (3, 2) 半径 1 面积 3 14159 外切矩形 左上角 (2, 1) 右下角 (4, 3) 面积 4 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动 “ *found*”。 #include instream #include cmath uslrig namespace std; 平面坐标中的点 本题坐标系统中, x轴的

4、正方向水平向右, y轴的正方向竖直向下。 class Point public: Point(double x 0 0, double y 0 0): x_(x), y_(y) double getX()constreturn x_; double getY() const return y_; ) void setX(double x)x_ x; void setY(double y)y_ y; private: double x_; x坐标 double y_; y坐标 , 矩形 class Rectangle public: Rectangle(Point P, int w, int h

5、) : point(P), width(w), height(h) double area()const矩形面积 return width * height; Point topLeft()const左上角顶点 return point; Point bottomRight()const 右下角顶点 (注: y轴正方向竖直向下 ) *found* return Point(_); private: Point point;左上角顶点 double width;水平边长度 double height;垂直边长度 ; 圆形 class Circle public: Circle(Point P,

6、double r): center(p), radius(r) Rectangle boundingB0x ( ) const; 外切矩形 double aEea()const圆形面积 *found* return PI *_; public: static const double PI;圆周率 private: Point center; 圆心 double radius; 半径 , const double Circle PI 3 14159; Rectangle Circle boundingBox ()const *found* Point pt(_); int w, h; *fou

7、nd* w h _; return Rectangle(pt, w, h); int main() Point P(3, 2); Circle c(p, 1); cout “圆形 n“; cout “圆心 (“ p getX() , P getY() “) n“; cout “半径 “ 1 end1; cout “面积 “ c area() end1 end1; Rectangle bb c boundingBox(); Point t1 bb topLeft(); Point br bb bottomRight(); cout “外切矩形 n“; cout “左上角 (“ t1 getX (

8、) , t1 getY() “) n“; cout “右下角 (“ br getX() , br getY() “) n“; cout “面积 “ bb area() end1; return 0; 三、综合应用题 3 请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 proj3,其中定义了 MyString类,一个用于表示字符串的类。成员函数 reverse的功能是将字符串进行 “反转 ”。例如,将字符串 ABCDEF“反转 ”后,得到字符串 FEDCBA;将字符串 ABCDEFG“反转 ”后,得到字符串 GFEDCBA。请编写成员函数 reverse。在main函数中给出

9、了一组测试数据,此时程序运行中应显示: 读取输入文件 反转前 STR1 ABCDEF STR2 ABCDEFG 反转后 STR1 FEDCBA STR2 GFEDCBA 要求: 补充编制的内容写在 “ *333*”与 “ *666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out dat中,输出函数 WriteToFile已经编译为 obj文件,并且在本程序中调用。 mgsering h #include iostream #include cstring using namespace std; class MyString public: MyString(cons

10、t char * s) str new charstrlen(s) 1; strcpy(str, s); MyString()deletestr; ) void reverse(); friend ostream&operator (ostream &os, const MyString &mystr) os mystr str; return os; private: char * str; ; void writeTOFile(char * , const MyString&); main cpp #include“mystring h“ #include fstream void MyS

11、tring reverse() *333* *666* int main() char inname128, pathname 80; strcpy(pathname, “); sprintf(inname, “in dat“, pathname); cout “读取输入文件 n n“; i fstream infile(inname); if(infile fail() cerr “打开输入文件失败 !“; exit(1); char buf4096; infile getline(buf, 4096); MyString str1(“ABCDEF“), str2(“ABCDEFG“), s

12、tr3(buf); cout “反转前 n“; cout “STR1 “ str1 end1; cout “STR2 “ str2 end1 end1; str1 reverse(); str2 reverse(); Str3 reverse(); cout “反转后 n“; cout “STR1 “ str1 end1; cout “STR2 “ str2 end1 end1; writeToFile(pathname, str3); return 0; 国家二级 C+机试(操作题)模拟试卷 294答案与解析 一、基本操作题 1 【正确答案】 (1)int Foo y_ 42; (2)Foo

13、 f(a); (3)cout “X “ f getX() end1; 【试题解析】 (1)主要考查考生对静态成员的掌握,因为静态整型变量 y_是 Foo类的公有成员,所以给 y_赋值时要加上 “Foo ”,即 int Foo y_ 42;。 (2)主要考查考生对构造函数的掌握,题目要求程序输出: X a Y 42 可以知道,在给 Foo类的 f声明时要同时初始化为字符 a,即语句 Foo f(a);。 (3)主要考查考生对成员函数的掌握,因为 x是类 Foo的私有成员,所以不能在main函数中直接调用,要通过公有成员函数 getX()调用。 二、简单应用题 2 【正确答案】 (1)point

14、getX() width, point getY() height (2)radius * radius (3)center getX() radius, center getY() radius (4)2 * radius 【试题解析】 (1)主要考查考生对成员函数的掌握,程序要求返回右下角顶点,该点的 x坐标为左上角顶点的 x坐标加上 width,该点的 y坐标为左上角顶点 y坐标加上 height,即 return Point(point getX() width, point getY()height);。 (2)主要考查考生对成员函数的掌握,程序要求计算圆形面积,也就是返回圆面积,即

15、 return PI * radius * radius;。 (3)主要考查考生对成员函数的掌握,首先看函数声明: Rectangle Circle boundingBox()const,可知该函数要返回的是一个 Rectangle类型,即要返回的是圆的外切矩形。再看 Rectangle类的构造函数 Rectangle(Point P, int W,int h),由此可知,空格处要定义的点 pt为左上角点,即 Point pt(center getX() radius, center getY() radius);。 (4)由 函数声明和 Rectangle类的构造函数可知, W和 h应该为直

16、径,即 w h2 * radius;。 三、综合应用题 3 【正确答案】 Int length strlen(str); 把字符串 str的长度赋值给 lenth for(int i 0, j length 1; i j; i, j ) 从 i 0, j length 1, i j为条件 开始遍历,并把 Stri和 Strj交换 char temp stri; 给定义的临时变量 temp赋值为 stri stri strj; 给 Stri赋值 Strj strj temp; 给 Strj赋值为 temp 【试题解析】 主要考查考生对动态数组的掌握,先看题目要求:成员函数 revere的功能是将字符串进行 “反转 ”。再由类的定义可知,字符串存放在动态数组 str中,由 strlen函数得出字符串的长度,最后一个字符的下标为 lengh 1,第一个字符的下标为 0,将这两个字符交换,然后 j依次减 1同时 i依次加 1,继续交换,直到 i大于 j时停止循环即可。

展开阅读全文
相关资源
猜你喜欢
  • 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