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
Pia云商家在前面有介绍过一次,根据市面上的信息是2018的开办的国人商家,原名叫哔哔云,目前整合到了魔方云平台。这个云服务商家主要销售云服务器VPS主机业务和服务,云服务器采用KVM虚拟架构 。目前涉及的机房有美国洛杉矶、中国香港和深圳地区。洛杉矶为crea机房,三网回程CN2 GIA,自带20G防御。中国香港机房的线路也是CN2直连大陆,比较适合建站或者有游戏业务需求的用户群。在这篇文章中,简...
RackNerd 商家我们应该是比较熟悉的商家,速度一般,但是人家便宜且可选机房也是比较多的,较多集中在美国机房。包括前面的新年元旦促销的时候有提供年付10美元左右的方案,实际上RackNerd商家的营销策略也是如此,每逢节日都有活动,配置简单变化,价格基本差不多,所以我们网友看到没有必要囤货,有需要就选择。RackNerd 商家这次2022农历新年也是有几款年付套餐。低至RackNerd VPS...
近日华纳云发布了最新的618返场优惠活动,主要针对旗下的免备案香港云服务器、香港独立服务器、香港高防御服务器等产品,月付6折优惠起,高防御服务器可提供20G DDOS防御,采用E5处理器V4CPU性能,10Mbps独享CN2 GIA高速优质带宽,有需要免备案香港服务器、香港云服务器、香港独立服务器、香港高防御服务器、香港物理服务器的朋友可以尝试一下。华纳云好不好?华纳云怎么样?华纳云服务器怎么样?...
beginning为你推荐
上海fastreport2漏洞chromeexcursionsios5主机route补丁安装前必读支持ipad支持ipad南京医科大学合同管理系统columnios5iphone连不上wifi苹果手机“无法加入网络”怎么办
webhostingpad debian6 tk域名 qq数据库 1g内存 中国电信宽带测速网 银盘服务是什么 超级服务器 带宽租赁 smtp服务器地址 国内域名 东莞服务器托管 金主 广东服务器托管 镇江高防服务器 phpinfo 美国主机 godaddy域名 建站行业 linux命令vi 更多