




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
全國(guó)計(jì)算機(jī)等級(jí)考試網(wǎng)上報(bào)名系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)全國(guó)計(jì)算機(jī)等級(jí)考試網(wǎng)上報(bào)名系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)進(jìn)度安排1、已完成的工作安排:第1周確定畢業(yè)設(shè)計(jì)題目。第2周下達(dá)任務(wù)書;查閱、收集有關(guān)文獻(xiàn)資料。第3~4周撰寫并上交開題報(bào)告。2、待完成的工作安排:第5~8周根據(jù)安排進(jìn)行畢業(yè)實(shí)習(xí)及課題調(diào)研。第5周進(jìn)行系統(tǒng)需求分析和方案論證。第6周進(jìn)行系統(tǒng)總體設(shè)計(jì)。第7~8周進(jìn)行系統(tǒng)詳細(xì)設(shè)計(jì)。第9~11周進(jìn)行程序設(shè)計(jì)。第12~13周進(jìn)行系統(tǒng)測(cè)試;完成畢業(yè)論文的初稿。第14周系統(tǒng)驗(yàn)收;對(duì)畢業(yè)論文進(jìn)行修改并定稿;準(zhǔn)備論文答辯。六、主要參考文獻(xiàn)[1]鄧良松,陸麗娜.軟件工程.西安電子科技大學(xué)出版社,2001[2]王佑中,著,Web動(dòng)態(tài)技術(shù)入門,北京:機(jī)械工業(yè)出版社,2003[3]劉衛(wèi)宏.SQLServer2000實(shí)用教程.科學(xué)出版社,2003[4]劉廷等著.ASP.NET開發(fā)實(shí)例完剖析[M],北京:中國(guó)電力出版社[5]薩師煊,王珊.數(shù)據(jù)庫(kù)系統(tǒng)概論.高等教育出版社,2006[6]李閩溟,吳繼剛,周學(xué)明.WEB網(wǎng)站開發(fā)實(shí)例導(dǎo)航.人民郵電出版社,2003[7]王穎.敦促新理論的研究.哈爾濱工業(yè)大學(xué)碩士論文,1992[8]張小艷著.基于B/S模式的網(wǎng)上考試系統(tǒng)[J],工礦自動(dòng)化,2002年,04期第26-28頁(yè)[9]賈振華著.淺談網(wǎng)上考試系統(tǒng)中自動(dòng)抽題的實(shí)現(xiàn)[J],大眾科技,2003年,04期第106-107頁(yè)[10]李翠梅.SQLServer中數(shù)據(jù)完整性之表間關(guān)系[J].科技與經(jīng)濟(jì).2006年第24期107-108頁(yè)[11]張斌黃獻(xiàn)波.基于ASP.NET的用戶權(quán)限設(shè)計(jì)與實(shí)現(xiàn)[J].光盤技術(shù).2006年第3期28-30頁(yè)[12]宋陽(yáng).ASP.NET的網(wǎng)站科研成果管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn).長(zhǎng)春師范學(xué)院學(xué)報(bào)(自然科學(xué)版[J].第25卷第6期2006年12月53-55頁(yè)[13]夏陽(yáng)張強(qiáng)陳小林.基于ASP.NET的電子商務(wù)網(wǎng)站開發(fā)與設(shè)計(jì)[J].計(jì)算機(jī)工程與設(shè)計(jì).第25卷第11期2027-2029頁(yè)[14]王洪濤,劉文娛.深入剖析WEB編程技術(shù)及應(yīng)用實(shí)例.人民郵電出版社,2004[15]GrantPalmer著.康博譯.C#程序員參考手冊(cè)[M].清華大學(xué)出版社.2002年9月第1版.2002年9月第1次印刷[16]StevenMandel.MicrosoftSQLServer2005StoredProcedureProgramminginT-SQLand.NET[J].NetDeveloper'sJournalVol.5.No.5p.222007[17]J.R.McDnonell,D.Wagen.EvolvingRecurrentPercepptionsTimeModeling.IEEETrans.onNeuralNetwoks.1994[18]PeterVarhol.TheFutureofASP.NETHingesonWeb2.0[J].VisualStudioMagazineVol.17.No.1p.402007專業(yè)譯文原文:C#PrimerApracticalApproachChapter4.InterfaceInheritanceAninterfacespecifiesasetofabstractmethodsandproperties.Likeanabstractbaseclass,aninterfaceismadeconcretebyeachofitsderivedclasses.Unlikeanabstractbaseclass,aninterfacecannotprovideadefaultimplementationordefinestate,suchasaninstancedatamemberorconstant.Anabstractbaseclassprovidesacommoninterfaceforafamilyofrelatedtypes.Incomputergraphics,forexample,Lightmayserveasanabstractbaseclassforafamilyoflights.Usersarelikelytomanipulatethelightsinasceneindependentlyoftheactualtype—turningthemonoroff,repositioningthem,changingtheircolorandintensity,andsoon.ThedeliveryofaLighthierarchyincludestheabstractbaseclassandseveralcommonderivedinstances,suchasclassesrepresentingaspotlight,adirectionallight,andapointlight(thinkofthesun).Wecaneithermakeuseoftheseprebuiltinstancesorderiveanewinstance(s).Forexample,intheDisneyfilmDinosaurweintroducedaclasstorepresentabarn-doorlight.Aninterface,ontheotherhand,providesacommonserviceorcharacteristicforotherwiseunrelatedtypes.Forexample,anytypewishingtobethetargetoftheforeachstatementmustimplementtheIEnumerableinterface.Forexample,theArrayList,BindingManager,DataView,andBitArrayclassesareallderivedfromtheIEnumerableinterface,butotherwisetheyhavelittleincommon.Byconvention,interfacesunder.NETbeginwithacapitalIfollowedbyamnemonicidentifierwithacapitalizedfirstletter.ThisisacarryoverfromCOM-basedprogramming,whichhasinterfacessuchasIUnknownorIDirectDraw.Unlikeclasses,whichsupportsingleinheritanceonly,interfacessupportmultipleinheritance.TheSystem.Stringclass,forexample,isderivedfromfourinterfacesprovidedwithintheSystemnamespace:publicsealedclassString:IComparable,ICloneable,IConvertible,IEnumerable{...}AsC#programmers,wehavethreedifferentexperiencesofinterfaces:(1)asusersofconcreteinstancesofeithertheSystemoruser-introducedinterfaces,(2)asprovidersofanewclassimplementationofeithertheSystemoruser-introducedinterfaces,(3)asprovidersofanewinterfaceclass.Welookateachofthesethreeaspectsinthischapter.4.1ImplementingaSystemInterface:IComparableLet'sstartbyimplementingourownclassinstanceofapredefinedinterfacewithintheSystemnamespace.Themotivationalcontextisthefollowing:WeneedtosortanArrayListofstringsinascendingorderbythelengthofthestring.OK.Thatsoundssimpleenough.Sohowarewegoingtodothat?IfwelookatthepublicmethodsofArrayList,weseethatitprovidesanoverloadedpairofSort()memberfunctions:System.Collections.ArrayListSort:Overloaded.SortstheelementsintheArrayList,oraportionofit.Let'slookatthedocumentationforthetwodifferentmethodsandseewhichone,ifeither,fitsthebill.Here'stheonewithanemptyparameterlist:publicvirtualvoidSort()SortstheelementsintheentireArrayListusingtheIComparableimplementationofeachelement.JustbyitsnameweknowthatIComparableisaninterface.TheelementheldbyourArrayListisastring.TheStringclassimplementstheIComparableinterface.Theno-parameterSort()methodoftheArrayListusestheIComparableimplementationoftheStringclasstodeterminetheorderingoftwostringobjects.Thisimposesadictionaryorderonthewords—notanorderingbylength.Thisinstance,then,isnotofusetous.Okay.Maybethenextoverloadedinstanceisuseful:publicvirtualvoidSort(ICompareric)SortstheelementsintheentireArrayListusingthespecialcompareric.ThisinstanceprovidesuswithawaytooverridethedefaultorderingalgorithmassociatedwiththeStringclass.We'llcreateaspecialimplementationoftheIComparerinterfacethatsortsthestringsbylength.(Ifweweredefiningaclass,wewouldincludeanimplementationoftheIComparableinterfaceifwewantedtosupportsortingwithintheArrayListcontainer.)Howdowedothat?WhataretheIComparermethods,andwhatdotheydo?Notonlydowehavetoprovideadefinitionofeveryinterfacemember,butwemustimplementthedocumentedbehaviorofeachmemberifwewantourimplementationtotransparentlymeldwiththeotherimplementationsofthatinterface.Inaddition,weneedtothrowthesameexceptionsunderthesameabnormalconditions.Thecompilercannotenforcethis.Recognizingandthrowingtheexceptionsareresponsibilitiesoftheinterfaceimplementation.Itturnsoutthereisonlyonemethodtoimplement.Phew!Notonlythat,buttheimplementationseemsdoable:intCompare(objectx,objecty);Comparestwoobjectsandreturnsavalueindicatingwhetheroneislessthan(negativenumber),equalto(zero),orgreaterthan(positivenumber)theother.Whataboutanyexceptionsthemethodcanthrow?Againwehavetolookatthedocumentation.Asitturnsout,thereisjustone,anditalsoseemsdoable:ArgumentExceptionNeitherxnoryimplementstheIComparableinterface.-or-xandyareofdifferenttypesandneitheronecanhandlecomparisonswiththeother.ThismeansthatourimplementationoftheIComparerinterfacerequiresonlyonemethod:Compare().ItshouldthrowanArgumentExceptionifoneorbothofthetwoargumentsareinvalid;inourcase,thatsimplymeansthatthetwoargumentsarenotbothstrings.Let'scalltheclassStringLengthComparer:publicsealedclassStringLengthComparer:IComparer{//firstobligation:theCompare()methodpublicintCompare(objectx,objecty){...}}OurCompare()instancemustdefinetwoparametersoftypeobject,eventhoughourimplementationisinterestedinonlytwoparametersofthestringtype.ThisisnecessarybecauseCompare()isimplicitlyavirtualfunction(asareallinterfacememberfunctions),andthereforethesignatureoftheoverridinginstancemustexactlymatchthesignatureoftheinheritedmethod.Thisissomethingofaninconvenience.ItmeanswehavetocheckwithinCompare()thattheargumentsarebothoftypestring.Ifwewereabletoexplicitlydeclarethemastypestring,thecompilerwouldenforcethattyperequirementautomatically.We'llseehowtogetaroundthat—atleastpartially—inSection4.4.TheonlythingleftnowistheimplementationofCompare().Wecanbreakthatdownintotwoprimarysteps.Firstwemustconfirmthevalidityofthetwoarguments.Thatdone,wemustcomparethelengths.Wehavetwoparametersoftypeobject,andwemustconfirmthattheyarereallyinstancesoftypestring.Onestrategyistousetheisoperator:if((!(xisstring))||(!(yisstring)))thrownewArgumentException("somediremessage");//OK:argumentsarevalid;//let'scastthemtostringobjectsstringxs=(string)x;stringys=(string)y;Alternatively,wecanallowtheasoperatortodothedowncasting.Wethrowanexceptionifeitherxsorysissettonull:stringxs=xasstring;stringys=yasstring;if(xs==null||ys==null)thrownewArgumentException("somediremessage");That'sreallytheonlytrickypart.Hereisthelengthcomparison:intret_val=1;if(xs.Length<ys.Length)ret_val=-1;elseif(xs.Length==ys.Length)ret_val=0;returnret_val;Sowe'veimplementedourfirstconcreteinstanceofaninterfaceclass.HereishowwemightinvokeSort():ArrayListstringList=newArrayList();//fillitupstringList.Sort(newStringLengthComparer());4.2AccessinganExistingInterfaceInthissectionweimplementagenericbinarytreethatholdsnodevaluesofanytype.Asyouknowbynow,thewaywedothatinC#istodeclarethenodetobeoftypeobject.Asanadditionalwrinkle,anodevalueisinsertedonlyoncewithinatree.Ifitoccursanothertime,weincrementanoccurrencecount.ThisgivesusthechancetolookattheIComparableinterface.ThenodeclassiscalledTreeNode:publicsealedclassTreeNode{privateintm_occurs;privateobjectm_nval;privateTreeNodem_lchild,m_rchild;//...}Forourtreewe'llimplementseveralpoliciesthatprovideopportunitiesforexercisingsomeoftheinterfacesdefinedwithinthe.NETframework.Forexample,wewanttofixthetypeofthetreeafterinsertingthefirstelement.ThetreeclassiscalledBinaryTree:publicclassBinaryTree{publicdelegatevoidAction(refTreeNodenode);privateTypem_elemType;privateTreeNodem_root;privateActionm_nodeAction;//...}WhentheusercreatesaBinaryTreeobject,wewantittobeabletoholdavalueofanytype.Wesupportthatcapabilitybyusingthetypeobject.Oncetheuserinsertsavalue,however,wewantalltheremainingvaluesinsertedinthattreetobeofthesametype.Theinsertionofafirstvaluelocksthetypeofthattree.Forexample,hereishowourtreemustbehave.Whenwecreateanewtree,itcanholdobjectsofanytype.Oncewehaveinsertedanelement,however,thetreecanstoreonlyotherelementsofthattype.Forexample,whenwewriteBinaryTreebt=newBinaryTree();btcanpotentiallystoreelementsofanytype.However,oncewewritebt.insert("Piglet");btbecomesabinarytreethatholdselementsoftypestring.Subsequentinsertionsofstringelements,suchasbt.insert("Eeyore");bt.insert("Roo");arefine.EachelementisinsertedwithinthetreeaccordingtotheorderingsupportedbytheIComparableinterface.Whatwewanttopreventisasubsequentattemptbytheuser,afterhavinginsertedanobjectofonetype,toinsertanobjectofadifferenttype.Forexample,iftheuserwritesbt.insert(1024);wewanttorecognizeandflagthatthetypebeinginsertedisdifferentfromthetypetowhichwe'vepreviouslyboundourtree.Todothis,we'llthrowanexception.We'llmakenofurtherconstraintsonobjectsinorderforthemtobeacceptedastreenodevalues.OnlytypesthatimplementtheIComparableinterfaceareaccepted.Why?Becauseeachelementispassedtousthroughtheobjectparameter,sowehavelostallcompile-timetypeinformation.Theinterfaceprovidesanorderingservicethatistypeindependent—forexample,privateIComparableconfirm_comparable(objectelem){IComparableic=elemasIComparable;if(ic==null){stringmsg="ElementtypemustsupportIComparable--"+elem.GetType().Name+"doesnotcurrentlydoso!";thrownewArgumentException(msg);}returnic;}Hereishowwemightinvokeconfirm_comparable():publicvoidinsert(objectelem){//ifthisisthefirstelementif(m_root==null){confirm_comparable(elem);m_elemType=elem.GetType();m_root=newTreeNode(elem);}else{confirm_type(elem);m_root.insert_value(elem);}}insert()checkstheelement'ssuitabilityonlywiththefirstinsertionofanobjectofthattype.Subsequently,itsimplyconfirmsthatthenewobjectisofthesametypeastheinitialobject.Ifitis,weinserttheelementwithinthetree,asshownhere:publicvoidinsert_value(objectval){//assumptionisthatBinaryTreehasconfirmedthis...IComparableic=valasIComparable;//OK:zeromeansthetwoobjectsareequalif(ic.CompareTo(m_nval)==0){m_occurs++;return;}//OK:lessthan;insertwithinleftsubtreeif(ic.CompareTo(m_nval)<0){if(m_lchild==null)m_lchild=newTreeNode(val);elsem_lchild.insert_value(val);}else{//insertwithinrightsubtreeif(m_rchild==null)m_rchild=newBTreeNode(val);elsem_rchild.insert_value(val);}}Whenwemanipulateanobject'sactualtype,wecanprettymuchignorewhateverinterfacesthattypeimplements.Whenwemanipulateanentityoftypeobject,however,thediscoveryanduseofaninterfacebecomescriticalbecauseallcompiletimetypeinformationislost.(Alternatively,wecanquerytheobjectatruntimeastoitsactualtype.WelookattypereflectioninSection8.2.)4.3DefininganInterfaceInSection4.1weimplementedanewinstanceofanexistinginterface.InSection4.2wesimplydiscoveredandusedtheinterfaceassociatedwithagiventype.Inthissectionweintroduceaninterfacedefinition.Thisinterfacesupportsthegenerationanddisplayofsequencesofnumbersbasedonauniquealgorithm.Hereisthegeneralsetofoperationswewishtosupport(twomethods,aproperty,andanindexer):*GenerateSequence(),whichgeneratestheuniquesequenceofelements*Display(),whichoutputstheelements*Length,whichreturnsacountofthenumberofelements*Indexer,whichallowstheusertoaccessaspecificelementAninterfacedefinitionbeginswiththekeywordinterfacefollowedbyaname.Recallthatin.NET,interfacesbyconventionbeginwithacapitalI.Thenamefollows,beginningwithacapitalletter,althoughthisconventionisnotenforcedbythecompiler.We'llcallourinterfaceINumericSequence:publicinterfaceINumericSequence{}Yes,itislegaltodefineanemptyinterface,sothisrepresentsacompleteinterfacedefinition.Themembersthataninterfaceispermittedtodefineareasubsetofthosepermittedforaclass.Aninterfacecandeclareonlymethods,properties,indexers,andeventsasmembers—forexample,publicinterfaceINumericSequence{//amethodboolgenerate_sequence(intposition);//asetofoverloadedmethodsvoiddisplay();voiddisplay(intfirst);voiddisplay(intfirst,intlast);//apropertyintLength{get;}//aone-dimensionalindexerintthis[intposition]{get;}}Allmembersofaninterfaceareimplicitlyabstract.Wecannotprovideadefaultimplementation,howevertrivial.Inaddition,themembersoftheinterfaceareimplicitlypublic.Wecannotmodifyamemberwitheithertheabstractorthepublickeyword.Aninterfacecannotdefineinstancedatamembers.Norcanitdefineeitheraconstructororadestructor.(Withoutstatemembers,neitherisrequired.)Inaddition,aninterfacecannotdeclarestaticmembers.Becauseaconstmemberisimplicitlystatic,constmembersarenotallowed,andneitherareoperatorsnor,notsurprisingly,astaticconstructor.Aninterfacecaninheritfromanotherinterface:publicinterfaceINumericSequence:ICollection{...}orfrommultipleinterfaces:publicinterfaceINumericSequence:ICollection,ICloneable{...}butaninterfacecannotexplicitlyinheritfromaclassorstruct.Allinterfaces,however,implicitlyinheritfromtherootObjectclass.4.3.1ImplementingOurInterface:ProofofConceptOncewehavedefinedourinterface,howcanwetellifitisanygood?Typically,inadditiontodefiningtheinterface,wedeliveratleastoneimplementation—asakindofproofofconceptorsanitychecktoconfirmtheviabilityoftheinterface.Let'sprovideaFibonacciimplementationtotestourinterface.ThefirsttwoelementsoftheFibonaccisequenceareboth1.Addingthetwopreviouselementsgenerateseachsubsequentelement.Forexample,thefirsteightFibonaccielementsare1,1,2,3,5,8,13,21.Sowhatdowedofirst?Aninterfaceisimplementedbyeitherclassorstructinheritance.Astructisn'tappropriateinthiscase:Wedon'texpecttobecreatingandmanipulatinglotsofFibonacciobjectsintime-criticalportionsoftheapplication.We'lldeclareFibonacciasaclassthen.Becausewedonotexpectittobesubsequentlyderivedfrom,we'lldeclareittobesealedaswell:publicsealedclassFibonacci:INumericSequence{}Thisemptydefinition,however,isillegal.Aclassinheritingfromaninterfacemustprovideanimplementationofeveryinterfacemember.Leavingoutevenonememberresultsinacompile-timeerror.(Theexceptionisanycaseinwhichtheclassimplementingtheinterfaceisabstract.Itcanthendeclareoneormoreoftheinterfacememberfunctionsabstract.ThisisillustratedinSection4.5.)Beforewecanimplementtheinterfacemembers,wemustdeterminethestateinformationnecessarytosupportthesequenceabstraction.Inthiscasewe'llneedanarraytoholdthesequenceelements,andtwoadditionalmemberstoholdthesizeandcapacityofthearray.Becausetheelementsofthesequenceareinvariant,weneedonlyasinglearray.We'lldeclarethearrayanditstwosupportingmembersasstatic.Theimplementationofaninterfacehastwomainelements:(1)providingtheunderlyinginfrastructure,ifany,tosupporttheabstraction,and(2)providingadefinitionforeachmemberoftheinterface,includingthemembersofallinheritedbaseinterfaces.HereistheskeletonofaFibonacciclassdesign:publicsealedclassFibonacci:INumericSequence{//infrastructuretosupportsequenceabstractionprivatestaticint[]m_elements;privatestaticshortm_count;privatestaticshortm_capacity=128;//Fibonacci-specificmethods://allforinfrastructuresupportsstaticFibonacci(){...}privatevoidcheck_pos(intpos){...}privatevoidgrow_capacity(){...}//INumericSequenceinheritedmemberspublicboolgenerate_sequence(intpos){...}publicvoiddisplay(){...}publicvoiddisplay(intfirst){...}publicvoiddisplay(intfirst,intlast){...}publicintLength{get{returnm_count;}}publicintthis[intposition]{...}}Theindexerhastoverifythevalidityoftheposition,ofcourse.I'vefactoredthatverificationintoaprivatememberfunction,check_pos().Ifthepositionisinvalid,anexceptionisthrown.Otherwisetheindexerreturnstheelement,decrementingthepositionbyone:publicintthis[intposition]{get{check_pos(position);returnm_elements[position-1];}}BecausearrayindexinginC#iszerobased—thatis,thefirstelementisretrievedwithanindexof0—wemustadjustthepositionspecifiedbytheuser.Whynotrequiretheusertomakethatadjustmentexplicitly?Whetherthat'sagooddecisionornotdependsontheperceivedsophisticationofourusers.Iftheyareothersoftwaredevelopers,requiringtheindextobezerobasedmightwellmakesense.Nonprogrammers,however,oftenfindthenotionofafirstelementbeingatpositionzeroveryunnatural.Byencapsulatingtheadjustmentwithintheclass,weshouldertheburdenandmakeusingourcodesaferandmorepleasantforourusers.Hereishowwemightexerciseourimplementation.FirstweprogramaninstancedirectlyasaFibonacciclassobject.NextweprogramitindirectlyasagenericINumericSequenceobject:publicstaticvoidMain(){//justsomemagicnumbers–usedaspositionsconstintpos1=8,pos2=47;//let'sdirectlyuseinterfacethroughclassobjectFibonaccifib=newFibonacci();//invokesindexer;//indexerinvokesgenerate_sequence(pos1);intelem=fib[pos1];intlength=fib.Length;stringmsg="ThelengthoftheINumericSequenceis";Console.WriteLine(msg+length.ToString());Console.WriteLine("Element{0}oftheFibonacciSequenceis{1}",pos1,elem);fib.display();//OK:let'snowuseinterfacegenericallyINumericSequenceins=fib;elem=ins[pos2];length=ins.Length;Console.WriteLine(msg+length.ToString());Console.WriteLine("Element{1}oftheFibonacciSequenceis{0}",elem,pos2);ins.display(44,47);}Asitturnsout,ourimplementationissomewhatflawed.(That'sthepointoftestingit.)Theproblemisself-evidentintheprogram'soutput:ThelengthoftheINumericSequenceis8Element8oftheFibonacciSequenceis21Elements1to8oftheFibonacciSequence:1123581321ThelengthoftheINumericSequenceis47Element47oftheFibonacciSequenceis-1323752223Elements44to47oftheFibonacciSequence:70140873311349031701836311903-1323752223What'sgoingonhere?Theprogramclaimsthattheforty-seventhelementoftheFibonaccisequenceis-1323752223.That'sreallynotright.Ifwelookatthedisplayofelements44through47,whathashappenedisprettyclear:Elements44to47oftheFibonacciSequence:70140873311349031701836311903-1323752223Wehavedeclaredm_elementstoholdelementsoftypeint.Unfortunatelytheforty-seventhFibonaccielementistoolargetobecontainedwithinanint.Thevalueoverflowedintothesignbit,sothevalueisincorrectlydisplayedasnegative.TobetterhandlelargeFibonaccivalues,weneedtoredefinem_elementsasatypeabletoholdlargervalues.Whattypeisthemostappropriate?Inadditiontotheintegraltypes,therearetwofloating-pointtypes(thesingle-precisionfloatandthedouble-precisiondouble)andthe28-digits-of-precisiondecimaltype.Let'sredeclarem_elementstobe,inturn,auint,aulong,adecimal,andadouble.Atposition50,onlytheulong,decimal,anddoubleareleftstanding:FibonacciElement#50:(int):-298632863FibonacciElement#50:(uint):3996334433FibonacciElement#50:(ulong):12586269025FibonacciElement#50:(decimal):12586269025FibonacciElement#50:(double):12586269025Atposition100,onlythedecimalanddoublearecapableofrepresentingthevalue.However,thedoublebeginstoloseprecisionbyrounding,whichisunacceptable.Onlythedecimalvaluesdonotroundoff.OurbestchoiceforrepresentingtheelementsoftheFibonaccisequenceisthusthedecimaltype:FibonacciElement#100:(ulong):37367171FibonacciElement#100:(decimal):354224848179261915075FibonacciElement#100:(double):3.54224848179262E20Still,however,thisisnotacompletesolution.Thedecimaltypereachesits28-digitlimitatposition139:FibonacciElement#139:(decimal):5583911FibonacciElement#139:(double):5.58406E28Whenweattempttocalculateposition140,thedecimalobjectoverflowsandthefollowingexceptionoccurs:System.OverflowException:ValueiseithertoolargeortoosmallforaDecimal.atSystem.Decimal.Add(System.Decimal,System.Decimal)atSystem.Decimal.op_Addition(System.Decimal,System.Decimal)atProject1.Fibonacci.version_decimal(Int32)atProject1.MainObj.Main()Wecanstoreanddisplayonlythefirst139FibonaccielementsusingthepredefinedC#arithmetictypes.Unlessweplantoimplementourownnumericclasssupportingverylargeintegralvalues,we'llneedtodefinealimittotheelementpositionausercanrequest.Becausethisholdstrueforanynumericsequence,weshouldaddthatlimitdefinitiontotheINumericSequenceinterface,asfollows:publicinterfaceINumericSequence{//thetwonewpropertiesintLength{get;}intMaxPosition{get;}//...restthesame...}publicsealedclassFibonacci:INumericSequence{//infrastructuretosupportsequenceabstractionprivatestaticint[]m_elements=newint[m_maxpos];privatestaticshortm_count;privateconstshortm_maxpos=128;publicintMaxPosition{get{returnm_maxpos;}}//...restthesame,exceptnolongerneedtogrowarray}ThismeansthatthereisaninfinitesetofFibonaccielementpositionsthatarelegitimatebutthatwecan'teasilysupportand,infact,havechosennottosupport.Inaddition,theusermightspecifyaninvalidposition—anyvaluelessthanorequaltozero.Howshouldwehandlethesetwoinvalidconditions?TheconventioninbothC#and.NETprogrammingistoreportallprogramanomaliesthroughtheraisingofanexception.Butwhichexceptionshoulditthrow?Shoulditthrowseparateexceptionsforaninvalidpositionandanunsupportedposition?Thereisnosinglerightanswer.Whoshoulddecide?Ifeachinterfaceimplementationisallowedtodecidewhetherandwhatexceptionstothrow,ifany,itbecomesnearlyimpossibletosafelyprogramtheinterfacegenerically.Forexample,towritethefollowingcodesequence:INumericSequenceins=oasINumericSequence;if(ins!=null)elem=ins[pos2];wemustknowthateveryimplementationoftheindexerreportsaninvalidpositioninexactlythesameway.Thismeansthattheinterfacedefinitionmustdecideunderwhatconditionsanexceptionmustbethrownandwhattheexceptionshouldbe.Unfortunately,wecandothatonlythroughdocumentation.ThereisnowaywithinC#todirectlyassociateamemberwithoneorasetofexceptionsitmaythrow.中文翻譯:4、接口繼承接口詳細(xì)說明了一組抽象的methods和properties。和abstractbaseclass一樣,接口依靠derivedclass將它塑造為具體實(shí)物而非抽象接口。和abstractbaseclass不同的是,接口不能提供缺省實(shí)現(xiàn)或是定義任何“狀態(tài)”,例如定義實(shí)體數(shù)據(jù)成員或常量。Abstractbaseclass為一整族相關(guān)型別提供了公共的接口。例如在計(jì)算機(jī)圖形學(xué)中,light可能作為一族發(fā)光體的abstractbaseclass,用戶可能在一組場(chǎng)景中以“與實(shí)際型別無關(guān)”的方式來操縱這些發(fā)光體,包括開啟或熄滅、調(diào)換位置、改變顏色和亮度、如此等等。整個(gè)Light體系包含abstractbaseclass、數(shù)個(gè)derivedclass也許代表聚光燈、定向燈、點(diǎn)光源(如太陽(yáng)等等)。我們可以利用這些預(yù)先建立好的classes?;驈闹性倥缮龅男碌腸l
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 手繪金魚國(guó)畫與西瓜主題藝術(shù)課件
- 數(shù)學(xué)高段課標(biāo)及教學(xué)培訓(xùn)
- 地震逃生和基本救護(hù)知識(shí)
- 護(hù)理查房病歷匯報(bào)
- 電工電子技術(shù) 課件 7. 三相交流異步電動(dòng)機(jī)電路的連接與測(cè)試
- 辦公室智慧管理方案
- 統(tǒng)編版2024~2025學(xué)年度六年級(jí)語(yǔ)文第二學(xué)期期中模擬卷(有答案)
- 教育功能唐智松
- 第一單元評(píng)估檢測(cè)題( A 卷)單元測(cè)試(無答案)三年級(jí)下冊(cè)數(shù)學(xué)西師大版
- 建筑工程風(fēng)險(xiǎn)管理案例分析
- 中醫(yī)五臟心完整版本
- 郵政集團(tuán)社招柜員筆試題
- 第9課 古代的商路、貿(mào)易與文化交流 -2023-2024學(xué)年高二歷史同步教學(xué)課件(選必3文化交流與傳播)
- 船舶機(jī)艙自動(dòng)化4.4 主機(jī)遙控系統(tǒng)的轉(zhuǎn)速與負(fù)荷控制
- Mini-CEX的測(cè)評(píng)內(nèi)容人文關(guān)懷
- 家政保潔培訓(xùn)課件教學(xué)
- 醫(yī)學(xué)生創(chuàng)新創(chuàng)業(yè)課件概述
- 《秤的發(fā)展史》課件
- 醫(yī)院感染科護(hù)士對(duì)防控感染的終末消毒與徹底清潔
- 酒店飯店服務(wù)流程
- 英語(yǔ)八年級(jí)英語(yǔ)上冊(cè)閱讀理解100及答案經(jīng)典
評(píng)論
0/150
提交評(píng)論