62 Pages

chapter06

Course: COP 3275, Fall 2011
School: University of Florida
Rating:
 
 
 
 
 

Word Count: 3542

Document Preview

3275: COP Chapter 06 JonathanC.L.Liu,Ph.D. CISEDepartment UniversityofFlorida,USA Iteration Statements Csiterationstatementsareusedtosetup loops. Aloopisastatementwhosejobisto repeatedlyexecutesomeotherstatement (theloopbody). InC,everyloophasacontrolling expression. Eachtimetheloopbodyisexecuted(an iterationoftheloop),thecontrolling expressionisevaluated. Iftheexpressionistrue(hasavaluethatsnot...

Register Now

Unformatted Document Excerpt

Coursehero >> Florida >> University of Florida >> COP 3275

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
3275: COP Chapter 06 JonathanC.L.Liu,Ph.D. CISEDepartment UniversityofFlorida,USA Iteration Statements Csiterationstatementsareusedtosetup loops. Aloopisastatementwhosejobisto repeatedlyexecutesomeotherstatement (theloopbody). InC,everyloophasacontrolling expression. Eachtimetheloopbodyisexecuted(an iterationoftheloop),thecontrolling expressionisevaluated. Iftheexpressionistrue(hasavaluethatsnot zero)theloopcontinuestoexecute. 2 Iteration Statements Cprovidesthreeiterationstatements: Thewhilestatementisusedforloops whosecontrollingexpressionistested beforetheloopbodyisexecuted. Thedostatementisusediftheexpression istestedaftertheloopbodyisexecuted. Theforstatementisconvenientforloops thatincrementordecrementacounting variable. 3 The while Statement Usingawhilestatementistheeasiest waytosetupaloop. Thewhilestatementhastheform while ( expression ) statement expressionisthecontrollingexpression; statementistheloopbody. 4 The while Statement Exampleofawhilestatement: while (i < n) i = i * 2; /* controlling expression */ /* loop body */ Whenawhilestatementisexecuted,the controllingexpressionisevaluatedfirst. Ifitsvalueisnonzero(true),theloopbodyis executedandtheexpressionistestedagain. Theprocesscontinuesuntilthecontrolling expressioneventuallyhasthevaluezero. 5 The while Statement Awhilestatementthatcomputesthesmallest powerof2thatisgreaterthanorequaltoanumber n: i = 1; while (i < n) i = i * 2; Atraceoftheloopwhennhasthevalue10: i = 1; Isi<n? i=i* Isi<n? i=i* Isi<n? i=i* Isi<n? i=i* Isi<n? 2; 2; 2; 2; iisnow1. Yes;continue. iisnow2. Yes;continue. iisnow4. Yes;continue. iisnow8. Yes;continue. iisnow16. No;exitfromloop. 6 The while Statement Althoughtheloopbodymustbeasingle statement,thatsmerelyatechnicality. Ifmultiplestatementsareneeded,usebracesto createasinglecompoundstatement: while (i > 0) { printf("T minus %d and counting\n", i); i--; } Someprogrammersalwaysusebraces,even whentheyrenotstrictlynecessary: while (i < n) { i = i * 2; } 7 The while Statement Thefollowingstatementsdisplaya seriesofcountdownmessages: i = 10; while (i > 0) { printf("T minus %d and counting\n", i); i--; } ThefinalmessageprintedisTminus1 andcounting. 8 The while Statement Observationsaboutthewhilestatement: Thecontrollingexpressionisfalsewhenawhile loopterminates.Thus,whenaloopcontrolledbyi >0terminates,imustbelessthanorequalto0. Thebodyofawhileloopmaynotbeexecutedat all,becausethecontrollingexpressionistested beforethebodyisexecuted. Awhilestatementcanoftenbewrittenina varietyofways.Amoreconciseversionofthe countdownloop: while (i > 0) printf("T minus %d and counting\n", i--); 9 Infinite Loops Awhilestatementwontterminateifthe controllingexpressionalwayshasanonzero value. Cprogrammerssometimesdeliberatelycreate aninfiniteloopbyusinganonzeroconstantas thecontrollingexpression: while (1) Awhilestatementofthisformwillexecute foreverunlessitsbodycontainsastatementthat transferscontroloutoftheloop(break,goto, return)orcallsafunctionthatcausesthe programtoterminate. 10 Printing a Table of Squares Thesquare.cprogramusesawhile statementtoprintatableofsquares. Theuserspecifiesthenumberofentriesin thetable: This program prints a table of squares. Enter number of entries in table: 5 1 1 2 4 3 9 4 16 5 25 11 square.c /* Prints a table of squares using a while statement */ #include <stdio.h> int main(void) { int i, n; printf("This program prints a table of squares.\n"); printf("Enter number of entries in table: "); scanf("%d", &n); i = 1; while (i <= n) { printf("%10d%10d\n", i, i * i); i++; } return 0; } 12 Summing a Series of Numbers Thesum.cprogramsumsaseriesof integersenteredbytheuser: This program sums a series of integers. Enter integers (0 to terminate): 8 23 71 5 0 The sum is: 107 Theprogramwillneedaloopthatuses scanftoreadanumberandthenadds thenumbertoarunningtotal. 13 sum.c /* Sums a series of numbers */ #include <stdio.h> int main(void) { int n, sum = 0; printf("This program sums a series of integers.\n"); printf("Enter integers (0 to terminate): "); scanf("%d", &n); while (n != 0) { sum += n; scanf("%d", &n); } printf("The sum is: %d\n", sum); return 0; } 14 The do Statement Generalformofthedostatement: do statement while ( expression ) ; Whenadostatementisexecuted,the loopbodyisexecutedfirst,thenthe controllingexpressionisevaluated. Ifthevalueoftheexpressionis nonzero,theloopbodyisexecuted againandthentheexpressionis evaluatedoncemore. 15 The do Statement Thecountdownexamplerewrittenasado statement: i = 10; do { printf("T minus %d and counting\n", i); --i; } while (i > 0); Thedostatementisoftenindistinguishable fromthewhilestatement. Theonlydifferenceisthatthebodyofa do statementisalwaysexecutedatleastonce. 16 The do Statement Itsagoodideatousebracesinalldo statements,whetherornottheyre needed,becauseadostatement withoutbracescaneasilybemistaken forawhilestatement: do printf("T minus %d and counting\n", i--); while (i > 0); Acarelessreadermightthinkthatthe wordwhilewasthebeginningofa whilestatement. 17 Calculating the Number of Digits Thenumdigits.cprogramcalculatesthe numberofdigitsinanintegerenteredbythe user: Enter a nonnegative integer: 60 The number has 2 digit(s). Theprogramwilldividetheusersinputby10 repeatedlyuntilitbecomes0;thenumberof divisionsperformedisthenumberofdigits. Writingthisloopasadostatementisbetter thanusingawhilestatement,because everyintegereven0hasatleastonedigit. 18 numdigits.c /* Calculates the number of digits in an integer */ #include <stdio.h> int main(void) { int digits = 0, n; printf("Enter a nonnegative integer: "); scanf("%d", &n); do { n /= 10; digits++; } while (n > 0); printf("The number has %d digit(s).\n", digits); return 0; } 19 The for Statement Theforstatementisidealforloopsthat haveacountingvariable,butitsversatile enoughtobeusedforotherkindsofloopsas well. Generalformoftheforstatement: for ( expr1 ; expr2 ; expr3 ) statement expr1,expr2,andexpr3areexpressions. Example: for (i = 10; i > 0; i--) printf("T minus %d and counting\n", i); 20 The for Statement Theforstatementiscloselyrelatedtothe whilestatement. Exceptinafewrarecases,aforloopcan alwaysbereplacedbyanequivalentwhileloop: expr1; while ( expr2 ) { statement expr3; } expr1isaninitializationstepthatsperformed onlyonce,beforetheloopbeginstoexecute. 21 The for Statement expr2controlslooptermination(theloop continuesexecutingaslongasthevalue ofexpr2isnonzero). expr3isanoperationtobeperformedat theendofeachloopiteration. Theresultwhenthispatternisappliedto thepreviousforloop: i = 10; while (i > 0) { printf("T minus %d and counting\n", i); i--; } 22 The for Statement Studyingtheequivalentwhilestatementcan helpclarifythefinepointsofaforstatement. Forexample,whatifi--isreplacedby--i? for (i = 10; i > 0; --i) printf("T minus %d and counting\n", i); Theequivalentwhileloopshowsthatthe changehasnoeffectonthebehaviorofthe loop: i = 10; while (i > 0) { printf("T minus %d and counting\n", i); --i; } 23 The for Statement Sincethefirstandthirdexpressionsina forstatementareexecutedas statements,theirvaluesareirrelevant theyreusefulonlyfortheirsideeffects. Consequently,thesetwoexpressions areusuallyassignmentsor increment/decrementexpressions. 24 for Statement Idioms Theforstatementisusuallythebestchoicefor loopsthatcountup(incrementavariable)or countdown(decrementavariable). Aforstatementthatcountsupordownatotal ofntimeswillusuallyhaveoneofthefollowing forms: Countingupfrom0ton1: for (i = 0; i < n; i++) Countingupfrom1ton:for (i = 1; i <= n; i++) Countingdownfromn1to0:for (i = n - 1; i >= 0; i--) Countingdownfromnto1:for (i = n; i > 0; i--) 25 for Statement Idioms Commonforstatementerrors: Using<insteadof>(orviceversa)inthe controllingexpression.Countinguploops shouldusethe<or<=operator.Counting downloopsshoulduse>or>=. Using==inthecontrollingexpression insteadof<,<=,>,or>=. Offbyoneerrorssuchaswritingthe controllingexpressionasi<=ninsteadof i<n. 26 Omitting Expressions in a for Statement Callowsanyoralloftheexpressionsthatcontrol aforstatementtobeomitted. Ifthefirstexpressionisomitted,noinitializationis performedbeforetheloopisexecuted: i = 10; for (; i > 0; --i) printf("T minus %d and counting\n", i); Ifthethirdexpressionisomitted,theloopbodyis responsibleforensuringthatthevalueofthe secondexpressioneventuallybecomesfalse: for (i = 10; i > 0;) printf("T minus %d and counting\n", i--); 27 Omitting Expressions in a for Whenthefirstandthirdexpressionsareboth omitted,theresultingloopisnothingmore thanawhilestatementindisguise: for (; i > 0;) printf("T minus %d and counting\n", i--); isthesameas while (i > 0) printf("T minus %d and counting\n", i--); Thewhileversionisclearerandtherefore preferable. 28 Omitting Expressions in a for Ifthesecondexpressionismissing,it defaultstoatruevalue,sothefor statementdoesntterminate(unless stoppedinsomeotherfashion). Forexample,someprogrammersuse thefollowingforstatementtoestablish aninfiniteloop: for (;;) 29 for Statements in C99 InC99,thefirstexpressioninafor statementcanbereplacedbya declaration. Thisfeatureallowstheprogrammerto declareavariableforusebytheloop: for (int i = 0; i < n; i++) Thevariableineednothavebeen declaredpriortothisstatement. 30 for Statements in C99 Avariabledeclaredbyaforstatement cantbeaccessedoutsidethebodyof theloop(wesaythatitsnotvisible outsidetheloop): for (int i = 0; i < n; i++) { printf("%d", i); /* legal; i is visible inside loop */ } printf("%d", i); ***/ 31 /*** WRONG for Statements in C99 Havingaforstatementdeclareitsown controlvariableisusuallyagoodidea:its convenientanditcanmakeprogramseasier tounderstand. However,iftheprogramneedstoaccessthe variableafterlooptermination,itsnecessary tousetheolderformoftheforstatement. Aforstatementmaydeclaremorethanone variable,providedthatallvariableshavethe sametype: for i (int = 0, j = 0; i < n; i++) 32 The Comma Operator Onoccasion,aforstatementmayneedto havetwo(ormore)initializationexpressions oronethatincrementsseveralvariableseach timethroughtheloop. Thiseffectcanbeaccomplishedbyusinga commaexpressionasthefirstorthird expressionintheforstatement. Acommaexpressionhastheform expr1 , expr2 whereexpr1andexpr2areanytwo expressions. 33 The Comma Operator Acommaexpressionisevaluatedintwosteps: First,expr1isevaluatedanditsvaluediscarded. Second,expr2isevaluated;itsvalueisthevalueofthe entireexpression. Evaluatingexpr1shouldalwayshaveaside effect;ifitdoesnt,thenexpr1servesnopurpose. Whenthecommaexpression++i,i+jis evaluated,iisfirstincremented,theni+jis evaluated. Ifiandjhavethevalues1and5,respectively,the valueoftheexpressionwillbe7,andiwillbe incrementedto2. 34 The Comma Operator Thecommaoperatorisleftassociative, sothecompilerinterprets i = 1, j = 2, k = i + j as ((i = 1), (j = 2)), (k = (i + j)) Sincetheleftoperandinacomma expressionisevaluatedbeforetheright operand,theassignmentsi=1,j=2, andk=i+jwillbeperformedfromleft toright. 35 The Comma Operator Thecommaoperatormakesitpossibletoglue twoexpressionstogethertoformasingle expression. Certainmacrodefinitionscanbenefitfromthe commaoperator. Theforstatementistheonlyotherplacewhere thecommaoperatorislikelytobefound. Example: for (sum = 0, i = 1; i <= N; i++) sum += i; Withadditionalcommas,theforstatement couldinitializemorethantwovariables. 36 Program: Printing a Table of Squares (Revisited) Thesquare.cprogram(Section6.1) canbeimprovedbyconvertingits whilelooptoaforloop. 37 square2.c /* Prints a table of squares using a for statement */ #include <stdio.h> int main(void) { int i, n; printf("This program prints a table of squares.\n"); printf("Enter number of entries in table: "); scanf("%d", &n); for (i = 1; i <= n; i++) printf("%10d%10d\n", i, i * i); return 0; } 38 Printing a Table of Squares (Revisited) Cplacesnorestrictionsonthethreeexpressions thatcontrolthebehaviorofaforstatement. Althoughtheseexpressionsusuallyinitialize,test, andupdatethesamevariable,theresno requirementthattheyberelatedinanyway. Thesquare3.cprogramisequivalentto square2.c,butcontainsaforstatementthat initializesonevariable(square),testsanother (i),andincrementsathird(odd). Theflexibilityoftheforstatementcansometimes beuseful,butinthiscasetheoriginalprogram wasclearer. 39 square3.c /* Prints a table of squares using an odd method */ #include <stdio.h> int main(void) { int i, n, odd, square; printf("This program prints a table of squares.\n"); printf("Enter number of entries in table: "); scanf("%d", &n); i = 1; odd = 3; for (square = 1; i <= n; odd += 2) { printf("%10d%10d\n", i, square); ++i; square += odd; } } return 0; 40 Exiting from a Loop Thenormalexitpointforaloopisatthe beginning(asinawhileorfor statement)orattheend(thedo statement). Usingthebreakstatement,its possibletowritealoopwithanexit pointinthemiddleoraloopwithmore thanoneexitpoint. 41 The break Statement Thebreakstatementcantransfer controloutofaswitchstatement,butit canalsobeusedtojumpoutofa while,do,orforloop. Aloopthatcheckswhetheranumbern isprimecanuseabreakstatementto terminatetheloopassoonasadivisor isfound: for (d = 2; d < n; d++) if (n % d == 0) break; 42 The break Statement Aftertheloophasterminated,anif statementcanbeusetodetermine whetherterminationwaspremature (hencenisntprime)ornormal(nis prime): if (d < n) printf("%d is divisible by %d\n", n, d); else printf("%d is prime\n", n); 43 The break Statement Thebreakstatementisparticularlyusefulfor writingloopsinwhichtheexitpointisinthemiddle ofthebodyratherthanatthebeginningorend. Loopsthatreaduserinput,terminatingwhena particularvalueisentered,oftenfallintothis category: for (;;) { printf("Enter a number (enter 0 to stop): "); scanf("%d", &n); if (n == 0) break; printf("%d cubed is %d\n", n, n * n * n); } 44 The break Statement Abreakstatementtransferscontroloutofthe innermostenclosingwhile,do,for,orswitch. Whenthesestatementsarenested,thebreak statementcanescapeonlyonelevelofnesting. Example: while () { switch () { break; } } breaktransferscontroloutoftheswitchstatement, butnotoutofthewhileloop. 45 The continue Statement Thecontinuestatementissimilartobreak: breaktransferscontroljustpasttheendofa loop. continuetransferscontroltoapointjustbefore theendoftheloopbody. Withbreak,controlleavestheloop;with continue,controlremainsinsidetheloop. Theresanotherdifferencebetweenbreak andcontinue:breakcanbeusedin switchstatementsandloops(while,do, andfor),whereascontinueislimitedto loops. 46 The continue Statement Aloopthatusesthecontinue statement: n = 0; sum = 0; while (n < 10) { scanf("%d", &i); if (i == 0) continue; sum += i; n++; /* continue jumps to here */ } 47 The continue Statement Thesameloopwrittenwithoutusing continue: n = 0; sum = 0; while (n < 10) { scanf("%d", &i); if (i != 0) { sum += i; n++; } } 48 The goto Statement Thegotostatementiscapableofjumpingtoany statementinafunction,providedthatthestatement hasalabel. Alabelisjustanidentifierplacedatthebeginningof astatement: identifier : statement Astatementmayhavemorethanonelabel. Thegotostatementitselfhastheform goto identifier ; ExecutingthestatementgotoL;transferscontrolto thestatementthatfollowsthelabelL,whichmustbe inthesamefunctionasthegotostatementitself. 49 The goto Statement IfCdidnthaveabreakstatement,a gotostatementcouldbeusedtoexit fromaloop: for (d = 2; d < n; d++) if (n % d == 0) goto done; done: if (d < n) printf("%d is divisible by %d\n", n, d); else printf("%d is prime\n", n); 50 The goto Statement Thegotostatementisrarelyneededin everydayCprogramming. Thebreak,continue,andreturn statementswhichareessentially restrictedgotostatementsandthe exitfunctionaresufficienttohandle mostsituationsthatmightrequirea gotoinotherlanguages. Nonetheless,thegotostatementcan behelpfulonceinawhile. 51 The goto Statement Considertheproblemofexitingaloopfromwithina switchstatement. Thebreakstatementdoesnthavethedesired effect:itexitsfromtheswitch,butnotfromtheloop. Agotostatementsolvestheproblem: while () { switch () { goto loop_done; } } loop_done: /* break won't work here */ Thegotostatementisalsousefulforexitingfrom nestedloops. 52 Balancing a Checkbook Manysimpleinteractiveprogramspresentthe userwithalistofcommandstochoosefrom. Onceacommandisentered,theprogram performsthedesiredaction,thenpromptsthe userforanothercommand. Thisprocesscontinuesuntiltheuserselects anexitorquitcommand. Theheartofsuchaprogramwillbealoop: for (;;) { promptusertoentercommand; readcommand; executecommand; } 53 Balancing a Checkbook Executingthecommandwillrequireaswitch statement(orcascadedifstatement): for (;;) { promptusertoentercommand; readcommand; switch (command) { case command1: performoperation1; break; case command2: performoperation2; break; . . . case commandn: performoperationn; break; default: printerrormessage; break; } } 54 Balancing a Checkbook Thechecking.cprogram,which maintainsacheckbookbalance,usesa loopofthistype. Theuserisallowedtocleartheaccount balance,creditmoneytotheaccount, debitmoneyfromtheaccount,display thecurrentbalance,andexitthe program. 55 Balancing a Checkbook *** ACME checkbook-balancing program *** Commands: 0=clear, 1=credit, 2=debit, 3=balance, 4=exit Enter command: 1 Enter amount of credit: 1042.56 Enter command: 2 Enter amount of debit: 133.79 Enter command: 1 Enter amount of credit: 1754.32 Enter command: 2 Enter amount of debit: 1400 Enter command: 2 Enter amount of debit: 68 Enter command: 2 Enter amount of debit: 50 Enter command: 3 Current balance: $1145.09 Enter command: 4 56 checking.c /* Balances a checkbook */ #include <stdio.h> int main(void) { int cmd; float balance = 0.0f, credit, debit; printf("*** ACME checkbook-balancing program ***\n"); printf("Commands: 0=clear, 1=credit, 2=debit, "); printf("3=balance, 4=exit\n\n"); for (;;) { printf("Enter command: "); scanf("%d", &cmd); switch (cmd) { case 0: balance = 0.0f; break; 57 } case 1: printf("Enter amount of credit: "); scanf("%f", &credit); balance += credit; break; case 2: printf("Enter amount of debit: "); scanf("%f", &debit); balance -= debit; break; case 3: printf("Current balance: $%.2f\n", balance); break; case 4: return 0; default: printf("Commands: 0=clear, 1=credit, 2=debit, "); printf("3=balance, 4=exit\n\n"); break; } } 58 The Null Statement Astatementcanbenulldevoidof symbolsexceptforthesemicolonatthe end. Thefollowinglinecontainsthree statements: i = 0; ; j = 1; Thenullstatementisprimarilygoodfor onething:writingloopswhosebodies areempty. 59 The Null Statement Considerthefollowingprimefindingloop: for (d = 2; d < n; d++) if (n % d == 0) break; Ifthen%d==0conditionismovedintothe loopscontrollingexpression,thebodyofthe loopbecomesempty: for (d = 2; d < n && n % d != 0; d++) /* empty loop body */ ; Toavoidconfusion,Cprogrammers customarilyputthenullstatementonalineby itself. 60 The Null Statement Accidentallyputtingasemicolonaftertheparenthesesin anif,while,orforstatementcreatesanullstatement. Example1: if (d == 0); /*** WRONG ***/ printf("Error: Division by zero\n"); Thecallofprintfisntinsidetheifstatement,soits performedregardlessofwhetherdisequalto0. Example2: i = 10; while (i > 0); /*** WRONG ***/ { printf("T minus %d and counting\n", i); --i; } Theextrasemicoloncreatesaninfiniteloop. 61 The Null Statement Example3: i = 11; while (--i > 0); /*** WRONG ***/ printf("T minus %d and counting\n", i); Theloopbodyisexecutedonlyonce;themessage printedis: T minus 0 and counting Example4: for (i = 10; i > 0; i--); /*** WRONG ***/ printf("T minus %d and counting\n", i); Again,theloopbodyisexecutedonlyonce,andthe samemessageisprintedasinExample3. 62
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

University of Florida - CGS - 2531
CGS 2531I.Hardware TermsTerms and PhrasesPC- stands for personal computer. Has four functions: 1. It accepts input 2.Through the CPU (central processing unit); 3. Once the information has beenprocessed it can then be stored. 4. Or directed to one of
University of Florida - CGS - 2531
CGS PowerPoint: Ethics, Privacy, Viruses, and Emerging TechnologiesEthics Ethics is a standard of conduct that guide decisions and actions based on dutiesderived from core values. Values are our fundamental beliefs or principles. They define what we t
University of Florida - CGS - 2531
COUNT FunctionsCOUNT - =COUNT(value 1, up to 30)oCounts the number of numeric valueso Includes: numbers, cell references, cell ranges, and formulasoBlank cells and text cells are ignoredExample:COUNTA - =COUNTA(value 1, up to 30)o Counts number o
University of Florida - CGS - 2531
File Management Windows XPWays to Open Windows Explorer Start Programs Explorer Right Click on Start button explorer Right click on my computer icon on desktop, select exploreBasic Components File: the basic unit of storageo Looks like a sheet of p
University of Florida - CGS - 2531
CGS POWERPOINT: THE INTERNETThe Internet The internet is a specific worldwide network of interconnected computers, whereconnections and resources are voluntarily globally shared. The internet incorporates information, data, and resources on all subjec
University of Florida - CGS - 2531
CGS2531 NotesFebruary 9MICROSOFT WORD POWERPIONTThe most powerful word processor to date.May be used for: letters, memos, flyers, calendars, manuals, faxes, web pages,research papers, brochures, desktop publishing, resumes, theses, contracts,templat
University of Florida - CGS - 2531
Spring 2009Instructor: Sungwook MoonMWF 5CGS2531 Excel Database part., Practice quiz* Use only the database functions you learned after test #3.Refer to the Florida Football 2008 table for the following questions.1. What is the table (database) name
University of Florida - CGS - 2531
Spring 2009Instructor: Sungwook MoonMWF 5CGS2531 Excel Database part., Practice quiz #2* Use only the database functions you learned after test #3.Refer to the College choice table for the following questions.(I am about to graduate from high school
University of Florida - CGS - 2531
CGS2531'sStudyGuideforTest1Study Class Notes, CD Presentations, Tutorials, Course Text, Windows Section,Changing Technologies, and the CD Internet, Copyright, Viruses, and Ethics Readings.This guide is not necessarily complete. You are responsible for
University of Florida - CGS - 2531
CGS2531March 9, 2011 NotesViruses, Malware, and ControversyVirus is a self-replicating program that spreads by inserting copies of itself intoother executable code or documents.Usually infect executable filesTrojans horsesWormsSome viruses may be
University of Florida - CWR - 3201
ANALYSIS (CHARTS &amp; GRAPHS)WATER MANOMETERCollection TimeH2OCollectedVelocityHeight1Height2HeightDifferenceHydraulicGradientTimeVolumeFlowRateQVh1h1h2h233mLLmsecondsm /sm/smmm2080.2080.000208306.93E060.98087452
University of Florida - CWR - 3201
LAB #4FORCES DUE TO IMPACT OF A JETMONDAY LABANALYSISCONSTANTS USED IN LABWater TemperatureMass of water collectedMass of jockey weightJet diameterElevation of surface above nozzleHorizontal distance from x-origin topivotArea of nozzle22120
University of Florida - CWR - 3201
LAB #7FRICTION LOSS ACROSS A PIPEANALYSIS (SHORT ANSWER)2(a). Laminar regions are defined as areas where Re&lt; 2000. Laminar flows are also referred to asviscous flows or streamline flows. The slope in the laminar region is 1.747 (s/m). I obtained this
University of Florida - CWR - 3201
CWR3201 HydrodynamicsLab 1: Forces on a Plane SurfaceAnalysis1. The table is provided on the next page.2. Present a sensitivity analysis consisting of:a. The effect of an error of 1 mm in the moment results in ameasured moment that is incorrect to 0
University of Florida - CWR - 3201
LAB 2: RESEVOIR ORIFICECOEFFICIENTSQuestions:1) By calculating coefficient discharge using equation 7, a value ofCd=0.303 was tabulated for the sharp-edged orifice and Cd=1 for there-entrant. By using equation 6, the values I found for Cd with thesh
University of Florida - CWR - 3201
Lab 3: Flow Through a Venturi MeterTable 1: Maximum Flow Rate Calculated and Given ValuesManometerTubeDiameter(m)Distance(m)CrossSectional Area(m^2)Height(m)CollectionTime (sec.)IdealPressureExperimentalDistributionsHA(h1)0.026-0.054
University of Florida - CWR - 3201
4 : Table 1: Given Values and Reference ValuesWater Temperature (Deg C)20Mass of Water Collected (kg)12Mass of Jockey Weight (kg)600Jet Diameter (m)0.01Elevation of Surface Above Nozzle0.035(m)Horizontal Distance From X-origin0.15to Pivo
University of Florida - CWR - 3201
Analysis 2For flow 1, the difference between the experimental and theoretical values fory2/y1 was 0.054 (From 3.844-3.79). For flow 2 the difference was much larger at 1.331(From 10.647-9.316). Flow 1 has a percentage error of 14.25%, an expected level
University of Florida - CWR - 3201
ConclusionThis lab analyzed characteristics of laminar and turbulent flow, as well as thetransition between flow types. There is a clear distinction in the two separate flow types.Laminar flow is slow and steady. Turbulent flow is fast and chaotic thro
University of Florida - CWR - 3201
ConclusionThis lab analyzed the resistance a circular cylinder exerted on an airstream. Thisresistance is known as drag. Measured data was used to calculate drag coefficients for thecylinder. Integration of Figure 3 calculated a drag coefficient of 1.1
University of Florida - CWR - 3201
Table 1: Maximum Flow Rate DataManometerTubeDiameter(m)Distance(m)Cross SectionalArea (m^2)Height(m)CollectionTime(sec.)IdealPressureExperimentalDistributionsHA(h1)0.026-0.0540.000530660.27221.500HB0.0232-0.0340.0004225180.25
University of Florida - PHY - 2061
Name:_ _PHY20619-29-05Exam 1 Solutions+2q7q5q+3q3q2q3q3q+4q+4qd5q7q+2q1. [6 points] A central particle of charge 2q is surrounded by a square array of chargedparticles. The length of the square side is d, and charges are placed at the s
University of Florida - PHY - 2061
Final Phy2061 Honors Physics April 28, 20091.) (2) Imagine a cube of side 1 m that occupies 0 to 1 m along all three positive axes with one corner at the origin, i. e. 0 x 1 m, 0 y 1 m, 0 z 1 m, and that we have an electric field given by E = a[3.0x4 i]
University of Florida - PHY - 2061
Homework 7 solutions continued: Solar wind can have a large effect on the earth. On March 13, 1989, in Qubec, 6 million people lost commercial electric power for 9 hours due to a huge geomagnetic storm. The effect is due to the changing magnetic fields, a
University of Florida - PHY - 2061
Homework IVChaps. 28-301.) A charge of +2e, where e is the fundamental charge=1.602 10-19 C, isapproaching at v=5 106 m/s from a great distance away a fixed charge of +Q, whereQ is some integer number of positive elemental charges. If the point of clo
University of Florida - PHY - 2061
Homework IV1.) A charge of +2e, where e is the fundamental charge=1.602 10-19 C, isapproaching from a great distance away at v=5 106 m/s a fixed charge of +Q, whereQ is some integer number of positive elemental charges. If the point of closestapproach
University of Florida - PHY - 2061
Homework IXChaps. 37 (due March 23 no late homework accepted due toTest on March 25.)1.) In an RLC alternating current circuit, R=100 , L = 0.1 H, C=0.1 F and thefrequency, f, is 60 Hz. In this circuit:a.) What is the inductive reactance, XL ?b.) Wh
University of Florida - PHY - 2061
Homework IXChap. 37no late homework accepted test on Thursday, March 251.) In an RLC alternating current circuit, R=100 , L = 0.1 H, C=0.1 F and thefrequency, f, is 60 Hz. In this circuit:a.) What is the inductive reactance, XL ?XL = L = 2 fL = 2 (6
University of Florida - PHY - 2061
Homework V - PHY2061Due in Class Tuesday Feb. 9 no late homework accepted dueto test on Thursday Feb. 11 on Chapters 25-321.) a.) Three resistors, R1=10 , R2=20 , R3=30 , are arranged in series. What isthe total equivalent resistance of all three resi
University of Florida - PHY - 2061
Homework VIII Chaps. 35-36, Induction1.) Consider the Earths magnetic field as that of a dipole with the magnetic field around the equator having magnitude 30 T. The radius of the earth is 6.37 106 m. a. Calculate the magnetic flux B in low earth orbit (
University of Florida - PHY - 2061
Homework VIII Chaps. 35-36, Induction1.) Consider the Earths magnetic field as that of a dipole with the magnetic field around the equator having magnitude 30 T. The radius of the earth is 6.37 106 m. a. Calculate the magnetic flux B in low earth orbit (
University of Florida - PHY - 2061
Homework VII Chap. 34, Induction (Statements in red for your information, not necessarily of importance to the solving of the problem.)1.) The north pole of a high field permanent magnet (Nd2Fe14B like the one we dropped down the copper pipe in class) wi
University of Florida - PHY - 2061
Homework VI - PHY20611.) In class we considered a problem (B field from two wires in some symmetric geometrical arrangement) like sample problem 33-3. Consider instead the arrangement below, where two long wires carring currents (both equal to i) are com
University of Florida - PHY - 2061
Homework VI - PHY20611.) In class we considered a problem (B field from two wires in some symmetric geometrical arrangement) like sample problem 33-3. Consider instead the arrangement below, where two long wires carring currents (both equal to i) are com
University of Florida - PHY - 2061
Homework V - PHY20611.) a.) Three resistors, R1=10 , R2=20 , R3=30 , are arranged in series. What isthe total equivalent resistance of all three resistors?-R1R2R3Req= 60 b.) Now the same three resistors are arranged in parallel, what is their total
University of Florida - PHY - 2061
Homework Xdue Tuesday, April 6, 2009 Chaps. 38-391.) This is a waveguide problem. First, a short tutorial (cribbed from the web athttp:/www.fnrf.science.cmu.ac.th/theory/waveguide/index.html)a.) the idea is to transmit/transfer electromagnetic radiati
University of Florida - PHY - 2061
Homework XIChap. 401.) An object is on the left side of a convex mirror whose radius of curvature is25 cm. If a virtual image of the object is formed to the right of the convexmirror at a distance (absolute magnitude) of 7.2 cm,a.) what is the distan
University of Florida - PHY - 2061
Homework XI, part 2 (cosmology and quantum) Due Tuesday, April 20,20101.) You learned in the lecture (or from the chapter in the book on Cosmology, page 1186) that Hubble found that v=Hd, where v is the velocity of some observed galaxy, d is the distance
University of Florida - PHY - 2061
Homework 1.) For PHY2061, Chaps. 25-26, Spring 2009Show work on problems to get credit the answer is notenough.Chap. 25:1.) Two electrons are held a fixed distance r apart. melectron=9.11 10-31 kgOne electron is released, and under the influence of t
University of Florida - PHY - 2061
Homework II, PHY2061 (show work for credit)1.) Three thin (but finite thickness) concentric conducting shells have radii R 1 &lt; R2&lt; R3 and charges -2Q, +Q, and +3Q respectively, where Q is some positive number.What is the charge on the inner surface of
University of Florida - PHY - 2061
Homework III, PHY2061 (show work for credit)1.) In the picture, the potential energy at point P is some value, where P lies on thez-axis at -2d on a line connecting the plus charge at +d and the minus charge at d.Where on the z-axis above the minus cha
University of Florida - PHY - 2061
Test 1, Phy2061SPRING 2010The electric field is given by the negative rate of change of the electric potential perunit length (i. e. you need to take the slope at the point asked for):= / = 400 /8 =400 /0.08 = 5000 / 5 = 0 volts/cm (flat) at 10 cm=
University of Florida - PHY - 2061
Test IIChap. 31-37Chap. 331. Four long straight wires are arranged as show on the corners of a square withside length 2s. The upper left wire and the upper right wire have currents comingout of thepage, and thelower left andlower rightwires have
University of Toronto - CHM - 220H1
University of Toronto - CHM - 220H1
University of Toronto - CHM - 220H1
University of Toronto - MAT - 135
University of Toronto - MAT - 135
University of Toronto - MAT - 135H
University of Toronto - PSY - 100H
Practice Test for TT11. Jane and Janet are identical twins. According to evidence presented by Gleitman on weightgain, if Jane and Janet overeat at the same rate and exercise very little for 3 months, what patternof weight gain would you expect them to
University of Toronto - MAT - 135H
University of Toronto - MAT - 135H
University of Toronto - APM - 346H
Problem 1x3 ux - uy = 0,Characteristics are: Solution:u(x, 0) =1 1 + x21 1 -y = 2 2x 2 2 u(x, y) = 1 - 2 x2 y x2 - 2 x2 y + 1Problem 29 uxx + 6 uxy + uyy + ux = 0There are innitely many correct answers ! One of them: = 3 y - x,Canonical form:=x
University of Toronto - APM - 346H
University of Toronto - APM - 346H
MIDTERM TEST II Course: APM346H Instructor: Chugunova Marina Date: 10 November 2008This test consists of 2 parts. Please use the backs of pages if you need more room to write. No books, notes, or calculators allowed. The total number of points is 48. GOO
University of Toronto - APM - 346H
University of Toronto - MAT - 234H
University of Toronto - MAT - 234H
University of Toronto - MAT - 234H
University of Toronto - MAT - 234H