1 / 12
文档名称:

C程序设计程序代码例121.doc

格式:doc   大小:60KB   页数:12页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

C程序设计程序代码例121.doc

上传人:ttteee8 2019/7/27 文件大小:60 KB

下载得到文件列表

C程序设计程序代码例121.doc

文档介绍

文档介绍:C++,setupaPoint(dot)classthatcontainsdatamembersx,y(coordinatepoints).ItasabaseclasstoderiveaCircle(round)class,increasethedatamembersr(radius),andthentoCirclefordirectbaseclass,derivedaCylinder(Cylinder)class,adddatamemberh(high)・Towritetheprogram,theoverloadedoperator〃〈〈“and“〉〉〃tobeusedtooutputtheaboveclassobject・Foralargerprogram,thereareseveralstepstotake・Inthefirstclass,wedeclarethederivedclass,stepbystep,andstepbystep・declarethebaseclassPointclassThepartsofthePointthatcanbewrittenoutofthebaseclassareasfollows:#inelude<iostream>//declareclassPointTheclassPoint{public:Point(floatx=0,floaty二0);//constructorswithdefaultparametersVoidsetPoint(float,float);//setthecoordinatesFloatgetX()const{returnx;}//readxcoordinatesFloatgetY()const{returny;}//readycoordinatesFriendostream&operator(ostream&,constPoint&);//overloadedoperator〃〈〈“Protected://protectedmembersFloatx,y;};//thememberfunctionofthePointclassisdefinedbelow//Point,sconstructorPoint:Point(floata,floatb)//tox,yinitializes(x=a;Y二b;}//setthecoordinatesofxandyVoidPoint::setPoint(floata,floatb)//forx,ytonewvalue{x=a;Y二b;}//overloadedoperator〃〈〈“toenabletheoutputpointcoordinatesOstream&operator<<(ostream&output,constPoint&p){theoutput<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Returntheoutput;pletesthestatementofthebaseclassPointclass・Now,todebugthebaseclassdeclarationyouwroteabove,'(){Pointp(,);//establishthePointclassobject,p<<<<<<<<<<<<<<<<"><<<<<<"><<<<<<z,><<<<<<"><<<<<<z,><<<<<<z,><<<<<<,z>〈〈〈〈〈〈〃>〈〈〈〈〃〉〈〈//(,);//resetthepositionofpCout<<<<<<<<<,z><<<< ><<<<<z,>//overloadingoperator,'<<<<<<<<<<<<<<<<<<<<<<<<<〈〈〃>>,y=6・4P(new):[,]Thetestprogramchecksthefunctionofeachfunctioninthebaseclassandthefunctionofoperatoroverloading,whichprovesthattheprogramiscorrect・declarethederivedclassCircleOntopofthat,writethepartthatdeclaresthed