面向对象程序设计C++双语Word文档下载推荐.docx
- 文档编号:22420238
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:28
- 大小:55.52KB
面向对象程序设计C++双语Word文档下载推荐.docx
《面向对象程序设计C++双语Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《面向对象程序设计C++双语Word文档下载推荐.docx(28页珍藏版)》请在冰豆网上搜索。
z=c;
}intSun(){returnx+z;
}};
------------
9、Objectofabaseclasscanbetreatedasanobjectofthederivedclass.------------
三、Completetheprogram(3*5’=15’)(Everyquestionis5point,totalis15point)
(attention:
onelineforjustonesentence)
1、Afterthemainfunction,theresultis:
x=0;
y=0
x=3;
y=5
Destructoriscalled...
Pleasecompletetheprogram.
#include<
iostream.h>
voidmain()
{
demod;
d.show();
demod1(3,5);
d1.show();
demod2(d1);
d2.show();
}
classdemo{
intx,y;
public:
------demo(intx=0,inty=0)-----{x=a;
y=b;
}
---------demo(*d)-------{
x=d.x;
y=d.y;
------~demo()--------{-----Destructoriscalled...
-----}
voidshow()
-------------cout<
”x=”<
x<
”;
y=”<
y;
---------------
};
2、#include<
#include<
string.h>
classperson{
char*Name;
intAge;
person(char*name,intage);
~person();
char*GetName(){returnName;
intGetAge(){returnAge;
voidshow();
person:
person(char*name,intage){
------------①------------------------
-------------②-----------------------
Age=age;
~person()
{
deleteName;
voidperson:
show(){
cout<
GetName()<
'
\t'
GetAge()<
endl;
classstudent:
publicperson{
char*Department;
intNumber;
student(char*,int,char*,int);
~student(){deleteDepartment;
voidSetDep(char*){//……theimplementationisomitted}
voidSetNum(intnum){Number=num;
char*GetDep(){returnDepartment;
intGetNum(){returnNumber;
};
--------------------------③--------------------------------------------
--------------------------④---------------------
--------------------------⑤---------------------
Number=num;
3、Thefollowingprogramisusedtocalculatethedistancebetweentwopoints,pleasecompletetheprogram.
math.h>
classPoint
{public:
Point(doublexx=0,doubleyy=0){X=xx;
Y=yy;
doubleGetX(){returnX;
doubleGetY(){returnY;
-----------------①---------------------------
private:
doubleX,Y;
doubleDist(Point&
a,Point&
b)
----------②--------------
-----------③--------------
returnsqrt(dx*dx+dy*dy);
intmain()
{
Pointp1(3.0,5.0),p2(4.0,6.0);
----------------④--------------------
"
Thedistanceis"
d<
return0;
Theresultis------------⑤----------------
四、Readtheprogramandwriteouttheresult.(Everyquestionis5point,totalis20point)
1、Pleasewritetheresultofthefollowingprogram:
intsub(intn)
inta;
if(n==1)
return1;
a=n+sub(n-1);
return(a);
voidmain()
{inti=5;
sub(i)<
2、Pleasewritetheresultofthefollowingprogram:
classtest{
intnum;
floatfl;
test();
intgetint(){returnnum;
floatgetfloat(){returnfl;
~test();
test:
test(){
cout<
Initalizingdefault"
num=0;
fl=0.0;
~test(){cout<
Destructorisactive"
voidmain(){
testarray[2];
array[1].getint()<
"
array[1].getfloat()<
3、Pleasewritetheresultofthefollowingprogram:
#include<
string.h>
classStudent{
stringname;
staticintnum;
Student(string&
str){
name=str;
++num;
intStudent:
num=0;
intmain(){
Students1("
Smith"
),s2(“John”);
”Student:
num=”<
Student:
num<
“\n”;
Students3("
Marry"
),s4(“Tom”);
s3.num="
s3.num<
s4.num="
s4.num<
4、Pleasewritetheresultofthefollowingprogram:
classB1
{public:
B1(inti){cout<
constructingB1"
i<
~B1(){cout<
destructingB1"
classB2
B2(intj){cout<
constructingB2"
j<
~B2(){cout<
destructingB2"
classB3
B3(){cout<
constructingB3*"
classC:
publicB2,publicB3,publicB1
C(inta,intb,intc,intd):
B1(a),memberB2(d),memberB1(c),B2(b)
{cout<
constructingC"
~C(){cout<
destructingC"
B2memberB2;
B1memberB1;
B3memberB3;
Cobj(1,3,5,7);
五、Programming(Thequestionis15point)
Accordingtothedescription,designaprogramwithmainfunction.(Description:
Inthefirststep,pleasedeclareanabstractclassShape.Then,basedonittwoclassesnamedRectangleandCirclearederived.Inboththetwoclasses,thefunctionsGetArea()calculatingfortheareaandGetPeri()calculatingfortheperimetermustbeinvolved.)
江西财经大学
06-07学年第二学期期末考试试卷
试卷代码:
03874A课时:
64学时
课程名称:
面向对象程序设计(C++)(双语)适用对象:
计算机及其相关专业
试卷命题人:
杨勇试卷审核人:
舒蔚
I、Single-Choice(Everyquestiontakes2points,thetotalscoreis32points)
1、Whenweinput“TaoZou”,theoutputofthefollowingprogramis()consequently.
iostream>
string>
usingnamespacestd;
intmain()
stringstr;
pleaseenteryourname"
cin>
>
str;
hello,"
str<
!
\n"
;
A.hello,Zou!
B.hello,Tao!
C.hello,TaoZou!
D.hello,!
2、Thestatement(d)isnotthecharacteristicofthestandardlibrary.
A.ItsupportsStringsandI/Ostreams
B.
B.
ItsupportstheCstandardlibrarywithveryminormodifications
C.ItSupportsfornumericalcomputation
D.Itsupportscompilingcheckingerrors
E.
3、Afterexecutingthefollowingprogram,()istherunningresult.
longfac(intn){
longf;
b
if(n>
1)f=n*fac(n-1);
elsef=1;
returnf;
fac(6)<
A.120B.720C.30.D.1
4、GivenaclassMyClass,afterexecutingthesentence:
MyClassa[2],b,*p,thedestructor~MyClass(d)willbecalled()times.
A.1B.2C.3D.4
5、Inordertoimprovethespeedofthefunction,thefunctioncanbewrittenas(d).
A.InlinefunctionB.FunctionoverloadingC.RecursivefunctionD.Friendfunction
6、Therunningresultsoftheprogramare(a).
voidfunc(intp,int&
q)
{intt;
t=p;
p=q;
q=t;
{intx=1,y=2;
func(x,y);
”,”<
y<
A.1,2B.2,1C,1,1D.2,2
7、Forfunctionswithdefaultarguments,()isnotwrong.
A.intadd(intx,inty=5,intz=6)
B.intadd(intx=1,inty=5,intz)
C.intadd(intx=1,inty,intz=6)
D.intadd(intx,inty=5,intz)
8、C++hasthefollowingcharacteristicsexcept().
A.PolymorphismB.ObjectC.AbstractD.Inheritance
9、Oneofthefollowingdescriptionisright,itis().
A.C++isasub-setofC,itreservesalmostallthecharacteristicsofC
B.Bothconstructoranddestructorcannotbeoverloaded
C.IfclassBisafriendofclassA,thenclassAisalsothefriendofclassB
D.Noobjectsofanabstractbaseclasscanbeinstantiated
10、Foranon-memberoperatoroverloadedfunction,amodecomputationcandedefinedas().
A.Xoperator%(constX)
B.Xoperator%(constX,constX)
C.Xoperator%()
D.voidoperator%(constX,constX)
11、(d)isnottrueforthedescriptionofconstructor.
A.Theconstructorshouldhavethesamenameastheclassname
B.Thesystemwillautomaticallycalltheconstructorduringdefiningobject
C.Noreturningtypefortheconstructor
D.Theconstructorcanhavejustonlyone
12、Amongthefollowingdescriptions,(c)isnotcorrect.
A.Insideinlinefunction,thereisnocycleandswitchsentences.
B.Usingthesamenameforoperationsondifferenttypesiscalledoverloading
C.Giventhefunctionprototype:
doublesqrt(double),wecanwritecout<
sqrt("
three"
)
D.Theformofoperatoroverloadingforprefixincrementislike:
typeoperator++()
13、Forvirtualfunctions,amongthefollowingdeclarations(d)isright.
A.Virtualfunctionscanbedefinedasfriendfunctions
B.Virtualfunctionscanbeoverloaded
C.Constructorscanbevirtualfunctions,whiledestructorscannot
D.Virtualfunctionscannotbedefinedasstaticfunctions
14、IfwewanttodefineafriendfunctionofclassAB,wecandefineitas:
A.voidfriendfunc(AB&
)c
B.friendfunc(AB&
C.friendintfunc(AB&
D.friendvoidfunc()
15、Aboutclassandobject,(a)iswrong.
A.AclasscanjusthaveoneobjectB.Classisanabstractofonetypeofobjects
C.ObjectisaninstanceofaclassD.Therelationlikethevariablesandtheirtype
16、Forstaticmemberdata,itisinitializedatb().
E.Beforethedeclarationofclassandafterthemainfunction
F.Beforethemainfunctionandafterthedeclarationofclass
G.Intheclassdeclaration
II、TrueorFalse(Sixprogramsaregiveninthefollowing,foreachofthem,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 面向 对象 程序设计 C+ 双语
![提示](https://static.bdocx.com/images/bang_tan.gif)