Programming MethodologyLecture06.docx

上传人:b****8 文档编号:28517415 上传时间:2023-07-18 格式:DOCX 页数:26 大小:34.18KB
下载 相关 举报
Programming MethodologyLecture06.docx_第1页
第1页 / 共26页
Programming MethodologyLecture06.docx_第2页
第2页 / 共26页
Programming MethodologyLecture06.docx_第3页
第3页 / 共26页
Programming MethodologyLecture06.docx_第4页
第4页 / 共26页
Programming MethodologyLecture06.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

Programming MethodologyLecture06.docx

《Programming MethodologyLecture06.docx》由会员分享,可在线阅读,更多相关《Programming MethodologyLecture06.docx(26页珍藏版)》请在冰豆网上搜索。

Programming MethodologyLecture06.docx

ProgrammingMethodologyLecture06

ProgrammingMethodology-Lecture06

Instructor(MehranSahami):

Allrighty,welcomeback.Ifyouhaven抰turnedintheassignmentyetandyou,atsomepointwantto,turnitintothatboxupthere.

Soacouplequickannouncementsbeforewestart.Firstofwhich,firstofwhichisthequarterisalready1/5ofthewayover,right?

Aftertodayit抯liketwoweeksoftenweekareover,sothat抯hardtobelieve.

Butthere抯threehandoutsinthebackincludingyournextassignmentbecausethefunneverstops;whenoneassignment抯duethenextassignmentgoesout,andacoupleotherhandouts.Assignmentone,asyouknow,isduetodaysopleasedropitoffintheboxinfrontand,congratulations,you抣lall?

well,assumingyoudidn抰takealatedayyou抮eallprogrammers,right?

Becausehopefullyyoualldid,Karel,yougothimtorunaroundtheworldanddostuff.Hopefullyfiguredoutsomeinterestingoutrhythmsandnowyoucanturnitin.Question?

Student:

Ididn抰knowifyouneededahardcopy[inaudible].

Instructor(MehranSahami):

Unhuh,youwanttogetahardcopyinassoonasyoucan,likerightafterclass.Buthardcopiesareimportantbecausewewantyoutoturninbothbecauseweusetheelectricsubmissiontobeabletoactuallyrunitandyoursectionleadermakescommentsonthehardcopyandsoit抯importanttohaveboth.

Butjustbecauseyouasked?

Allrighty.SoIwanttotakeaquickpainpolebeforewestart.Solet抯actuallydiveintotherealsortofmeaningfulthings.Whatthepainpolereallyis?

rememberIaskedyoutothinkabouthowmuchtimeitactuallytookyoutodotheassignment?

SototalitupoveralltheKarelproblems;howmanytotalhours;thinkaboutit,ittookyoutoactuallydotheassignment.Right?

Andwe抮ejustgoingtogothroughanddoaquickshowofhands.

Howmanypeopleactuallygotthroughtheassignmentinzerototwohours?

Allright.Maybelikeacouplepeople.I抣lmakeasmallbar.Howabouttwotofour?

Afairnumber.Fourtosix?

That抯goodtosee.Sixtoeight;eighttoten;tento12;12to14;14to16;16plus?

Rockon.Thanksforadmittingit.It抯agoodtime.Hopefullyitwasagoodtime.

Butthat抯?

firstofall,onethingtonoteistheworldissurprisinglynormal.Right?

Likeeverythingintheworldisjustnormallydistributed,that抯justthewayitis.

Thesecondthingisthatcomputerprogramming,rightorsoftwareengineeringisaprettyhighvarianceevent,rightthatyoucangofromlessthantwohoursto16plus.Idon抰jokewhenIsayit抯actuallyveryhighvariance.Buthopefullywhatthisgiveyouisagain,whatweshootfor,right,isabouttenhoursperweekoutsideofclassfor,youknow,work.WeshootforhereandasImentioned,youknow,itlookslikeyou抮ealldoingrealwellbecauseyou抮esortofbelowtheaveragepoint.Thetruthofthematteriskindofasthequartergoeson,theassignmentstendtogetalittlebitharderwhichmeansyou抣lactuallyseethiscurvekindofmovedownalittlebitmoreintothatrange.Thisisgoodtimestoactuallyseeithererightnow.

