Beruflich Dokumente
Kultur Dokumente
Introductionto Flowcharting
CSC103:IntroductiontoComputerandProgramming
START
WhatisaFlowchart?
Aflowchartisa diagramthatdepicts theflowofa program. Thefigureshownhere isaflowchartforthe paycalculating program
ReadHours
ReadPayRate
DisplayGross Pay
END
CSC103:IntroductiontoComputerandProgramming
BasicFlowchartSymbols
Noticetherearethree typesofsymbolsinthis flowchart:
roundedrectangles parallelograms arectangle
START
Displaymessage Howmany hoursdidyou work?
Rounded Rectangle
ReadHours
Parallelogram
ReadPayRate
Rectangle
Rounded Rectangle
DisplayGross Pay
END
CSC103:IntroductiontoComputerandProgramming
9/7/2011
BasicFlowchartSymbols
Terminals
representedbyrounded rectangles indicate a starting or indicateastartingor endingpoint
START
START
Displaymessage Howmany hoursdidyou work?
Terminal
ReadHours
ReadPayRate
DisplayGross Pay
END
Terminal
END
CSC103:IntroductiontoComputerandProgramming
BasicFlowchartSymbols
Input/OutputOperations
representedby parallelograms indicate an input or indicateaninputor outputoperation
Displaymessage Howmany hoursdidyou work?
START
Displaymessage Howmany hoursdidyou work?
ReadHours
Input/Output Operation
ReadPayRate
ReadHours
DisplayGross Pay
END
CSC103:IntroductiontoComputerandProgramming
BasicFlowchartSymbols
Processes
representedbyrectangles indicatesaprocesssuchas amathematical a mathematical computationorvariable assignment
MultiplyHours byPayRate. Storeresultin GrossPay.
Process
START
Displaymessage Howmany hoursdidyou work?
ReadHours
ReadPayRate
DisplayGross Pay
END
CSC103:IntroductiontoComputerandProgramming
9/7/2011
START
Displaymessage Howmany hoursdidyou work?
Output Operation
ReadHours
ReadPayRate
DisplayGross Pay
END
CSC103:IntroductiontoComputerandProgramming
START
Displaymessage Howmany hoursdidyou work?
ReadHours
ReadPayRate
DisplayGross Pay
END
CSC103:IntroductiontoComputerandProgramming
START
Displaymessage Howmany hoursdidyou work?
ReadHours
Output Operation
ReadPayRate
DisplayGross Pay
END
CSC103:IntroductiontoComputerandProgramming
9/7/2011
START
Displaymessage Howmany hoursdidyou work?
ReadHours
ReadPayRate
DisplayGross Pay
END
CSC103:IntroductiontoComputerandProgramming
10
SteppingThroughthe Flowchart
Howmuch doyouget paidper hour?
START
Displaymessage Howmany hoursdidyou work?
ReadHours
ReadPayRate
DisplayGross Pay
END
CSC103:IntroductiontoComputerandProgramming
11
SteppingThroughthe Flowchart
Yourgross payis800
START
Displaymessage Howmany hoursdidyou work?
ReadHours
ReadPayRate
Output Operation
DisplayGross Pay
END
CSC103:IntroductiontoComputerandProgramming
12
9/7/2011
FourFlowchartStructures
Sequence Decision Repetition Case
CSC103:IntroductiontoComputerandProgramming
13
SequenceStructure
aseriesofactionsareperformedinsequence Thepaycalculatingexamplewasasequence flowchart.
CSC103:IntroductiontoComputerandProgramming
14
DecisionStructure
Oneoftwopossibleactionsistaken,dependingona condition.
CSC103:IntroductiontoComputerandProgramming
15
9/7/2011
DecisionStructure
Anewsymbol,thediamond,indicatesayes/noquestion.If theanswertothequestionisyes,theflowfollowsonepath.If theanswerisno,theflowfollowsanotherpath
NO
YES
CSC103:IntroductiontoComputerandProgramming
16
DecisionStructure
Intheflowchartsegmentbelow,thequestionisx<y?is asked.Iftheanswerisno,thenprocessAisperformed.Ifthe answerisyes,thenprocessBisperformed.
NO x<y?
YES
ProcessA
ProcessB
CSC103:IntroductiontoComputerandProgramming
17
DecisionStructure
Theflowchartsegmentbelowshowshowadecision structureisexpressedinCasanif/elsestatement.
Flowchart
CCode
NO x<y?
YES
if (x < y) a = x * 2; else
Calculateaas xplusy.
Calculateaas xtimes2.
a = x + y;
CSC103:IntroductiontoComputerandProgramming
18
9/7/2011
DecisionStructure
Theflowchartsegmentbelowshowsadecisionstructurewith onlyoneactiontoperform.Itisexpressedasanifstatement inCcode.
Flowchart CCode
NO x<y?
YES
if (x < y) a = x * 2;
Calculateaas xtimes2.
CSC103:IntroductiontoComputerandProgramming
19
RepetitionStructure
Arepetitionstructurerepresentspartoftheprogramthat repeats.Thistypeofstructureiscommonlyknownasaloop.
CSC103:IntroductiontoComputerandProgramming
20
RepetitionStructure
Noticetheuseofthediamondsymbol.Alooptestsa condition,andiftheconditionexists,itperformsanaction. Thenitteststheconditionagain.Iftheconditionstillexists, theactionisrepeated.Thiscontinuesuntiltheconditionno longerexists.
CSC103:IntroductiontoComputerandProgramming
21
9/7/2011
RepetitionStructure
Intheflowchartsegment,thequestionisx<y?isasked.If theanswerisyes,thenProcessAisperformed.Thequestion isx<y?isaskedagain.ProcessAisrepeatedaslongasxis lessthany.Whenxisnolongerlessthany,therepetition stopsandthestructureisexited.
CSC103:IntroductiontoComputerandProgramming
22
RepetitionStructure
Theflowchartsegmentbelowshowsarepetitionstructure expressedinCasawhileloop.
Flowchart
CCode
while (x < y)
x = x+1;
CSC103:IntroductiontoComputerandProgramming
23
ControllingaRepetitionStructure
Theactionperformedbyarepetitionstructuremust eventuallycausethelooptoterminate.Otherwise,aninfinite loopiscreated. Inthisflowchartsegment,xisneverchanged.Oncetheloop starts,itwillneverend. QUESTION:Howcanthis flowchartbemodifiedso itisnolongeraninfinite YES loop? x<y? Displayx
CSC103:IntroductiontoComputerandProgramming
24
9/7/2011
ControllingaRepetitionStructure
ANSWER:Byaddinganactionwithintherepetitionthat changesthevalueofx.
CSC103:IntroductiontoComputerandProgramming
25
APreTestRepetitionStructure
Thistypeofstructureisknownasapretestrepetition structure.TheconditionistestedBEFORE anyactionsare performed.
CSC103:IntroductiontoComputerandProgramming
26
APreTestRepetitionStructure
Inapretestrepetitionstructure,iftheconditiondoesnot exist,theloopwillneverbegin.
CSC103:IntroductiontoComputerandProgramming
27
9/7/2011
APostTestRepetitionStructure
Thisflowchartsegmentshowsaposttest repetitionstructure. TheconditionistestedAFTER theactions areperformed. Aposttestrepetitionstructurealways performsitsactionsatleastonce.
Displayx
Add1tox
YES x<y?
CSC103:IntroductiontoComputerandProgramming
28
APostTestRepetitionStructure
Theflowchartsegmentbelowshowsaposttestrepetition structureexpressedinCasadowhileloop.
Displayx
CCode Flowchart do {
Add1tox
YES x<y?
CSC103:IntroductiontoComputerandProgramming
29
CaseStructure
Oneofseveralpossibleactionsistaken,depending onthecontentsofavariable.
CSC103:IntroductiontoComputerandProgramming
30
10
9/7/2011
CaseStructure
Thestructurebelowindicatesactionstoperform dependingonthevalueinyears_employed.
CASE years_employed
1
bonus=100
2
bonus=200
3
bonus=400
Other
bonus=800
CSC103:IntroductiontoComputerandProgramming
31
CaseStructure
CASE years_employed l d
1
bonus=100
2
bonus=200
3
bonus=400
Other
bonus=800
CSC103:IntroductiontoComputerandProgramming
32
Connectors
Sometimesaflowchartwillnotfitononepage. Aconnector(representedbyasmallcircle)allows youtoconnecttwoflowchartsegments.
CSC103:IntroductiontoComputerandProgramming
33
11
9/7/2011
Connectors
START
END A
CSC103:IntroductiontoComputerandProgramming
34
Modules
Aprogrammodule(suchasafunctioninC)is representedbyaspecialsymbol.
CSC103:IntroductiontoComputerandProgramming
35
Modules
START
ReadInput.
Callcalc_pay function.
Displayresults.
END
CSC103:IntroductiontoComputerandProgramming
36
12
9/7/2011
CombiningStructures
Structuresarecommonlycombinedtocreatemorecomplex algorithms. Theflowchartsegmentbelowcombinesadecisionstructure withasequencestructure.
CSC103:IntroductiontoComputerandProgramming
37
CombiningStructures
Thisflowchartsegment showstwodecision structurescombined.
NO
x>min?
YES
Displayxisoutside thelimits.
NO
x<max?
YES
Displayxisoutside thelimits.
Displayxis withinlimits.
CSC103:IntroductiontoComputerandProgramming
38
Review
Whatdoeachofthefollowingsymbols represent?
(Answeronnextslide) CSC103:IntroductiontoComputerandProgramming
39
13
9/7/2011
Answer
Whatdoeachofthefollowingsymbols represent?
Terminal Input/Output Operation Decision
Connector
Process
Module
CSC103:IntroductiontoComputerandProgramming
40
Review
Namethefourflowchartstructures.
(Answeronnextslide) CSC103:IntroductiontoComputerandProgramming
41
Answer
Sequence Decision Repetition p Case
CSC103:IntroductiontoComputerandProgramming
42
14
9/7/2011
Review
Whattypeofstructureisthis?
(Answeronnextslide) CSC103:IntroductiontoComputerandProgramming
43
Answer
Repetition
CSC103:IntroductiontoComputerandProgramming
44
Review
Whattypeofstructureisthis?
(Answeronnextslide) CSC103:IntroductiontoComputerandProgramming
45
15
9/7/2011
Answer
Sequence
CSC103:IntroductiontoComputerandProgramming
46
Review
Whattypeofstructureisthis?
(Answeronnextslide) CSC103:IntroductiontoComputerandProgramming
47
Answer
Case
CSC103:IntroductiontoComputerandProgramming
48
16
9/7/2011
Whattypeofstructureisthis?
Review
(Answeronnextslide) CSC103:IntroductiontoComputerandProgramming
49
Answer
Decision
CSC103:IntroductiontoComputerandProgramming
50
SwitchonaLamp
CSC103:IntroductiontoComputerandProgramming
51
17
9/7/2011
CSC103:IntroductiontoComputerandProgramming
52
CSC103:IntroductiontoComputerandProgramming
53
CSC103:IntroductiontoComputerandProgramming
54
18
9/7/2011
Flowchartsandsubprocesses
Thesubprocess isusefulbecause:
Itprovidesameansofsimplifyingprogramsbymaking commonprocessesavailabletoawidenumberof programs. Itdividescomplexprogramsintomodules Itmakesformorereliableprogramssinceonceitisshown thataprocessworksthenitcanbemadeasubprocess and neednotbetestedagain.
CSC103:IntroductiontoComputerandProgramming
55
Example
CSC103:IntroductiontoComputerandProgramming
56
Usingnestedloopsinflowcharts
CSC103:IntroductiontoComputerandProgramming
57
19