西电c++试题Word下载.docx
- 文档编号:15302342
- 上传时间:2022-10-29
- 格式:DOCX
- 页数:9
- 大小:138.73KB
西电c++试题Word下载.docx
《西电c++试题Word下载.docx》由会员分享,可在线阅读,更多相关《西电c++试题Word下载.docx(9页珍藏版)》请在冰豆网上搜索。
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;
friendCoperator+(constC&
constC&
);
//…
CC:
:
operator+(constC&
c1,constC&
c2){cout<
<
c1.sz;
//….
}
第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(){/*…*/}
c1.m();
C:
m();
c1.s();
s();
}(10)
template<
classT,inti>
classArray{intsz;
Array():
sz(i){}//……
voidf(intx)
{
Array<
int,x>
ay;
PartIIWritethefollowingprograms'
output.(30points)
1.(6points)
#include<
iostream>
usingnamespacestd;
voidmain(){inti=1;
while(i<
=15){i++;
if(i%3!
=1)continue;
elsecout<
;
2.(6points)
classIntNumber{
第3页共7页intvalue;
IntNumber(intvalue){this->
value=value;
IntNumber&
operator*=(intv){value*=v;
return*this;
friendvoidoperator<
(ostream&
outf,IntNumber&
n){outf<
n.value<
endl;
template<
classT>
constchar*cmp(Ta,Tb){return<
T>
CMP;
}constchar*cmp(IntNumbera,IntNumberb){return<
IntNumber>
cmp;
}constchar*cmp(IntNumbera,intb){return<
IntNumber,int>
}intmain(){
IntNumbera
(1),b
(2);
b*=10;
cout<
b=<
b;
cout<
cmp(a,b)<
endl;
cmp(a,0)<
cmp(1,0)<
return0;
3.(6points)
voidadd1(inta1){a1++;
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<
t1<
<
t2<
*t3<
t4<
t5<
4.(6points)
classB{public:
voidm(){cout<
B:
m<
classD:
publicB{public:
D:
intmain(){B*p[2];
p[0]=newD;
p[1]=newB;
for(inti=0;
=1;
i++)p[i]->
5.(6points)
classC{intvalue;
C(intv):
value(v){}booloperator<
(C&
b){
if(value<
b.value)returntrue;
returnfalse;
第5页共7页intgetValue(){returnvalue;
doublegetMin(doublea,doubleb){
getMin(double,double)isinvocated!
\t;
if(a<
b)returna;
returnb;
CgetMin(C&
a,C&
b){
getMin(C&
C&
)isinvocated!
CgetMin(Ca,Cb){
getMin(C,C)isinvocated!
intmain(){
Cc1(-9),c2(90);
getMin(10,99)<
getMin(1.2,2.3)<
getMin(10,2.3)<
getMin(c1,2).getValue()<
}
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;
s3.display();
s2=s1+3;
[3456789]
s3=++++s2
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c+ 试题