《程序设计导论sk演示教学.ppt》由会员分享,可在线阅读,更多相关《程序设计导论sk演示教学.ppt(48页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、程序设计导论sk2007ComputerHardwarenComputersareconstructedfromphysicalcomponentsreferredtoashardwarenHardwarefacilitatesthestorageandprocessingofdataunderthedirectionofafilesystemnComputerhardwaredoesnotstoredatausingthesamesymbolsthathumansdo2BitsandBytesnThesmallestandmostbasicdataiteminacomputerisabitO
2、penorclosedswitch0or1nThegroupingof8bitstoformalargerunitisreferredtoasabyteCanrepresentanyoneof256distinctpatternsnThecollectionsofpatternsconsistingof0sand1susedtorepresentletters,singledigits,andothersinglecharactersarecalledcharacter codescomputerhardware3Componentscomputerhardware4MainMemoryUni
3、t(RAM)nStoresdataandinstructionsassequenceofbytesnAprogrammustresideinmainmemoryifitistooperateonthecomputernCombines1ormorebytesintoasingleunit,referredtoasawordnConstructedasrandomaccessmemory,orRAMEverysectionofmemorycanbeaccessedrandomlyasquicklyasanyothersectionVolatile:dataislostwhenpoweristur
4、nedoffnSizeisusuallyspecifiedinbytes(MBorGB)computerhardware5CentralProcessingUnit(CPU)nControl unit:directsandmonitorstheoveralloperationofthecomputerKeepstrackofwherethenextinstructionresidesIssuesthesignalsneededtobothreaddatafromandwritedatatootherunitsinthesystemExecutesallinstructionsnArithmet
5、ic and Logic Unit(ALU):performsallofthecomputations,suchasaddition,subtraction,comparisons,andsoon,nCPUsareconstructedasasinglemicrochip,whichisreferredtoasamicroprocessorcomputerhardware6Input/OutputUnitnTheinput/output(I/O)unitprovidesaccesstothecomputer,allowingittoinputandoutputdatanItistheinter
6、facetowhichperipheral(外围的)devices,suchaskeyboards,consolescreens,andprinters,areattachedcomputerhardware7SecondaryStoragenUsedaspermanentstorageforprogramsanddataMagnetictape,magneticdisks,andCD-ROMsnDirect access storage device(DASD):allowsacomputertoreadorwriteanyonefileorprogramindependentofitspo
7、sitiononthestoragemediumMagnetic hard disk consistsofrigidplattersthatspintogetheronacommonspindleInitially,themostcommonmagneticdiskstoragedevicewastheremovablefloppy diskcomputerhardware8MagneticHardDisk扇区柱面道computerhardware9ProgrammingLanguagesnComputer program:dataandinstructionsusedtooperateaco
8、mputerandproduceaspecificresultAprogramorsetofprogramsiscalledsoftwarenProgramming:writinginstructionsinalanguagethatthecomputercanrespondtoandthatotherprogrammerscanunderstandnProgramming language:setofinstructionsthatcanbeusedtoconstructaprogram10MachineLanguagenExecutable program:programthatcanop
9、erateacomputernExecutableprogramsarewrittenwithbinarynumbers,whichisacomputersinternallanguage(machine language)Anexampleofasimplemachinelanguageprogramcontainingtwoinstructionsis:1100000000000000000100000000001011110000000000000010000000000011nOpcodeisshortforoperationcode;tellsthecomputertheoperat
10、iontobeperformedProgrammingLanguages11AssemblyLanguagenAssembly language:usesthesubstitutionofword-likesymbolsfortheopcodes,anddecimalnumbersandlabelsformemoryaddressesLOAD firstADD secondMUL factorSTORE answer load R1,R0load R2,new_number ADD R2,R1jmp addressProgrammingLanguages12AssemblyLanguage(c
11、ontinued)ProgrammingLanguages13Theleveloflanguages11000000,00000000,00010000,00000010opcodeMachinelanguageAssemblylanguageADDop1op2Languagespecificationrate=rate+1;Highlevellanguagecompileruseinstructionsthataredirectlytiedtoonetypeofcomputer.SourcecodeObjectcodeProgrammingLanguages14High-to-LowLeve
12、lLanguages(compile&link)ProgrammingLanguages15Datapipeline1+ratedep*R_step1depositrateoutputrateR_step1depositoutputR_step1registersControlunitWhatisaprogram(physically)nAsetofinstructionsthatcanmakethecomputerrunchronologically.rate=rate+1;result=rate*depositaprogram16Programisawhiteboxfordataproce
13、ssing(logically)aprogram17Codinganalgorithm:constructawhiteboxstepbystepAlgorithms18Algorithms(arithmeticprogression)Algorithms19AlgorithmsnAlgorithm:specificstepsrequiredtoproduceadesiredresultSet n equal to 100Set a equal to 1Set b equal to 100Calculate sum=n(a+b)/2Display the sumnWhenEnglishphras
14、esareusedtodescribeanalgorithm,thedescriptioniscalledpseudocodeInput the three numbers into the computerCalculate the average by adding the numbers and dividing the sum by threeDisplay the averageAlgorithms20AlgorithmsandflowchartAformulaorsetofstepsforsolvingaparticularproblem.Tobeanalgorithm,these
15、tofrulesmustbeunambiguousandhaveaclearstoppingpoint.Algorithmscanbeexpressedinanylanguage,fromnaturallanguageslikeEnglishorChinese.Algorithms21flowchartnAflowchartisanorganizedcombinationofshapes,lines,andtextthatgraphicallyillustratesaprocessorstructure.Algorithms22FlowchartSymbolsAlgorithms23Flowc
16、hartforcalculatingtheaverageofthreenumbersAlgorithms24structuredprogrammingnAtechniquefororganizingandcodingcomputerprograms:ahierarchyofmodulesisused,eachhavingasingleentryandasingleexitpoint,controlispasseddownwardthroughthestructurewithoutunconditionalbranchestohigherlevelsofthestructure.structur
17、edprogramming25Amodulemustacceptdata,processthedata,andproducearesultstructuredprogramming26StructuredprogrammingAwell-designedprogramisbuiltusingmodulesstructuredprogramming27First-levelstructurediagramstructuredprogramming28Second-levelrefinementstructurediagramstructuredprogramming29TheSoftwareDe
18、velopmentProcessPhaseI:SpecifytheprogramsrequirementsPhaseII:DesignanddevelopmentStep1:AnalyzetheproblemStep2:SelectanoverallsolutionalgorithmStep3:WritetheprogramStep4:TestandcorrecttheprogramPhaseIII:DocumentationPhaseIV:Maintenance30PhaseI:SpecifytheProgramsRequirementsnItisimpossibletoconstructa
19、successfulprogramforaproblemthatisnotfullyunderstood.SoftwareDevelopmentprocess31PhaseII:DesignandDevelopmentnStep1:Analyzetheproblem.Youmustunderstand:TheoutputsthatmustbeproducedTheinputdatarequiredtocreatethedesiredoutputsTheformulasrelatingtheinputstotheoutputsnStep2:Selectanoverallsolutionalgor
20、ithmSoftwareDevelopmentprocess32PhaseII:DesignandDevelopment(continued)SoftwareDevelopmentprocess33PhaseII:DesignandDevelopment(continued)nForlargerprogramsyouwillhavetorefinetheinitialalgorithmandorganizeitintosmalleralgorithms,withspecificationsforhowthesesmalleralgorithmswillinterfacewitheachothe
21、rFirst-level structure diagram foranalgorithmisthefirstattemptatastructureforasolutionalgorithmTop-down algorithm development startsatthetopmostlevelandproceedstodevelopmoreandmoredetailedalgorithmsasitproceedstothefinalsetofalgorithmsSoftwareDevelopmentprocess34PhaseII:DesignandDevelopment(continue
22、d)SoftwareDevelopmentprocess35PhaseII:DesignandDevelopment(continued)SoftwareDevelopmentprocess36PhaseII:DesignandDevelopment(continued)nThesooneryoustartprogramminganapplication,thelongeritusuallytakestodebugandcomplete.SoftwareDevelopmentprocess37PhaseII:DesignandDevelopment(continued)nStep3:Write
23、theprogram(orcodethealgorithm)Sequence structuredefinestheorderinwhichinstructionsareexecutedbytheprogramSelection structureprovidesthecapabilitytomakeachoicebetweendifferentinstructions,dependingontheresultofsomeconditionRepetition structure,alsocalledlooping oriteration,providestheabilityforthesam
24、eoperationtoberepeatedbasedonthevalueofaconditionInvocation SoftwareDevelopmentprocess38PhaseII:DesignandDevelopment(continued)nStep4:TestandcorrecttheprogramAprogramerroriscalledabugTestingattemptstoensurethataprogramworkscorrectlyandproducesmeaningfulresultsIfyoufindanerror,initiatedebugging:locat
25、ing,correcting,andverifyingthecorrectionDevelopasetoftestdatathatdetermineswhethertheprogramgivescorrectanswersThetestsshouldexamineeverypossiblesituationunderwhichaprogramwillbeusedSoftwareDevelopmentprocess3940PhaseIII:DocumentationnSixdocumentsforeveryproblemsolution:1.Therequirementsstatement2.A
26、descriptionofthealgorithmsthatwerecoded3.Commentswithinthecodeitself4.Adescriptionofmodificationandchangesmadeovertime5.Sampletestruns,whichincludetheinputsusedforeachrunandtheoutputobtainedfromtherun6.Ausersmanual,whichisadetailedexplanationofhowtousetheprogramSoftwareDevelopmentprocess41CaseStudy:
27、circumferenceofcirclenVoidmain()nStatements;compoundstatements;n/commentsSoftwareDevelopmentprocess42PhaseIV:MaintenancenHoweasilyaprogramcanbemaintained(corrected,modified,orenhanced)isrelatedtotheeasewithwhichtheprogramcanbereadandunderstoodSoftwareDevelopmentprocess43BackupnMakingandkeepingbackup
28、copiesofyourworkwhenwritingaprogramiscriticalNotpartoftheformalsoftwaredevelopmentprocessnBackupisunimportantifyoudontmindstartingalloveragainnManyorganizationskeepatleastonebackuponsitewhereitcanbeeasilyretrieved,andanotherbackupcopyeitherinafireproofsafeorataremotelocationSoftwareDevelopmentproces
29、s44WhatisaProgrammingLanguagefor(conclusion)nProgrammingisanexplanatoryactivityToyourself,nowandinthefuture.Towhoeverhastoreadyourcode.Tothecompiler,whichhastomakeitrun.nExplanationsrequirelanguageTostateclearlywhatisgoingon.Tocommunicateideasoverspaceandtime.45HowtomakeaniceprogramnAnalysistheproblemnCorrectalgorithmnNicestructurenCodingwithCommentsnDebuggingndocumentation46Theassignment:nFinishandhandinpersonalwebpage(10.8)nReadthematerialrecommendedinChapterone.Includetheexercises.47此课件下载可自行编辑修改,仅供参考!此课件下载可自行编辑修改,仅供参考!感谢您的支持,我们努力做得更好!谢谢感谢您的支持,我们努力做得更好!谢谢