西电c++试题Word下载.docx

上传人:b****3 文档编号:15302342 上传时间:2022-10-29 格式:DOCX 页数:9 大小:138.73KB
下载 相关 举报
西电c++试题Word下载.docx_第1页
第1页 / 共9页
西电c++试题Word下载.docx_第2页
第2页 / 共9页
西电c++试题Word下载.docx_第3页
第3页 / 共9页
西电c++试题Word下载.docx_第4页
第4页 / 共9页
西电c++试题Word下载.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

西电c++试题Word下载.docx

《西电c++试题Word下载.docx》由会员分享,可在线阅读,更多相关《西电c++试题Word下载.docx(9页珍藏版)》请在冰豆网上搜索。

西电c++试题Word下载.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1