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

CloudCone(12.95美元/月CN2 GT线路,KVM架构1 Gbps带宽

整理一下CloudCone商家之前推送的闪购VPS云服务器产品,数量有限,活动推出可能很快机器就售罄了,有需要美国便宜VPS云服务器的朋友可以关注一下。CloudCone怎么样?CloudCone服务器好不好?CloudCone值不值得购买?CloudCone是一家成立于2017年的美国服务器提供商,国外实力大厂,自己开发的主机系统面板,CloudCone主要销售美国洛杉矶云服务器产品,优势特点是...

3C云1核1G 9.9元 4核4G 16元 美国Cera 2核4G 24元

3C云互联怎么样?3C云互联专注免备案香港美国日本韩国台湾云主机vps服务器,美国高防CN2GIA,香港CN2GIA,顶级线路优化,高端品质售后无忧!致力于对互联网云计算科技深入研发与运营的极客共同搭建而成,将云计算与网络核心技术转化为最稳定,安全,高速以及极具性价比的云服务器等产品提供给用户!专注为个人开发者用户,中小型,大型企业用户提供一站式核心网络云端服务部署,促使用户云端部署化简为零,轻松...

JustHost:俄罗斯/新西伯利亚vps,512MB内存/5GB空间/不限流量/200Mbps/KVM/自由更换IP,$1.57/月

justhost怎么样?justhost是一家俄罗斯主机商,2006年成立,提供各种主机服务,vps基于kvm,有HDD和SSD硬盘两种,特色是200Mbps不限流量(之前是100Mbps,现在升级为200Mbps)。下面是HDD硬盘的KVM VPS,性价比最高,此外还有SSD硬盘的KVM VPS,价格略高。支持Paypal付款。国内建议选择新西伯利亚或者莫斯科DataLine。支持Paypal付...

beginning为你推荐
打印机morphvox计算机xp支持ipad支持ipad重庆网通重庆联通现在有哪些资费???win7关闭445端口如何快速关闭445端口tracerouteTRACEROUTE的作用是什么ipad如何上网如何用手机流量在IPAD上上网iphonewifi苹果wifi版和4G版是什么意思,有什么区别吗iphonewifi苹果手机怎么wi-fi共享
域名备案网站 本网站服务器在美国维护 腾讯云盘 漂亮qq空间 pccw Hello图床 免费ddos防火墙 网通服务器ip ibox官网 申请个人网站 100m独享 支付宝扫码领红包 电信托管 免费邮件服务器 空间登陆首页 带宽租赁 百度云加速 智能dns解析 德隆中文网 东莞主机托管 更多