Italsohopefullygivesyouachancetogageforyourselfhowyou抮edoingsortofrelativetoexpectations.Right?

Ifyou抮esortofdoingreal?

youknow,hopefullyyouputinyourcommentsanditwasgoodsoftwareengineeringandeverythingandI抦totallywillingtobelieveitwasandyoujustwroteyourcodeanditjustallworkedanditwasbeautifuland,sortof,ifyou抮edoneinthisend,aslongasyou抮estillfeelinglikeyou抮eunderstandingtheconceptsandyou抮epluggingaway,that抯importantandjustkeeppluggingandyouwilldojustfine,trustme.

TherehavebeentimeswhenIhavebeendownheremyselfanditwasn抰funwhenIwasthere,butyoujustkeeppluggingawayanditworksout.

Andbuttheimportantthingisifyouweresortofinaparticularrange,evenifyou抮einthisrangeandthingsjustworkedbutyoudidn抰understandwhy,that抯moredangerousthanbeinginthisrangeandunderstandingwhybecausealltheconceptsinthisclasswillbuildontopofeachother.Somakesureyouunderstandtheconceptsnotjustthat,ohKarelhappenedtodotherightthing.Yes,hegottotherightspotinthemiddleoftheworld,butnowhe抯justspinningaround.That抯fineifhe抯justspinningaround,hejustgotthatmiddlespot,right.We抮ekindofalock,likeyoujustthrowinenoughinstructionsuntilIkindofdidtherightthing;that抯notrealgoodunderstandingandyouwanttotalktome,talktoyoursectionleader,talktotheTAtotrytoclearthatup.

Allright,sowiththatsaidwe抮ejustgoingtodiveinbecausethere抯aquestionintheback.

Student:

Isitanhonorableviolationifyoulookatsomeoneelse抯codeonceyoualreadybothhandedyouassignmentsinandgottenitback?

Instructor(MehranSahami):

Onceyou抳egottenitbackandit抯alreadygraded,it抯finetoactuallybeabletolookatsomeoneelse抯codebecauseatthatpointyoucanjustkindof,youknow,shareideas.

Allright,anyotherquestions?

Allrighty,soacouplethingstocoverrealquickly.Lasttimewetalkedallaboutmethodsandsomemoreaboutobjects.There抯twothingsyoushouldknowintheprogramsthatyou抮egoingtobedoing,iswetalkedalittlebitaboutoneofthemlasttimeintermsofhowtogetinputfromtheuser.There抮ethesefunctionsthatyoushouldknowabout.

OneiscalledREADINTandthere抯somepromptinsidedoublequotesthatyougiveandwhatthatdoesisasktheuserbasicallyforanintegerandgivesyoubacksomevaluethatyoucansay,assigntoaninteger.There抯alsoaversionofthistogetdoubles,whichsurprisinglyenoughiscalledREDOUBLEandhasexactlysortofthesameproperties.Soit抯calledREDOUBLE;ithassomestringhereasit抯parameterorsometexthereinitsparameterinsidedoublequoteswhichitdisplaystothescreenandthengetsyoubackavaluewhichisadoubleoneyoucanassigntoadouble.Thosearejusttwothingsoffthebatthatyoushouldknowaboutbecausethat抯howyou抮egoingtogetinput,atleastforthetimebeing,fromtheuserinalotofcases.

