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

Virmach:1核/512M1核M1核512M/夏季美国vps促销,年付$7.2,9月更换AMD平台

virmach怎么样?virmach家这几年非常火,从商家的黑五闪购开始,以超低的价格吸引了大批的国人客户,而且商家的机器还是非常稳定的,站长手里的4.75刀年付已经用了两年了,非常稳定,不过商家到国内的线路一般,目前商家新上了夏季优惠促销,价格低到发指,年付7.2美元起,商家反馈将在9月开始更换AMD+NVMe平台,这个消息从年初就有了,不过一直没有更换,目前这个时间也不确定是否准确。点击进入:...

速云:深圳独立服务器,新品上线,深港mpls免费体验,多重活动!

速云怎么样?速云是一家国人商家。速云商家主要提供广州移动、深圳移动、广州茂名联通、香港HKT等VDS和独立服务器。目前,速云推出深圳独服优惠活动,机房为深圳移动机房,购买深圳服务器可享受5折优惠,目前独立服务器还支持申请免费试用,需要提交工单开通免费体验试用,次月可享受永久8折优惠,也是需工单申请哦!点击进入:速云官方网站地址活动期限至 2021年7月22日速云云服务器优惠活动:活动1:新购首月可...

创梦网络-新上雅安电信200G防护值内死扛,无视CC攻击,E5 32核高配/32G内存/1TB SSD/100Mbps独享物理机,原价1299,年未上新促销6折,仅779.4/月,续费同价

创梦网络怎么样,创梦网络公司位于四川省达州市,属于四川本地企业,资质齐全,IDC/ISP均有,从创梦网络这边租的服务器均可以****,属于一手资源,高防机柜、大带宽、高防IP业务,另外创梦网络近期还会上线四川眉山联通、广东优化线路高防机柜,CN2专线相关业务。广东电信大带宽近期可以预约机柜了,成都优化线路,机柜租用、服务器云服务器租用,适合建站做游戏,不须要在套CDN,全国访问快,直连省骨干,大网...

beginning为你推荐
支持ipad责任编辑:纪春联通版iphone4s怎样看苹果4S是联通版还是电信版联通版iphone4s怎么区分iphone4s电信版和联通版google中国地图求教谷歌中国地图~手机如何使用?联通iphone4联通iphone4跟苹果的iphone4有什么不一样? 比如少了什么功能? 还是什么的?迅雷下载速度迅雷限制下载速度要设置多少迅雷雷鸟100+怒放手机是迅雷做的么?迅雷之前不是出了一款雷鸟手机么?ipad无法加入网络为什么我的ipad加入网络没法用杀毒软件免费下载2013排行榜杀毒软件排行榜2015有哪些?
花生壳域名 主机域名 免费linux主机 万网域名管理 西安电信测速 bluehost 42u标准机柜尺寸 patcha 北京主机 卡巴斯基永久免费版 福建天翼加速 新天域互联 东莞数据中心 shopex主机 创建邮箱 四川电信商城 河南移动梦网 dnspod 云服务器比较 免费网络 更多