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

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

1、国家二级 C+机试(操作题)模拟试卷 463及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,该工程中包含程序文件 main cpp,其中有关 TVSet(“电视机 ”)和主函数 main的定义。程序中位于每个 “ ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: 规格: 29英寸,电源:开,频道: 5,音量: 18 规格: 29英寸,电源:关,频道: -1,音量: -1 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #include using n

2、amespace std; class TVSet “电视机 ”类 const int size; int channel; 频道 int volume; 音量 bool on; 电源开关: true表示开, false表示关 public: ERROR*found* TVSet(int size) this-size(size); channel=0; volume=15; on=false; int getSize()constreturn size; 返回电视机规格 bool isOn()constreturn on; 返回电源开关状态 返回当前音量,关机情况下返回 -1 int get

3、Volume()constreturn isOn()?volume: -1; 返回当前频道,关 机情况下返回 -1 int getChannel()const return isOn()?channel: -1; ERROR *found* void turnOnOff ()const 将电源在 “开 ”和 “关 ”之间转换 on=!on; void setChannelTo(int chan) 设置频道 (关机情况下无效 ) if(isOn()& chan=0 & chan=0 & vol #include #include using namespace std; class Score

4、public: Score(double*s, int n): s (s), n(n) double GetScore(int i)const return si; ) void Sort(); private: double * s; int n; ; void Score: Sort() *found* for(int i=0; ii; j-) if(_sj using namespace std; class MiniComplex复数类 public: 重载流插入和提取运算符 friend ostream&operator(istream&isObject, MiniComplex&c

5、omplex) char ch; isObjectcomplex realPartchcomplex imagPartch; return isObject; MiniComplex(double real=0, double imag=0); 构造函数 MiniComplex operator+(const MiniComplex&otherComplex)const; 重载运算符 + private: double realPart;存储实部变量 double imagPart;存储虚部变量 ; void writeToFile(char*); main cpp #include“Mini

6、Complex h“ MiniComplex: MiniComplex(double real, double imag)realPart=real;imagPart=imag; MiniComplex MiniComplex: operator+(const MiniComplex&other-Complex)const *333* *666* int main() void writeToFile(char*); MiniComplex num1(23, 34), num2(56, 35); coutimagPart+OtherComplex imagPart; 把 this中的虚部 (t

7、his-imagPart)和 othercomplex虚部相加赋值给 sum虚部 sum realPart = this-realPart+otherComplex realPart; 把 this中的实部 (this-reapart)加上 othercomplex实部赋值给 sum实部 return sum; 返回对象 sum 【试题解析】 主要考查考生对运算符重载的掌握,题目要求编写 operater+运算符函数,以实现复数的求和与运算。复数的和的 实部等于两个复数的实部之和,虚部等于两个复数的虚部之和。函数要返回的类型是 MiniComplex,因此要先定义一个 MiniComplex类型变量 sum,然后对它们的实部和虚部各自求和,返回sum即可。

展开阅读全文
相关资源
猜你喜欢
  • ASD-STAN PREN 4339-2001 Aerospace Series Heat Resisting Alloy CO-WH4001 (CoCr29W9) Filler Metal for Welding Wire and Rod (Edition P 2 Supersedes Edition P 1 March 1997 )《航空航天系列 焊丝和.pdf ASD-STAN PREN 4339-2001 Aerospace Series Heat Resisting Alloy CO-WH4001 (CoCr29W9) Filler Metal for Welding Wire and Rod (Edition P 2 Supersedes Edition P 1 March 1997 )《航空航天系列 焊丝和.pdf
  • ASD-STAN PREN 4340-1997 Aerospace Series Magnesium Alloy MG-W68001 Filler Metal for Welding Wire and Rod (Edition P 1)《航空航天系列 焊丝和焊条用镁合金MG-W68001填料金属 第P1版》.pdf ASD-STAN PREN 4340-1997 Aerospace Series Magnesium Alloy MG-W68001 Filler Metal for Welding Wire and Rod (Edition P 1)《航空航天系列 焊丝和焊条用镁合金MG-W68001填料金属 第P1版》.pdf
  • ASD-STAN PREN 4341-2001 Aerospace Series Aluminium Alloy AL-W46431 Filler Metal for Welding Wire and Rod (Edition P 2 Supersedes Edition P 1 March 1997 )《航空航天系列 焊丝和焊条用铝合金AL-W46431填.pdf ASD-STAN PREN 4341-2001 Aerospace Series Aluminium Alloy AL-W46431 Filler Metal for Welding Wire and Rod (Edition P 2 Supersedes Edition P 1 March 1997 )《航空航天系列 焊丝和焊条用铝合金AL-W46431填.pdf
  • ASD-STAN PREN 4342-2001 Aerospace Series Titanium TI-W99001 Filler Metal for Welding Wire and Rod (Edition P 2)《航空航天系列 焊丝和焊条用钛合金TI-W99001填料金属 第P2版》.pdf ASD-STAN PREN 4342-2001 Aerospace Series Titanium TI-W99001 Filler Metal for Welding Wire and Rod (Edition P 2)《航空航天系列 焊丝和焊条用钛合金TI-W99001填料金属 第P2版》.pdf
  • ASD-STAN PREN 4343-1997 Aerospace Series Steel FE-WM1001 (X13Cr12) Filler Metal for Welding Wire and Rod (Edition P 1)《航空航天系列 焊丝和焊条用钢FE-WM1001(X13Cr12)填料金属 第P1版》.pdf ASD-STAN PREN 4343-1997 Aerospace Series Steel FE-WM1001 (X13Cr12) Filler Metal for Welding Wire and Rod (Edition P 1)《航空航天系列 焊丝和焊条用钢FE-WM1001(X13Cr12)填料金属 第P1版》.pdf
  • ASD-STAN PREN 4344-2001 Aerospace Series Steel FE-WM1002 (X13Cr13) Filler Metal for Welding Wire and Rod (Edition P 2 Supersedes Edition P 1 March 1997 Replaced by EN 4344)《航空航天系列 .pdf ASD-STAN PREN 4344-2001 Aerospace Series Steel FE-WM1002 (X13Cr13) Filler Metal for Welding Wire and Rod (Edition P 2 Supersedes Edition P 1 March 1997 Replaced by EN 4344)《航空航天系列 .pdf
  • ASD-STAN PREN 4346-2000 Aerospace Series Steel FE-PM1505 (X1CrNiMoAlTi12-9-2) Vacuum Induction Melted and Consumable Electrode Remelted Softened Forging Stock a or D Less Than or E.pdf ASD-STAN PREN 4346-2000 Aerospace Series Steel FE-PM1505 (X1CrNiMoAlTi12-9-2) Vacuum Induction Melted and Consumable Electrode Remelted Softened Forging Stock a or D Less Than or E.pdf
  • ASD-STAN PREN 4347-2000 Aerospace Series Steel FE-PM1506 (X3CrNiMoAl13-8-2) Vacuum Induction Melted and Consumable Electrode Remelted Softened Forging Stock a or D Less Than or Equ.pdf ASD-STAN PREN 4347-2000 Aerospace Series Steel FE-PM1506 (X3CrNiMoAl13-8-2) Vacuum Induction Melted and Consumable Electrode Remelted Softened Forging Stock a or D Less Than or Equ.pdf
  • ASD-STAN PREN 4351-1997 Aerospace Series Rod Ends with Self-Aligning Double Row Ball Bearings and Threaded Shank in Corrosion Resisting Steel Dimensions and Loads Inch Series (Edit.pdf ASD-STAN PREN 4351-1997 Aerospace Series Rod Ends with Self-Aligning Double Row Ball Bearings and Threaded Shank in Corrosion Resisting Steel Dimensions and Loads Inch Series (Edit.pdf
  • 相关搜索

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

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