addressbeginning

beginning  时间:2021-05-17  阅读:()
BeginningCforEngineersFall2005Instructor:BettinaSchimanskiTAs:GabeMulley&JoelDeverWebsite:www.
cs.
rpi.
edu/~schimb/beginC2005Lecture1–Section2(8/31/05)Section4(9/1/05)OverviewCourseGoalsIntroductionUnixandtheHistoryofCFirstCProgramDataTypesandexpressionsI/OCourseGoalsIntroducegeneralconceptsofprogrammingBegintothinklikeaprogrammerStartprogramminginCWhyisthisimportantTounderstandbasiccomputerconceptsToappreciatestructuredprogrammingWillserveasabasisforanyfutureprogrammingyoudoNeededfortheLaboratoryIntroductiontoEmbeddedControl(LITEC)course–ENGR2350WhatisprogrammingGivenawell-definedproblem:FindanalgorithmtosolveaproblemExpressthatalgorithminawaythatthecomputercanexecuteitAnalgorithmisasequenceofinstructionstosolveaproblemsuchthat:EachinstructionisunambiguousandissomethingthecomputercandoAfteraninstructionisfinishedthereisnoambiguityaboutwhichinstructionistobeexecutednextExecutionfinishesinafinitenumberofstepsThedescriptionofthealgorithmisfiniteCProgrammingLanguageEvolvedfromBCPL(1967)andB(1969)ByDennisRitchieatBellLabsBythelate1970sitwaswidelyusedStandardizedin1989intheUSthroughtheAmericanNationalStandardsInstitute(ANSI)andworldwidethroughInternationalStandardsOrganization(ISO)C++isasupersetofCCStandardLibraryCprogramsconsistofmanyfunctionsCStandardLibrary-collectionofexistingfunctionsProgramminginCisacombinationof:CreatingyourownfunctionsUsingCStandardLibraryfunctionsCPortabilityCishardware-independentApplicationsinCcanrunwithlittleornomodificationsonawiderangeofcomputersystemsUseANSIstandardlibraryfunctionsinsteadofyourownequivalentRAM(memory)I/ODevicesCentralProcessingUnit(CPU)SecondaryStorageRegistersComputerArchitectureofaComputerI/OdevicesInputOutputCPUALUMainMemorySecondaryStorageI/ODevicesCommunicationswiththeoutsideworldInputdevices:keyboardmousejoystickscannermicrophoneOutputdevices:screenprintercomputerspeakersnetworksRAM(memory)I/ODevicesCentralProcessingUnit(CPU)SecondaryStorageRegistersComputer"Administrative"sectionofthecomputer–supervisesoperations:controlsI/OandALUHas2componentstoexecuteprograminstructionsArithmetic/LogicUnitperformsarithmeticoperations,andmakeslogicalcomparisonsControlUnitcontrolstheorderinwhichyourprograminstructionsareexecutedUsesoneormoreregistersasscratchspaceforstoringnumbersbetweeninstructionsAtypicalCPUtodaycanexecutemillionsofarithmeticoperationsinasecondRAM(memory)I/ODevicesCentralProcessingUnit(CPU)SecondaryStorageRegistersComputerCentralProcessingUnit(CPU)RAM(memory)I/ODevicesCentralProcessingUnit(CPU)SecondaryStorageRegistersComputerCentralProcessingUnit(CPU)RAM(memory)I/ODevicesCentralProcessingUnit(CPU)SecondaryStorageRegistersComputerCentralProcessingUnit(CPU)ManycomputersnowhavemultipleCPUs(multiprocessors)andcanthereforeperformmanyoperationsatatimeMainMemorySometimescalledrandomaccessmemory(RAM).
Storesthenumbers(data)thataprogramuseswhenitrunsonthecomputer.
Containsmillionsofcircuitswhichareeitherofforon(0or1)BinaryAlsostorestheinstructionsoftheprogramthatisrunningonthecomputer.
Dividedintofixedsizeunitsofmemorycalledwords.
eachwordstoresonenumbereachwordhasitsownaddressRAM(memory)I/ODevicesCentralProcessingUnit(CPU)SecondaryStorageRegistersComputerDataProgramInstructionsMainMemoryRAM(memory)I/ODevicesCentralProcessingUnit(CPU)SecondaryStorageRegistersComputerDataProgramInstructionsSecondaryStoragePermanentstorageusedtosavedataandprogramswhentheyarenotrunningonthecomputer.
Dataandprogramsareorganizedintovaryingsizeunitscalledfiles.
Filesareorganizedintodirectoriesthatcancontainsubdirectories.
SecondarystorageischeaperperMegabytethanmainmemory,butaccesstodataismuchslowerRAM(memory)I/ODevicesCentralProcessingUnit(CPU)SecondaryStorageRegistersComputerSecondaryStorageRAM(memory)I/ODevicesCentralProcessingUnit(CPU)SecondaryStorageRegistersComputerTheProgrammingProcessUseaneditor(suchasEmacs,Notepad,Vi,etc.
)tocreateaprogramfile(sourcefile)containsthetextoftheprogramwritteninsomeprogramminglanguage(likeC)UseapreprocessortoincludethecontentsofotherfilesUseacompilertoconvertthesourcefileintoamachinecodefile(objectfile)convertfrom"English"tobinarywithmachineoperationsUsealinkertoconverttheobjectfileintoanexecutablefile.
includeothermachinecodethattheprogramrequiresRuntheexecutablefileCreatingaCProgramACprogramisasetoffunctionsthatcollectivelysolveagivenproblem.
eachfunctionisasequenceofCstatements(instructions)executionalwaysbeginswithafunctionnamed"main"onefunctioncallsanotherfunctiontogetittoexecuteitsstatementsTheCstatementsinafunctionareexecutedoneaftertheotherinsequentialorderaswritten.
EachCstatementisendedbyasemi-colon.
FirstCProgramAnythingbetween/*and*/isacommentintendedtoimprovethereadabilityoftheprogram.
#includeisusedtotellthecompilerandlinkerwhatlibraryresourcestheprogramuses.
thelibrarydefineseverythingyouneedtodisplaymessagesonthescreenThisprogramcontainsonefunctionnamed"main".
Noticewheresemi-colonsareplaced.
Theprogramoutputs(printstothescreen)thewordsHello,World!
/*BettinaSchimanskiHelloWorldProgramprog01a.
cAugust31,2005*/#includeintmain(){printf("Hello,World!
\n");return0;}DisplayingMessagesOnTheScreen:UsingprintfTodisplayamessageonthecomputerscreenusetheprintfstatement.
Thebackslash"\"indicatesanescapesequence.
Thismeanstakethealternatemeaningofwhateverimmediatelyfollowsit.
\nmeanstostartanewline\tisatab\"isaquote\aisanaudiblealert(bell)Textstringsmustalwaysbesurroundedbydoublequotes.
printf("Hello,World\n");MoreExamplesprintf("Hello\nWorld!
\n");printf("\tFirstpartoflongmessage.
");printf("Secondpartoflongmessage.
\n");printf("\"Hello\"World!
"\n");HelloWorld!
Firstpartoflongmessage.
Secondpartoflongmessage.
"Hello"World!
"DefiningaCFunctionACfunctionhasthefollowingform:Thenameofthisfunctionis"main".
Theword"int"meansthatthisfunctionreturnsanintegernumber.
using0toindicatethattheprogramrancorrectly.
thisiswhatthereturnstatementdoesattheendofthefunctionThebracesdefinethebeginningandtheendofthefunction.
Thefirstlineofthefunctioniscalledthefunctionheader.
intmainsequenceofstatementsseparatedbysemicolonsreturn0;}FirstLab!
Gotohttp://www.
cs.
rpi.
edu/~schimb/beginC2005ClickonLectures&LabsandgotoLab1DojustPart1StandardDataTypesinCAdatatypetellswhattypeofdataisstoredinagivenmemorylocation.
StandardCdatatypesarebrokenintothefollowingtypes:IntegralTypesrepresentwholenumbersandtheirnegativesdeclaredasint,short,orlongFloatingTypesrepresentrealnumberswithadecimalpointdeclaredasfloat,ordoubleCharacterTypesrepresentsinglecharactersdeclaredascharCVariablesVariablesinCstoredatainmemorysothatthedatacanbeaccessedthroughouttheexecutionofaprogramAvariablestoresdatacorrespondingtoaspecifictype.
EachvariablethataCprogramusesmustbedeclaredatthebeginningofthefunctionbeforeitcanbeused.
specifythetypeofthevariablenumerictypes:intshortlongfloatdoublecharactertype:charspecifyanameforthevariableanypreviouslyunusedCidentifiercanbeused(withsomemoreexceptionsdiscussedlater)intx;floatsum,product;WhatDoesaVariableDeclarationDoAdeclarationtellsthecompilertoallocateenoughmemorytoholdavalueofthisdatatype,andtoassociatetheidentifierwiththislocation.
intapartmentNumber;floattax_rate_Y2K;charmiddleInitial;4bytesfortaxRateY2K1byteformiddleInitialVariableandfunctionNamesInCSomereservedwordsinC:breakcasecharconstcontinuedefaultdodoubleelseenumfloatforgotoifintlongreturnshortsignedstaticstructswitchtypedefunionunsignedvoidwhileVariablesandfunctionnamesinCarecalledidentifiers.
identifiersareusedformanyotherthingsaswellRulesforconstructingvalididentifiersinC:cancontainletters(upperandlowercase),digits,andtheunderscore(_)charactercannotstartwithadigitcannotbeareservedwordcanbeatmost256characterslong,thoughsomecompilersonlylookatfirst32charactersarecasesensitiveIdentifiersVALIDapartment_numbertax_rate_Y2KPrintHeadingageOfHorse_NOTVALID(Why)apartment#2000TaxRateAge-Of-Catdayofweek**UsingmeaningfulvariablenamesisagoodprogrammingpracticeGivingaValuetoaVariableYoucanassign(give)avaluetoavariablebyusingtheassignmentoperator=VARIABLEDECLARATIONScharmiddleInitial;charletter;intapartmentNumber;VALIDASSIGNMENTSTATEMENTSmiddleInitial='K';letter=middleInitial;apartmentNumber=8;AssignmentStatementAnassignmentstatementisusedtoputavalueintoavariable.
ThepreviousvalueisreplacedSyntax:=;isanydeclaredvariableintheprogramisanythingthatproducesavalueoftheappropriatetype(moreonthislater)first,theexpressiononrightisevaluated.
thentheresultingvalueisstoredinthememorylocationofvariableonleft.
Examples:count=10;count=count+1;area=3.
14*radius*radius;NOTE:AnautomatictypecoercionoccursafterevaluationbutbeforethevalueisstoredifthetypesdifferforexpressionandvariableExamplesArithmeticExpressionsWithIntegers(int,long)Operators:resultisalwaysanintegerSymbolNameExampleValue(x=10,y=3)+additionx+y13–subtractionx–y7*multiplicationx*y30/quotientx/y3%remainderx%y1–unaryminus–x-10+unaryplus+x10ArithmeticExpressionsContinued…Youcanstringtheoperatorstogethertobuildlongerexpressions.
useparenthesestospecifyorderofoperationsprecedence(aftersub-expressionsinparentheses):first:unaryplusandminusfromrighttoleftsecond:*and/and%fromlefttorightthird:+and–fromlefttorightArithmeticExpressionExampleinty=2;intz;z=-y*3*(4+5)%10+--3;-2*3*9%10+--3-2*3*9%10+3-6*9%10+3-54%10+3-4+3-1ArithmeticExpressionsWithReals(float,double)Arithmeticexpressionswithrealnumbers(numberswithdecimalpoints)workthesamewayaswithintegers,withafewexceptions:thereisnoremainderoperator("%")the"/"operatormeans"divide"(vsquotient),computingtheanswertomanydecimalplacestheresultisarealvalueratherthananintegervalueImportant:Realvaluesareapproximateandmaycontainerrorsinthelastfewdigits.
about7digitsofaccuracyfortypefloatabout14digitsofaccuracyfortypedoubleMixedModeArithmeticExpressionsArithmeticexpressions:bothintegersandfloatscangettricky.
ifbothoperandsareintegers,integerarithmeticisusedifeitheroperandisafloat,floatarithmeticisusedanintegeroperandisconvertedtofloatfortheoperationExamples:inta,x;x=3.
59;/*xgetsthevalue3(norounding)*/floaty=3;/*ygetsthevalue3.
0*/a=12;/*agetsthevalue12*/floatavg=(a+x)/2;/*avggetsthevalue7.
0…UHOH!
!
!
*/PrintingvariablesandconstantstothescreenwithprintfUsethefollowingconversionspecifications:%dforaninteger%ldforalonginteger%cforacharacter%fforafloat%fforadoubleExample:Output:intsum=5;floatavg=12.
2;charch='A';printf("Thesumis%d\n",sum);Thesumis5printf("avg=%f"\n",avg);avg=12.
2prinf("ch=%c\n",ch);ch=Aprintf("%d,%f,%c\n",sum,avg,ch);5,12.
2,Aprintf("%d\n",5);5Note:seep.
153inyourtextbookforacompletelistofalldatatypesReadingdatafromthekeyboardwithscanfUsedtoassignavaluetypedonthekeyboardtoavariable.
Usedsimilarlytoprintf.
Youmustusethefollowingconversionspecifications:DataTypeprintfconverstionspec.
scanfconversionspec.
int%d%dlong%ld%ldfloat%f%fdouble%f%lfchar%c%ccharacterstring%s%sTheusermusttypeavaluefollowedbytheEnterKey.
Ex:scanf("%d",&num);Example:ProgramtofindtheaverageoftwonumbersNotethatyoucandeclaremorethanonevariableperline.
Wedivideby2.
0insteadof2sothattherighthandsideisafloat(i.
e.
notruncationtakesplace)scanfisusedsimilarlytoprintf,exceptthatyouneedtoputanampersand(&)beforethevariablenameThefirstargumentofthescanffunctionistheconversionspecifier(s)inquotes,thenthevariablename(s)#includeintmain(){intnum1,num2;floatavg;/*gettwoinputs*/printf("Enterthefirstinteger:");scanf("%d",&num1);printf("Enterthesecondinteger:");scanf("%d",&num2);/*computeandprinttheavg*/avg=(num1+num2)/2.
0;printf("Theaverageis%f\n",avg);return0;}FinishLab1Gotohttp://www.
cs.
rpi.
edu/~schimb/beginC2005ClickonLectures&LabsandgotoLab1DoPart2HomeworkReadChapters1,2and9Dueatthebeginningofnextclass:HW1AcademicIntegrityStatementFYI:InfoonCygwin,Putty,SecureCRT,andEmacsareonthewebsite

