大连交大第一套模拟试题.docx

上传人:b****5 文档编号:5852778 上传时间:2023-01-01 格式:DOCX 页数:18 大小:25.44KB
下载 相关 举报
大连交大第一套模拟试题.docx_第1页
第1页 / 共18页
大连交大第一套模拟试题.docx_第2页
第2页 / 共18页
大连交大第一套模拟试题.docx_第3页
第3页 / 共18页
大连交大第一套模拟试题.docx_第4页
第4页 / 共18页
大连交大第一套模拟试题.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

大连交大第一套模拟试题.docx

《大连交大第一套模拟试题.docx》由会员分享,可在线阅读,更多相关《大连交大第一套模拟试题.docx(18页珍藏版)》请在冰豆网上搜索。

大连交大第一套模拟试题.docx

大连交大第一套模拟试题

专业

班级

学号

姓名

 

教研室主任

(签字)

 

学院院长(系主任)

(签字)

课程C++程序设计(A)

课程性质(√必修□专业限选□任选)考试方式(√闭卷□开卷)

得分

PartI、Selection(totalpoints40,2pointsperquestion,tatolquestion20.)

1.WhenC++programmeruns,italwaysstartatthe().

A.thefirstsentenceofprogramme

B.thefirstsentenceafterpretreatment(预处理)

C.main( )

D.pretreatment

2.Therearethefollowingdefinition:

intx=100,y;

int*p1;

constint*p2=&x;

Whichofthefollowingstatementsisincorrect?

()

A.p1=&x;B.p1=p2;

C.p2=p1;D.p2=&y;

3.Howmanytimesisthefollowingloopperformed(执行)?

()

for(intm=0,n=5;m=n=5;m++,n++)

A.endlesscircleB.0C.5D.error

4.WhichistheillegaldeclarationinC++?

()

A.intfat(intx=12,chary=‘a’,floatz=12.3);

B.intfat(intx,chary=‘a’,floatz=12.3);

C.intfat(intx=12,chary,floatz);

D.intfat(intx=12,chary=‘a’,float=12.3);

5.Iftherearethedefinition:

constintx=24;inty=10;whichistheincorrectusing?

()

A.int&r=x;B.int&r=y;C.int*p=&y;D.constint*p=&x;

6.Whichistheincorrectobjectdefinition?

()

classCss

{public:

Css(intx,inty=0){a=x;b=y;}

private:

inta,b;};

A.Cssc1;B.Cssc1(10);C.Css(30,50);D.Cssc1(10,70);

7.IfAisanabstractclass,whichdeclarationiscorrectasfollow?

()

A.Af(int)B.A*pC.intf(Aa1)D.Aobj

8.Whenoverloadingfunctioniscalled,whichofthefollowingconditionscannotbeusedasbasis?

()

A.parameter(参数)numberB.parametertype

C.functionnameD.functiontype

题号

总分

得分

9.Thepointervariableisa().

A.valueB.addressC.nameD.logo

10.Thereisthefunctiondeclaration:

voidfn(int&x);andthedefinition:

intm=20;thenthefollowingcallingiscorrect?

()

A.fn(10);B.fn(200+m);C.fn(m);D.fn(&m);

11.Whichisincorrectaboutdestructor?

()

A.Thedestructorcanhavetheoverloadfunction.

B.Thedestructoriscalledautomaticallywhenanobjectisreleased.

C.Thedestructorhasnotanyfunctiontype.

D.Theonlyonedestructorcanexistinaclass.

12.Wehaveaclassasfollow:

classBase

