毕业论文5000字英文文献翻译文档格式.docx

上传人:b****2 文档编号:13341963 上传时间:2022-10-09 格式:DOCX 页数:12 大小:26.84KB
下载 相关 举报
毕业论文5000字英文文献翻译文档格式.docx_第1页
第1页 / 共12页
毕业论文5000字英文文献翻译文档格式.docx_第2页
第2页 / 共12页
毕业论文5000字英文文献翻译文档格式.docx_第3页
第3页 / 共12页
毕业论文5000字英文文献翻译文档格式.docx_第4页
第4页 / 共12页
毕业论文5000字英文文献翻译文档格式.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

毕业论文5000字英文文献翻译文档格式.docx

《毕业论文5000字英文文献翻译文档格式.docx》由会员分享,可在线阅读,更多相关《毕业论文5000字英文文献翻译文档格式.docx(12页珍藏版)》请在冰豆网上搜索。

毕业论文5000字英文文献翻译文档格式.docx

veseenalready,suchasistreamandostream,arealldefinedasclassesthatis,theyarenotstrictlyspeakingpartofthelanguage.

Completeunderstandingoftheclassmechanismrequiresmasteringalotofinformation.Fortunately,itispossibletouseaclassthatsomeoneelsehaswrittenwithoutknowinghowtodefineaclassourselves.Inthissection,we'

lldescribeasimpleclassthatwecanuseinsolvingourbookstoreproblem.We'

llimplementthisclassinthesubsequentchaptersaswelearnmoreabouttypes,expressions,statements,andfunctionsallofwhichareusedindefiningclasses.

Touseaclassweneedtoknowthreethings:

Whatisitsname?

Whereisitdefined?

Whatoperationsdoesitsupport?

Forourbookstoreproblem,we'

llassumethattheclassisnamedSales_itemandthatitisdefinedinaheadernamedSales_item.h.

TheSales_itemClass

ThepurposeoftheSales_itemclassistostoreanISBNandkeeptrackofthenumberofcopiessold,therevenue,andaveragesalespriceforthatbook.Howthesedataarestoredorcomputedisnotourconcern.Touseaclass,weneednotknowanythingabouthowitisimplemented.Instead,whatweneedtoknowiswhatoperationstheclassprovides.

Aswe'

veseen,whenweuselibraryfacilitiessuchasIO,wemustincludetheassociatedheaders.Similarly,forourownclasses,wemustmakethedefinitionsassociatedwiththeclassavailabletothecompiler.Wedosoinmuchthesameway.Typically,weputtheclassdefinitionintoafile.Anyprogramthatwantstouseourclassmustincludethatfile.

Conventionally,classtypesarestoredinafilewithanamethat,likethenameofaprogramsourcefile,hastwoparts:

afilenameandafilesuffix.Usuallythefilenameisthesameastheclassdefinedintheheader.Thesuffixusuallyis.h,butsomeprogrammersuse.H,.hpp,or.hxx.Compilersusuallyaren'

tpickyaboutheaderfilenames,butIDEssometimesare.We'

llassumethatourclassisdefinedinafilenamedSales_item.h.

OperationsonSales_itemObjects

Everyclassdefinesatype.Thetypenameisthesameasthenameoftheclass.Hence,ourSales_itemclassdefinesatypenamed

Sales_item.Aswiththebuilt-intypes,wecandefineavariableofaclasstype.Whenwewrite"

Sales_itemitem"

wearesayingthatitemisanobjectoftypeSales_item.Weoftencontractthephrase"

anobjectoftypeSales_item"

to"

aSales_itemobject"

orevenmoresimplyto"

aSales_item."

InadditiontobeingabletodefinevariablesoftypeSales_item,wecanperformthefollowingoperationsonSales_itemobjects:

Usetheadditionoperator,+,toaddtwoSales_items,

Usetheinputoperator,<

<

toreadaSales_itemobject,

Usetheoutputoperator,>

>

towriteaSales_itemobject,

Usetheassignmentoperator,=,toassignoneSales_itemobjecttoanother,

Callthesame_isbnfunctiontodetermineiftwoSales_itemsrefertothesamebook.

ClassesarecentraltomostC++programs:

Classesletusdefineourowntypesthatarecustomizedfortheproblemsweneedtosolve,resultinginapplicationsthatareeasiertowriteandunderstand.Well-designedclasstypescanbeaseasytouseasthebuilt-intypes.

Aclassdefinesdataandfunctionmembers:

Thedatamembersstorethestateassociatedwithobjectsoftheclasstype,andthefunctionsperformoperationsthatgivemeaningtothedata.Classesletusseparateimplementationandinterface.Theinterfacespecifiestheoperationsthattheclasssupports.Onlytheimplementoroftheclassneedknoworcareaboutthedetailsoftheimplementation.Thisseparationreducesthebookkeepingaspectsthatmakeprogrammingtediousanderror-prone.

Classtypesoftenarereferredtoasabstractdatatypes.Anabstractdatatypetreatsthedata(state)andoperationsonthatstateasasingleunit.Wecanthinkabstractlyaboutwhattheclassdoes,ratherthanalwayshavingtobeawareofhowtheclassoperates.Abstractdatatypesarefundamentaltobothobject-orientedandgenericprogramming.

Dataabstractionisaprogramming(anddesign)techniquethatreliesontheseparationofinterfaceandimplementation.Theclassdesignermustworryabouthowaclassisimplemented,butprogrammersthatusetheclassneednotknowaboutthesedetails.Instead,programmerswhouseatypeneedtoknowonlythetype'

sinterface;

theycanthinkabstractlyaboutwhatthetypedoesratherthanconcret

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

当前位置:首页 > 高等教育 > 军事

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

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