Now,onethingyouwanttodoonceyouactuallygetsomeinputfromtheuseris,youwanttodosomemanipulationonitlikesomeexpressionsthatwetalkedaboutlasttime.Wetalkedaboutsomeofthedifferentoperatorslikeaddition,subtractionorunaryminus,it抯thesamesymbol,multiplication,divisionandmyfavorite,theremainder.Andsowetalkedaboutallthoseexceptforthislittleguylasttime.Alloftheoperatorskindofworkthewayyouwouldexpectthemto,okay.Andwe抣ltalkalittlebitmoreaboutdivisioninjustasecond.Theinterestingthingaboutdivision?

soallofthesethingsworkwithboth?

orIshouldsay?

alloftheseworkwithbothintegersanddoubles.Theremainder,aswetalkedabout,onlyworkswithintegers,rightbecauseitdoesn抰makesensetohavearemainderwhenyouhaverealvalues.

Thesethreeguysworkexactlythesameforintegersanddouble,justthewayyouwouldexpectaddition,multiplication,allthathappystuff,towork.Divisionkindofrearsitsuglyheadbecauseitactuallyworksslightlydifferentlyifyou抮edoingdivisionforintegersversusdoubles.Okay?

Thewholepointofthatis,ifyou抮edoingadivisionandthetwoargumentsthatyou抮edividing,rightifbothofthesethingsareintegers;inthiscaseIhaveintegerconstantwhichiswhatImean,thevalues,right.Ifbothoftheseintegers,whatitdoesisintegerdivisionwhichmeansitdoesthedivisionandthrowsawayanyremainder.Sowhatyougetbackisaninteger.So5dividedby2whentheseareintegersgivesyoubacktheValue2.Thatlittleremainderthingisjustgone.Ifyouwanttogettheremainderyouusethisguy.Okay?

Ifeitheroneoftheseparticularvalueshappenstobearealvalue,likeadouble,thenitwilldoreal-valuedivisionandgiveyoubackarealvalue.Soifyouhappentodivide5,evenif5isaninteger,bytheValue2.0andsoitknowsit抯arealvaluebecauseit抯gotadecimalpointinit,thiswillgiveyouback2.5asadoubleandsoyoucanassignthattoadouble.Okay?

Soifeitheroneoftheargumentsisadouble,yougetreal-valuedivision;ifthey抮ebothintegers,yougetbacktheintegerportion.Unhuh?

Student:

I抦alittleconfusedaboutthedouble;thedoubleisjustarealnumber?

Instructor(MehranSahami):

It抯justarealnumber.Yes.

Soanotherthingthatkindofcomesupwhenyoudoexpressions?

yeah,sometimesyou抮etakingnotesandyoujustdon抰know;it抯likecandyrainingfromthesky.

Theotherthingtokeepinmindisjustlikearithmetic,sometimesyouwantoperatorstoevaluateindifferentorder.There抯anorderprecedentforhowthesethingsactuallyevaluateincaseyouhavetohavesomebighonkingexpression.Theorderofprecedentisyoucanhaveparentheses.Parenthesesarethehighestprecedent.Thatmeansyouevaluateeverythinginparenthesesfirst,thenmultiplication,divisionandtheremainderoperatorhavethesamelevelofprecedents.Andsoifyouhavemultipleofthem;they抮eevaluatedfromlefttorightandthenadditionandsubtraction.Again,ifyouhavemultiple,evaluatelefttoright.

Soit抯justlikeregularrulesofprecedentinalgebra,whichhopefullyyou抮efamiliarwith,buttomakethatconcretelet抯sayyouhavesomeintegerXandwesayXequals1plus3times5dividedby2.Howdoesthatactuallyevaluate?

Wellfirstofall,wesaydowehaveanyparens?

Nowedon抰haveanyparens.Thatwouldbethehighestlevelofprecedence.Youcanalwaysforcesomethingtoevaluatemorehighlybyputtingitinparens.Sotheseguysareallatthesamelevel,soweevaluatelefttoright.Sowecomeacrossandwesayhere,here抯multiplication,weevaluatethisthing

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 广告传媒

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1