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

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

1、国家二级 C+机试(操作题)模拟试卷 440及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹下的源程序文件 modi1 cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: 1 0 注意:错误的语句在 *error*的下面,修改该语句即可。 #include struct Struct union int a; char c4; ; int b; *error* void main() Struct m; *error* m c0=0; m c1=0; m c2=0; *error* m c3=1; m b=m c3; cout #include #define M

2、AXLEN 1024 void convert(char *des, char * str, char *str2) void main() char destMAXLEN; char*str=”! &cefghi*! &“; char*str2=“jklm“; convert(dest, str, str2); cout #define CONST_PI 3 141592 class CCircle private: double radius; *1* public: *2* CCircle(int radius) this-radius=radius; double GetArea()

3、*3* ) double GetGirth() *4* void SetRadius(int m) radius=m; ; int main() CCircle circle(5); cout ; 这里定义的结构体并没有变量名列表,但是结构体定义一定是以 “; ”结束的,因此第 1个标识下应改为 “; ”。 (2)根据题目要求程序输出结果分别为 “1”和 “0”,即结构体变量 m的成员变量 a的值为 1, b的值为 0,又 a和字符数组 c4存放在同一段内存单元中,因此 a的值可由数组 c4决定 (两者使用同一地址单元 ),故 c0表示 a的低 8位, c1为 a的第二个 8位, c2为 a的

4、第三个 8位, c3为 a的最高 8位, a=0,所以 c0=1,c1=c2=c3=0,故第 2个标识下应改为 “m c0=1; ”。 (3)由 (2)分析可知第 3个标识下应改为 “m c3=0: ”。 二、简单应用题 2 【正确答案】 des0=0; char temp2=0, 0; for(int i=0; stri! =NULL; i+) if(stri=! ) temp0=a; 替换成 a strcat(des, temp); else if (stri=&) temp0=b; strcat(des, temp); 替换成 b else if(stri: =*) strcat(des

5、, str2); 替换成 str2 ) else temp0=stri; strcat(des, temp); 其他情况则添加在后面 【试题解析】 (1)由 审题分析可知,利用循环中不断检索 str字符串每一个字符,循环变量 i从 0开始,直到到了 str字符结束,即 srti=NULL为循环判断结束条件。 (2)在循环体内,用 if else语句判断是不是 “! ”、 “&”或 “*”这些特定的字符,如果是这些特定的字符则进行相应的替换,如果不是则将该字符直接加在 des后面。 (3)字符串的连接可以使用字符串连接函数 strcat(),将新字符连接在 des后面,即strcat(des,

6、temp)。 三、综合应用题 3 【正确答案】 (1)添加语句: const double PI; (2)将 “CCircle(int radius)”补充完整为: CCircle(int radius): PI(CONST_PI) (3)添加语句: return radius*radius*PI; (4)添加语句: return 2*radius*PI; 【试题解析】 (1)第 1个标识下定义私有常量 PI,常数据成员是使用 const说明的数据成员,因此第 1个标识下应添加 “const double PI; ”。 (2)常数据成员的初始化只能通过构造函数的成员初始化列表进行,构造函数CCircle(int radius)应对常数据成员 PI进行初始化,第 2个标识下应改为“CCircle(int radius): PI(CONST_PI)”。 (3)第 3个标识下返回圆面积值,圆面积为半径平方与 PI的乘积值,即第 3标识下应添加 “returnradius*radius*PI; ”。 (4)第 4个标识下返回周长,即第 4表示下应添加 “return 2*radius*PI; ”。

展开阅读全文
相关资源
猜你喜欢
  • ASTM C1472-2016 Standard Guide for Calculating Movement and Other Effects When Establishing Sealant Joint Width《确定密封材料接合宽度时计算胀缩和其它影响的标准指南》.pdf ASTM C1472-2016 Standard Guide for Calculating Movement and Other Effects When Establishing Sealant Joint Width《确定密封材料接合宽度时计算胀缩和其它影响的标准指南》.pdf
  • ASTM C1473-2005 Standard Test Method for Radiochemical Determination of Uranium Isotopes in Urine by Alpha Spectrometry《α光谱测定法放化测定尿中铀同位素的标准试验方法》.pdf ASTM C1473-2005 Standard Test Method for Radiochemical Determination of Uranium Isotopes in Urine by Alpha Spectrometry《α光谱测定法放化测定尿中铀同位素的标准试验方法》.pdf
  • ASTM C1473-2011 Standard Test Method for Radiochemical Determination of Uranium Isotopes in Urine by Alpha Spectrometry《α光谱测定法放化测定尿中铀同位素的标准试验方法》.pdf ASTM C1473-2011 Standard Test Method for Radiochemical Determination of Uranium Isotopes in Urine by Alpha Spectrometry《α光谱测定法放化测定尿中铀同位素的标准试验方法》.pdf
  • ASTM C1474-2000(2006)e1 Standard Test Method for Analysis of Isotopic Composition of Uranium in Nuclear-Grade Fuel Material by Quadrupole Inductively Coupled Plasma-Mass Spectromet.pdf ASTM C1474-2000(2006)e1 Standard Test Method for Analysis of Isotopic Composition of Uranium in Nuclear-Grade Fuel Material by Quadrupole Inductively Coupled Plasma-Mass Spectromet.pdf
  • ASTM C1474-2000(2011) Standard Test Method for Analysis of Isotopic Composition of Uranium in Nuclear-Grade Fuel Material by Quadrupole Inductively Coupled Plasma-Mass Spectrometry.pdf ASTM C1474-2000(2011) Standard Test Method for Analysis of Isotopic Composition of Uranium in Nuclear-Grade Fuel Material by Quadrupole Inductively Coupled Plasma-Mass Spectrometry.pdf
  • ASTM C1475-2005 Standard Guide for Determination of Neptunium-237 in Soil《测定土壤中镎237的标准指南》.pdf ASTM C1475-2005 Standard Guide for Determination of Neptunium-237 in Soil《测定土壤中镎237的标准指南》.pdf
  • ASTM C1475-2005(2010)e1 Standard Guide for Determination of Neptunium-237 in Soil《土壤中镎237检测的标准指南》.pdf ASTM C1475-2005(2010)e1 Standard Guide for Determination of Neptunium-237 in Soil《土壤中镎237检测的标准指南》.pdf
  • ASTM C1475-2017 Standard Guide for Determination of Neptunium-237 in Soil《测定土壤中镎237的标准指南》.pdf ASTM C1475-2017 Standard Guide for Determination of Neptunium-237 in Soil《测定土壤中镎237的标准指南》.pdf
  • ASTM C1477-2006 Standard Test Method for Isotopic Abundance Analysis of Uranium Hexafluoride and Uranyl Nitrate Solutions by Multi-Collector Inductively Coupled Plasma-Mass Spectro.pdf ASTM C1477-2006 Standard Test Method for Isotopic Abundance Analysis of Uranium Hexafluoride and Uranyl Nitrate Solutions by Multi-Collector Inductively Coupled Plasma-Mass Spectro.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

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