1 csi 101 elements of computing fall 2009 lecture #4 using flowcharts monday february 2nd, 2009
Post on 30-Jan-2016
214 views
TRANSCRIPT
1
CSI 101 Elements of Computing
Fall 2009
Lecture #4Using Flowcharts
Monday February 2nd, 2009
2
Let's Talk about Designing
● Why Design?● Proper Preparation Prevents Poor Performance● Determine flow and function
● What happens when● Think through before coding
● Prevents trial and error● Prevents massive corrections
● Determine most efficient way● Fewer places to insert errors● Faster processing
3
Advantages to Designing
● Ensure completeness● By working through design, can see if you have
covered everything requested
● Can see where requirements are vague or lacking
● Provide focus
● Important for large projects with multiple people
● Identify key flow points and transitions
● Can plan adequate and complete test plans
4
Design for Testing?
● To completely test, must be able to completely know flow
● Large projects have multiple tests● And therefore multiple testers● Rarely is developer the same person who tests
● Checkpoints● Key spots in program where status of data is
known
● Variation● Condition or branch that causes different results
5
Examples of Variations
● Conditions● Something greater or less than● Need to test how many states?
● 3 – Greater, lesser, or equal● Flows
● Looping until a particular event or successful test● How many variations?
● 3 – starting, continuing, and stopping● Transitions
● Calling a function● How many variations?
● 2 normal (before and after) and error restore
6
Designing made Easy
● Designs don't have to be large or complex● Some companies write out big documents
● Detail is important to the person writing● Most people only need highlights● The simpler a design is, easier to read and
understand● That's the philosophy behind Flowcharts
7
Flowcharts
● Pictorial● If you know the symbols, you can read
● Machine independent● Can be enlarged for emphasis● Uses simple recognizable shapes● Few constructs to remember
8
Symbols
9
Sample Flowchart (without text)
10
Terminator
● Starts and ends a process● Only one flow, either departing or entering
START
STOP
11
Process
● Contains calculation or process● Can contain a sequence of consecutive
operations● Has a single flow entering and a single flow
exiting
Calculate average Sum = A+B+C
Ave = Sum/3
12
Decision
● Condition whose result causes one of multiple calculations or processes
● Stated as question with only YES or NO as answer
● One flow entering and two flows exiting
Is A > B?
Yes
No
13
Input/Output
● Read input or write output● Only one operation, but can have multiple
inputs or outputs● One flow entering and one flow exiting
Read A,B,C
14
Connector
● Brings together separate flows that are coming together to perform the same operation
● Multiple flows entering, one flow exiting● Note there is no “disconnector”
15
B
Link
● Continues flow on another page● Note this is used ONLY to allow a flow to move
onto another page. There is never a need to have two links with the same letter or number on the same page!
● Link is labeled with a letter or number, and has a matching link on another page
● Only one flow, either entering or exiting● Enters at existing page, exits on other page
2
16
External Reference
● Not Input or Output, which use local devices● Memory transfer from database or other
external device● Denotes Load into register● One flow entering, one flow exiting
Get next Employee record
17
Predefined Function
● Denotes CALL● Perform a function that has previously been
written and stored in a library● If it's a function that produces a result, the
result can be stored into a variable● One flow entering, one flow exiting● In box below, MIN is the predefined function
● Low is the variable containing the result
Low = MIN(A,B,C)
18
Let’s try one
● Let’s write a flowchart to detail the process of a user logging into a computer account
● What’s the first step?● Determine input and output● Input: userid and password● Output: one of three situations:
● Accepted● Incorrect userid● Incorrect password
19
Other Considerations
● Password is encrypted. Must use system’s routine to check it
● The file containing user names cannot be “open” text● Would mean any process could get list of names● There must be a system routine to check for
existence
20
So what are our steps?
● INPUT userid and password● CALL check of userid● DECISION: is userid valid?
● No, send message to user and exit● Yes, continue
● CALL check of password, passing userid● DECISION: OK?
● No, send message to user and exit● Yes, send message of success and exit
21
AnswerSTART
Input userid, pwd
Exists = UserCheck (userid)
Userid exists?
No
Yes
A
B
22
Answer, part 2
A
OK = PwdCheck( userid, pwd)
Pwd ok?
“User does not exist”
No
“Begin work”
Yes
B
“Invalid password”
END
23
Extra consideration
● Some systems allow users three chances, in case they misspelled something
● How would that change this flowchart?● Have a loop
● Must use a counter, as there is no loop structure in flowcharts
● Set counter, flow to decision● Decision tests if counter <= 3● Yes, goes through process again● No, connect to connector before END terminator
24
Bonus Assignment
● Implement the “3 tries” extra consideration mentioned on the previous slide● In other words, recreate the flowchart on Slides
21 and 22 but with the “loop” that allows the user three tries
● This is not required; do it if you would like● Due the same time as Homework
Assignment #1● Counts as an extra 50 points