您好,欢迎访问三七文档
当前位置:首页 > 高等教育 > 理学 > 浙江工业大学考研845C++ 真题汇编
112012-2015845C++程序设计(I)真题汇编目录2015真题....................................................................................................................................2历年真题解析...........................................................................................................................10C++基础知识及流程控制................................................................................................10数组、C字符串、指针...................................................................................................13IO操作..............................................................................................................................15面向对象...........................................................................................................................162012编程大题.................................................................................................................222013编程大题.................................................................................................................252014编程大题.................................................................................................................29附录1:考试大纲.....................................................................................................................40附录2:历年考点....................................................................................................................43222015真题1.程序阅读题(5*9)1.请写出下面程序的运行结果。#includeiostreamusingnamespacestd;intmain(){intx=1;inty=1.5f;doublez=2.5+y;coutxzendl;cout((char*)xyz)[2];return0;}结果:13.5Z2.写出下面程序的运行结果。#includeiostreamusingnamespacestd;intmain(){for(inti=0;i=6;++i){for(intk=0;ki;k+=2)couti;coutendl;}return0;}结果:1233445556663.请写出下面程序的运行结果。#includeiostreamusingnamespacestd;inty=10;classEC33{intx;staticinty;public:EC(inta){x=a;}EC(floata){y+=a;}voidshow(){cout::y,y\n;}};intEC::y=100;intmain(){ECe1(10);e1.show();ECe2(10.0f);e2.show();return0;}结果:10,10010,1104.请写出下面程序的运行结果。#includeiostreamusingnamespacestd;classCExcept{};classCExceptApple:publicCExcept{};classCExceptOrange:publicCExcept{};intmain(){try{charstr[]=OrangeorApple?;charnewStr[10];char*p=str;for(;p-str=6;p++)newStr[p-str]=*p;newStr[p-str]=0;coutnewStrendl;switch(*(p-1)){case'm':throwCExceptApple();case't':throwCExceptOrange();44default:throwCExcept();}}catch(CExceptApple){coutApple;}catch(CExceptOrange){coutOrange;}catch(CExcept){coutUnknown;}return0;}结果:OrangeUnknown5.请写出下面程序的运行结果。#includeiostreamusingnamespacestd;classBClass{public:BClass(inta){coutBClass()endl;n=a;}virtualvoidshow(){coutBClass::show()endl;coutnendl;}~BClass(){cout~Base()endl;}protected:intn;};classSClass:publicBClass{BClassbase;intm;public:SClass(inta,intb,intc):BClass(a),base(b){coutSClass()endl;n=b;m=c;}voidshow(){coutSclass::Show()endl;coutn,mendl;}~SClass(){cout~SClass()endl;}55};intmain(){SClasss(1,2,3);BClass*p=&s;p-show();return0;}结果:BClass()BClass()BClass()SClass()Sclass::Show()2,3~SClass()~Base()~Base()~Base()2.程序改错题(5*3)1.下面程序存在编译期语法错误,请指出两个错误之处,并改正。#includeiostreamusingnamespacestd;voidMain(){x=10;inta[4][4]={{1,2,3,4},{2,3,4,5},{3,4,5,6},{4,5,6,7}},i,j;for(i=0;i4;i++){for(j=0;j=i;j++)couta[i][j];coutxendl;}}2.以下程序存在两处错误,请以尽量少的改动使得程序能够正常运行。#includeiostreamusingnamespacestd;classpoint{protected:point(inta){x=a;coutxendl;}point(point&p)66{x=p.x;coutxendl;}voidsetx(inta){x=a;}private:intx;};voidmain(){pointp1(1),p2(p1);p2.setx(2);pointp3=&p2;}3.下面这段程序最终输出结果为21,但是现在存在两个错误导致编译无法通过,找到语法错误并改正。#includeiostreamusingnamespacestd;voidmain(){inti,k,a[10],p[3];intk=5;for(i=0;i10;i++)a[i]=i;for(i=0;i3;i++)p[i]=a[i*(i+1)];for(i=0;i3;i++)k+=p[i]*2;cout(char)k;}3.编程题(30*3)1.文本文件A.txt中包含一组文本数据,且每组字符占一行,例子如下:1bcd24dp013Xcur……设计程序读入A.txt文件中的每行数据,逆转字符顺序后写入B.txt,在最后统计字符总数(注意:不包括数字),输出后例子如下:dcb1310pd42rucX总字符数:92.编制递归函数完成以下运算,并编写主函数测试。,函数原型longsum(intn);该函数完成的运算,并返回运算结果,其中n0。提示:递归表达式为:773.设计图书类CBook,能够存储书籍名称和价格两种属性。设计计算机图书CComputer类,继承自CBook,能够存储编程语言属性。设计历史图书CHistory;类,继承自CBook,能够存储历史年代属性。设计图书管理类CLib,支持新增书籍(包括计算机类图书和历史图书),该类提供函数输出所有书籍的名称列表,提供函数输出根据价格排序后的图书名称列表。编写测试代码验证CLib的功能。答案:1.#includefstream#includeiostream#includestringusingnamespacestd;intmain(){ifstreamin(A.txt);ofstreamout(B.txt);stringtemp=;intcount=0;while(!in.eof()){intemp;intlen=temp.length();for(inti=len-1;i=0;--i){if(isalpha(temp[i]))count++;outtemp[i];}outendl;}out总字符数:count;in.close();out.close();return0;}2.longsum(intn){if(n1)returnsum(n-1)+pow(n,2);elseif(n==1)return1;elseexit(1);}883.#includeiostream#includevector#includealgorithmusingnamespacestd;//CBook基类classCBook{public:CBook():bookName(unkonwn),price(0.0){}CBook(stringbookName,doubleprice):bookName(bookName),price(price){}stringgetBookName()const{returnbookName;}voidsetBookName(stringval){this-bookName=val;}doublegetPrice()const{returnprice;}voidsetPrice(doubleval){this-price=val;}private:stringbookName;doubleprice;};//CComputer子类classCComputer:publicCBook{public:CComputer():languageTyp
本文标题:浙江工业大学考研845C++ 真题汇编
链接地址:https://www.777doc.com/doc-4192858 .html