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

10gbiz($2.36/月),香港/洛杉矶CN2 GIA线路VPS,香港/日本独立服务器

10gbiz发布了9月优惠方案,针对VPS、独立服务器、站群服务器、高防服务器等均提供了一系列优惠方面,其中香港/洛杉矶CN2 GIA线路VPS主机4折优惠继续,优惠后最低每月仅2.36美元起;日本/香港独立服务器提供特价款首月1.5折27.43美元起;站群/G口服务器首月半价,高防服务器永久8.5折等。这是一家成立于2020年的主机商,提供包括独立服务器租用和VPS主机等产品,数据中心包括美国洛...

咖啡主机22元/月起,美国洛杉矶弹性轻量云主机仅13元/月起,高防云20G防御仅18元/月

咖啡主机怎么样?咖啡主机是一家国人主机销售商,成立于2016年8月,之前云服务器网已经多次分享过他家的云服务器产品了,商家主要销售香港、洛杉矶等地的VPS产品,Cera机房 三网直连去程 回程CUVIP优化 本产品并非原生地区本土IP,线路方面都有CN2直连国内,机器比较稳定。咖啡主机目前推出美国洛杉矶弹性轻量云主机仅13元/月起,高防云20G防御仅18元/月;香港弹性云服务器,香港HKBN CN...

柚子互联(34元),湖北十堰高防, 香港 1核1G 5M

柚子互联官网商家介绍柚子互联(www.19vps.cn)本次给大家带来了盛夏促销活动,本次推出的活动是湖北十堰高防产品,这次老板也人狠话不多丢了一个6.5折优惠券而且还是续费同价,稳撸。喜欢的朋友可以看看下面的活动详情介绍,自从站长这么久以来柚子互联从19年开始算是老商家了。六五折优惠码:6kfUGl07活动截止时间:2021年9月30日客服QQ:207781983本次仅推荐部分套餐,更多套餐可进...

beginning为你推荐
上海工程技术大学present37Singlesb支持ipad支持ipad支持ipadeaccelerator开启eAccelerator内存优化就各种毛病,DZ到底用哪个内存优化比较好。。。css下拉菜单css下拉菜单代码fusionchartsFusionCharts连接数据库你是怎么解决的,能告诉我吗?谢谢啦联通版iphone4s联通版iPhone4s 用联通3G卡好还是移动的好
中国域名注册 便宜域名注册 广州服务器租用 万网域名解析 cpanel主机 私服服务器 轻博 腾讯云分析 服务器干什么用的 银盘服务 阿里dns 网站防护 脚本大全 蓝队云 第八届中美互联网论坛 塔式服务器 windowsserver2008r2 winserver2008r2 gotoassist 游戏服务器 更多