宝塔面板企业版和专业版618年中活动 永久授权仅1888元+

我们一般的站长或者企业服务器配置WEB环境会用到免费版本的宝塔面板。但是如果我们需要较多的付费插件扩展,或者是有需要企业功能应用的,短期来说我们可能选择按件按月付费的比较好,但是如果我们长期使用的话,有些网友认为选择宝塔面板企业版或者专业版是比较划算的。这样在年中大促618的时候,我们也可以看到宝塔面板也有发布促销活动。企业版年付899元,专业版永久授权1888元起步。对于有需要的网友来说,还是值...

DiyVM:2G内存/50G硬盘/元起线路香港vps带宽CN2线路,香港VPS五折月付50元起

DiyVM是一家低调国人VPS主机商,成立于2009年,提供的产品包括VPS主机和独立服务器租用等,数据中心包括香港沙田、美国洛杉矶、日本大阪等,VPS主机基于XEN架构,均为国内直连线路,主机支持异地备份与自定义镜像,可提供内网IP。最近,商家对香港机房VPS提供5折优惠码,最低2GB内存起优惠后仅需50元/月。下面就以香港机房为例,分享几款VPS主机配置信息。CPU:2cores内存:2GB硬...

Virmach 3.23美元可用6个月的VPS主机

Virmach 商家算是比较久且一直在低价便宜VPS方案中玩的不亦乐乎的商家,有很多同时期的商家纷纷关闭转让,也有的转型到中高端用户。而前一段时间也有分享过一次Virmach商家推出所谓的一次性便宜VPS主机,比如很低的价格半年时间,时间到服务器也就关闭。这不今天又看到商家有提供这样的产品。这次的活动产品包括圣何塞和水牛城两个机房,为期六个月,一次性付费用完将会取消,就这么特别的产品,适合短期玩玩...

beginning为你推荐
浙江世纪华通集团股份有限公司支持ipadexportingjavaoutput_buffering飞飞的官方网站是啥重庆网通重庆网通上网资费目前是多少? 小区宽带接入类型的css3圆角怎样用css实现圆角矩形?win7telnetWin7系统中的telnet命令如何应用?联通iphone4iphone4想换联通的卡 是普通联通的卡都能开通3G么 还是得换联通3G卡 联通都有什么套餐 我是北京的csshack什么是Css Hack?ie6,7,8的hack分别是什么ipad上不了网平板电脑 能连接网络不能上网
域名查询 免费国外空间 东莞服务器租用 深圳主机租用 北京vps raksmart l5639 php主机 wdcp 华为云主机 国内php空间 e蜗牛 好看qq空间 促正网秒杀 我爱水煮鱼 数字域名 架设服务器 合租空间 1g空间 空间登入 更多