STL练习.docx

上传人:b****5 文档编号:2824706 上传时间:2022-11-15 格式:DOCX 页数:10 大小:262.08KB
下载 相关 举报
STL练习.docx_第1页
第1页 / 共10页
STL练习.docx_第2页
第2页 / 共10页
STL练习.docx_第3页
第3页 / 共10页
STL练习.docx_第4页
第4页 / 共10页
STL练习.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

STL练习.docx

《STL练习.docx》由会员分享,可在线阅读,更多相关《STL练习.docx(10页珍藏版)》请在冰豆网上搜索。

STL练习.docx

STL练习

综合实验1:

模拟客户分组

✧ClassClient

ClassClientmodelsaregistereduseroftheauctionsystem.

Thisclasscontainsprivatedatamemberstostorethefirstname,last

name,emailaddress,andpasswordoftheuser.

Theclassdeclarationincludesthefollowingpublicmembers.

●Defaultconstructor

Initializestheprivatedatamemberstodefaultvalues

●Fourparameterconstructor

Acceptsparameterstoinitializetheprivatedatamembers

●Copyconstructor

MakesacopyofaClientobject

●Accessorsandmutators

Provideaccesstotheprivatedatamembers

●virtualboolverifyPasswd(stringpasswd);

Returnstrueiftheinvokingobject'spasswordmatchesthe

passwordgivenintheparameter,falseifotherwise.

●operator>>

ThismethodreadsaClientobjectfromaninputstream.The

advertisementshouldbeinputthefollowingdatamembersofthe

classinthefollowingform.

firstname\nlastname\nemail\npassword\n

 

✧ClassGroup

ClassGroupmodelsacollectionofclients.

Thisclasscontainsaprivatedatamemberoftypevector.ThisvectorstorespointerstoClientobjects.AsinclassListing,thedeclarationofclassClientusesthekeywordtypedeftocreatealternatenamesfortypesvectorandvector:

:

iterator.Usethese

alternatenamesthroughouttheauctionproject.

●virtualvoidadd(Client*ptr);

AddstheClientpointergivenbytheparametertothevector

objects.

●virtualiteratorbegin();

ThisreturnsaniteratortothefirstClient*invectorobjects.

●virtualiteratorend();

ThisreturnsaniteratortothelastClient*invectorobjects.

●virtualClient*operator[](conststring&email);

ThisreturnstheClientpointerwhoseobject'semailequalsthe

parameteremail.

Followingisalistoffilesneededtocompletethisassessment.

∙handout-files1.zipcontainsallofthefollowingnecessaryfiles:

1Group.h-ThisfiledeclaresclassGroup.

2Client.h–ThefiledeclaresclassClient

Submission

Submitonlythefollowing.

1.Group.cpp

2.Client.cpp

综合实验2

Calculating"TheSumofItsParts"

 

Inthisassessment,youwillconstructarepresentationofacomplexstructure,ahospitalthatiscomposedofmanyparts.There

aretoomanypartsforahumantokeeptrackof,whichiswhywe

wantthecomputertodoitforus.Thedescriptionofthehospital

iscontainedinthefiledefinitions.txt.

Figure1Layoutofafloorinthehospital

 

Thebuildinghastenfloors.Eachfloorhasfourwingsemanating

fromacentralcore.

Eachwingcontainstwolongcorridorsjoinedattheendbyashort

connectingcorridor.

Eachlongcorridorcontainstwenty-onepatientrooms.Each

connectingcorridorcontainsfivesupplyrooms.

Thehospitalisdescribedbyalabeledtree,whosenodesareof

typePart.Anodecontainschildrennodescorrespondingtoits

subparts,asshowninthefigurebelow.Eachedgeislabeledby

thenumberofsubpartsthenodecontains.Forexample,thelabel

10ontheedgefromhospitaltofloorindicatesthatthehospital

hastenfloors.Youcanassumetherearenoduplicateedges,that

is,thereisatmostoneedgebetweenanytwonodes.

Figure2Treerepresentationofthehospital

Thedriverprogrammain.cppfirstloadsthefiledefinitions.txt,whichcontainsthesubpartrelationshipsthatdefinethehospital.Itthenprocessesqueriesfromthefilequeries.txt,whichcontainstwokindsofqueriesaboutthehospital.ThewhatisqueryrequeststhedescriptionofaPart.Thehowmanyqueryistheheartoftheexercise.ItaskshowmanyinstancesofaPartarecontainedinanotherPart.

Youareprovidedwithmain.cppandaskeletonversionofparts.hasastartingpoint.Yourjobistocompletetheparts.hfile(andwriteparts.cpp,ifyoudeemnecessary).Thestepsbelowpointthewaytowardasolution,buttheydonotcovereverydetail,soifyoufindyouneedtocreateadditionalfunctionsormemberitems,feelfreetodoso.

Files

Followingisalistoffilesneededtocompletethisassessment.

∙handout-files2.zipcontainsallofthefollowingnecessaryfiles:

3main.cpp-Testingprogramneededforyoutocheckyoursolution

4parts.h-Skeletonversionoftheheaderfile

5definitions.txt-Definitionofpartandsubpartrelationships

6queries.txt-Filecontainingqueriestotestyourimplementation.

Tasks

Tocompletethisassessment,youneedtocompletetheimplementationofclassPartandotherhelperfunctions.

Tobegin,verifythefilesneededforthisassessment.

Extractthearchivetoretrievethefilesneededtocompletethisassessment.

Followingisanorderedlistofstepsthatservesasaguidetocompletingthisassessment.Workandtestincrementally.Saveoften.

1.BeginbyaddingtoclassPartanadditionalmembernamedsubpartsthatisacontaineroftypemap.Yourcontainershouldmapapointer(oftypePart)toaninteger.So,forexampl

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

当前位置:首页 > 高等教育 > 院校资料

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

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