西电c++试题.docx
- 文档编号:2385281
- 上传时间:2022-10-29
- 格式:DOCX
- 页数:9
- 大小:138.73KB
西电c++试题.docx
《西电c++试题.docx》由会员分享,可在线阅读,更多相关《西电c++试题.docx(9页珍藏版)》请在冰豆网上搜索。
西电c++试题
第1页共7页西安电子科技大学
考试时间120分钟
试题
题号一二三四总分
分数
1.考试形式:
闭卷;2.本试卷共四大题,满分100分。
班级学号姓名任课教师
PartIThereisoneerrorineachcodeparagraph.Findouttheerrorandwritedowntheerrorstatementonyouranswersheet.
(20points)
(1)
float*ptr=newfloat[20];for(inti=0;i<20;i++)ptr[i]=i+2;deleteptr;
(2)
namespacemyspace{voiddo(){/*…*/}
inttemp;}
usingnamespacemyspace;
usingnamespacemyspace:
temp;
(3)
classC{intx;
voidsetx(inta){/*…*/}
};
voidmain(){Cc1;
c1.setx(3);}
(4)
classStudent{//…
public:
voidStudent();~Student();};
(5)classBC{intx;public:
BC(intxx=0){x=xx;}};
classDC:
publicBC{charc;
DC(intx1,charc1){
x=x1;c=c1;
}};(6)
classC{intsz;public:
friendCoperator+(constC&,constC&);//…
};
CC:
:
operator+(constC&c1,constC&c2){cout< } 第2页共7页 (7) classB{public: B(inta=10,floaty){i=a;z=y;}private: inti;floatz;}; (8) classAnimal{public: virtualvoidf()=0;}; voidf(){Animalb;} (9)classC{public: voidm(){/*…*/} staticvoids(){/*…*/} }; voidmain(){Cc1;c1.m();C: : m();c1.s();C: : s();}(10) template Array(): sz(i){}//…… }; voidf(intx) { Array PartIIWritethefollowingprograms'output.(30points) 1.(6points) #include if(i%3! =1)continue;elsecout< } 2.(6points) #include 第3页共7页intvalue;public: IntNumber(intvalue){this->value=value;} IntNumber&operator*=(intv){value*=v;return*this;} friendvoidoperator<<(ostream&outf,IntNumber&n){outf< template IntNumbera (1),b (2); b*=10; cout< } 3.(6points) #include } voidadd2(int&a2){a2++;} voidadd3(int*a3){(*a3)++;} intmain(){intt1=2,t2=2,*t3=&t2,t4=t2,&t5=t2; 第4页共7页add1(t1);add2(t2);add3(t3);add3(&t4);add2(t5);cout< } 4.(6points) #include voidm(){cout< : m< classD: publicB{public: voidm(){cout< : m< for(inti=0;i<=1;i++)p[i]->m();return0; } 5.(6points) #include C(intv): value(v){}booloperator<(C&b){ if(value 第5页共7页intgetValue(){returnvalue;}}; doublegetMin(doublea,doubleb){ cout< \t;if(a CgetMin(C&a,C&b){ cout< \t;if(a CgetMin(Ca,Cb){ cout< \t;if(a intmain(){ Cc1(-9),c2(90); cout< cout< cout< cout< } PartIIIObject-OrientedAnalyzingandDesigning(30points) 1.Fromfollowingpictures,pleaseanalyzeanddesigntheclassandclassHierarchies.(15points) 第6页共7页 2.(15points) DefineaclassnamedPointwhichcanexpressthepositionofanypointinaplanecoordinate(坐标)system.APointobjectcontainstwoprivatedatamember: xwhichholdsthehorizontalcoordinate,ywhichholdstheverticalcoordinate.Thisclassshouldhavesuchpublicoperations: a)adefaultconstructorthatsetthecoordinateto(0,0); b)aconstructorthattakestwointeger,whichinitializesthexandy; c)anoverloadedoperator“+=”whichmovesthepointtoanother position; d)somememberfunctionstore-setorgeteachoftwodatamembers. PartIVProgramming(20points) 1.(10points) Defineandimplementaclass“MyString”accordingtothemain()andtheoutputincomments. intmain(){ MyStrings1(0123456789),s2(5),s3; s1.display();//Output: [0123456789] s2.display();//Output(5spacesbetween[]): []s3.display();//Output(nospacebetween[]): []s3=s1; s1.display();//Output: [0123456789] s3.display();//Output: [0123456789] s2=s1+3; s1.display();//Output: [0123456789] s2.display();//Output: [3456789] s3=++++s2
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c+ 试题
![提示](https://static.bdocx.com/images/bang_tan.gif)