{public:

virtualvoidf1(){cout<<"classBasef1"<

voidf2(){cout<<"classBasef2"<

};

classDerived:

publicBase

{public:

voidf1()

{cout<<"classDerivedf1"<

virtualvoidf2()

{cout<<"classDerivedf2"<

};

Whichisthecorrectdescription?

()

A.BothBase:

:

f2()andDerived:

:

f1()arevirtualfunction

B.NeitherBase:

:

f2()norDerived:

:

f1()isvirtualfunction

C.Derived:

:

f1()isvirtualfunction,butBase:

:

f2()isn’tvirtualfunction

D.Derived:

:

f1()isn’tvirtualfunction,butBase:

:

f2()isvirtualfunction

13.Aclass’sinstantiation(实例化)refersto()

A.definetheclassB.demonstrateaspecificclass

C.createobjectsoftheclassD.callmembersoftheclass

14.Ifaclasshasatleastonepurevirtualfunction,wecalltheclassas?

()

A.abstractclassB.virtualbaseclassC.derivedclassD.noneisright

15.Inthefollowingfunctionprototypes(原型).WhichonecanbetheconstructoroftheclassAA()

A.voidAA(int);B.intAA();C.AA(int)const;D.AA(int);

16.Staticmemberfunctionshaveno()

A.returnvalueB.thispointer

C.pointerparameterD.returntype

17.GiventhatclassAisafriendclassofclassBandclassBisafriendclassofclassC,then()

A.classAmustbeafriendclassofclassC;

B.classCmustbeafriendclassofclassA;

C.thememberfunctionsofclassCcanvisitanymembersofclassB’sobjects;

D.thememberfunctionsofclassAcanvisitanymembersofclassB’sobjects.

考生注意:

考试时间100分钟试卷总分100分答案写在答题页共6页第1页

 

专业

班级

学号

姓名

18.Whichisincorrectaboutfriendrelation?

()

A.cannotbeinheritedB.relationbetweenclasses

C.isbidirectional(双向的)relationD.toimprovetheefficiencyofprogram

19.Whichisthecorrectdeclarationofthepurevirtualfunction()

A.intfpure(intx)=0;B.virtualintfpure(intx)=0;

C.vitualintfpure(intx=0);D.virtualintfpure(intx=0){}

20.Therearethefollowingdefinitionofclass:

classCA{intx;};

classCB:

publicCA

{inty;};

CA*pa,a;

CB*pb,b;

Whichusingisincorrect?

()

A.pa=&a;B.pa=&b;C.b=a;D.a=b;

 

PartIIPleasereadtheprogramandgivetheresult.(totalquestions:

10,totalpoints:

40.)

得分

1.#include

intfun(inta);

voidmain()

{ints=0;

intnum;

num=4;

for(inti=1;i<=num;i++)

s+=fun(i);

cout<<"s="<

}

intfun(inta)

{staticintb=1;

b*=a;

returnb;

}

2.#include

usingnamespacestd;

voidshift1(int&a,int&b)

{inttemp;

temp=a;a=b;b=temp;

}

voidshift2(inta,intb)

{inttemp;

temp=a;a=b;b=temp;

}

voidmain()

{intx=12,y=36;

shift2(x,y);

cout<<"x="<

shift1(x,y);

cout<<"x="<

}

3.#include

intfun(intx,inty)

{returnx*y;}

voidmain()

{intk=5;

cout<

}

4.#include

usingnamespacestd;

classA

{intx,y;

public:

A(inta=0,intb=0){x=a;y=b;}

voidPrint(void){cout<

};

voidmain()

{Aa1,a2(5),a3(8,9);

a1.Print();

a2.Print();

a3.Print();

}

5.#include

usingnamespacestd;

classA

{public:

intx,y;

staticintcount;

A()

{x=0;y=0;

count++;}

A(intx0,inty0)

{x=x0;y=y0;

count++;}

staticvoidstaFun()

{cout<

};

intA:

:

count=0;

共6页第2页

 

专业

班级

学号

姓名

voidmain()

{Aobj(2,4),*p;

cout<

:

count<<",";

Aa[5];

obj.staFun();

p=newA(6,9);

cout<count<<",";

A&rA=obj;

A:

:

staFun();

deletep;

}

6.#include

usingnamespacestd;

classRatio

{intnum,den;

public:

Ratio(intn=0,intd=1)

{num=n;den=d;

cout<<“con”<

Ratio(Ratio&r)

{num=r.num;

den=r.den;

cout<<“Copycon”<

};

voidfn(Ratio&r1)

{cout<<"fncalled"<

voidmain()

{cout<<“Rxis:

”;

Ratiox(40,9);

cout<<“Ryis:

”;

Ratioy(x);

fn(x);

}

7.#include

usingnamespacestd;

template

classTAdd

{Tx,y;

public:

TAdd(Ta,Tb):

x(a),y(b){cout<<”tem_constructor”<

intadd(){returnx+y;}

};

intmain()

{TAddt1(20,30);

cout<

}

8.#include

usingnamespacestd;

classbase

{intn;

public:

base(inta):

n(a)

{cout<<"base";

cout<<"n="<

~base()

{cout<<"des_base";}

};

classsubs:

publicbase

{basebobj;

intm;

public:

subs(inta,intb,intc):

base(a),bobj(c),m(b)

{cout<<"subs";

cout<<"m="<

}

~subs()

{cout<<"des_sub";}

};

voidmain()

{subss(1,2,3);}

9.#include

usingnamespacestd;

classfath

{public:

voidfun()

{cout<<"fathfun"<

voidfun(intx=0)

{cout<<"fathfun"<

};

classchil:

publicfath

{public:

voidfun(intx=25)

{cout<<"chilfun"<

};

共6页第3页

 

专业

班级

学号

姓名

intmain()

{fath*pf,f1;

chilc1;

pf=&c1;

c1.fun();

pf->fun(100);

return0;

}

10.#include

usingnamespacestd;

classBase

{public:

virtualvoidf(){cout<<"Base_f";}

};

classDer:

publicBase

{public:

Der(){}

voidf(){cout<<"Der_f";}

};

classBD:

publicDer

{public:

virtualvoidf()

{Der:

:

f();

cout<<"BD_f";}

};

voidmain()

{Baseb1,*p;

p=&b1;

b1.f();

p->f();

cout<

Derd1;

p=&d1;

d1.Base:

:

f();

p->f();

cout<

BDc1;

p=&c1;

p->f();

cout<

}

 

得分

PartⅢ、Clozetheprogram.(totalquestions:

4,totalblank:

10,totalpoints:

20)Fillinpropercontentontheemptylineoffollowingprogram,thentheprogramcansatisfyrequire.

1.TodefineaclassofPointandamemberfunction(doubleDistance(Point&))forcalculatingdistanceofdeuce(两点)andoutput.(6points)

#include

#include

usingnamespacestd;

classPoint

{public:

(1)

{x=xx;y=yy;}

doubleDistance(Point&p)//求两点之间的距离

{x-=p.x;

y-=p.y;

(2);

}

private:

doublex;

doubley;

};

voidmain()

{Pointp1(7,2),p2(3,4);

(3);

}

2.Thefollowingprogramdefinesonedimensionarrayclass.Todefineandfinishaddoperatoroverloadfunctionoftwoarrays.(6points)

#include

usingstd:

:

cout;

usingstd:

:

endl;

classArray

{intarr[10];

public:

Array(inta[])

{for(inti=0;i<=9;i++)

arr[i]=a[i];}

Array(){}

voiddisplay()

{for(inti=0;i<=9;i++)

cout<

cout<

}

~Array(){cout<<"detructoriscalled"<

(4);

};

共6页第4页

 

专业

班级

学号

姓名

Arrayoperator+(Arrayb,Arraya)

{Arraytemp;

inti;

(5)

(6);

returntemp;}

voidmain()

{intb1[10]={11,21,13,42,5,16,27,38,29,0};

intb2[10]={0,9,8,7,6,5,4,3,2,1};

Arrayarr1(b1),arr2(b2),arr3;

arr3=arr1+arr2;

arr3.display();

}

3.Theoutputresultoffollowingprogramis“0,6,6”.(4points)

#include

usingnamespacestd;

classBase

{public:

(7)f(){return0;}

};

classDerived:

publicBase

{public:

inti,j,k;

voidset(intii,intjj,intkk){i=ii;j=jj;k=kk;}

intf(){returni+j+k;}

};

voidmain()

{Baseb;

Derivedd;

cout<

d.set(1,2,3);

cout<

Base*p;

(8);

cout<f()<

}

4.Therearetwocomplexobjects‘com1’and‘com2’,thefollowingprogramcanjudgewhether‘com1’isequalto‘com2’with‘==’operatoroverloadfunctionorwith‘!

=’operatoroverloadfunction.

(4points)

#include

usingnamespacestd;

classcomplex

{floatx,y;

public:

complex(floata=0,floatb=0)

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

当前位置:首页 > 医药卫生 > 基础医学

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

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