Like this presentation? Why not share!

Algorithms

on Nov 21, 2012

• 1,962 views

Views

Total Views
1,962
Views on SlideShare
1,272
Embed Views
690

Likes
0
23
0

2 Embeds690

 http://nwl-elearning.mywisenet.com.au 671 http://moodle.wortech.ac.uk 19

Report content

• Comment goes here.
Are you sure you want to

AlgorithmsPresentation Transcript

• Algorithms forProgram Design 1
• Process ModellingProcess modelling is performed during the designstage of developing a new system.Data Flow Diagrams - show WHAT the new systemmust be able to do.Process Specification - provides details of HOW therequired functionality is achieved.Various techniques used to clarify procedures Structure Diagrams Flow Charts Pseudocode / Structured EnglishProvides the logical design for a computer algorithm 2
• Start Start Flow Charts Subtotal = 00 Subtotal = • Not to be confused with Data Flow Diagrams (DFDs) VAT = 1.175 VAT = 1.175 Shows steps required to achieve the correct outcome Input: ItemPrice Input: ItemPrice Flow charts provide a graphical representation of an algorithm Subtotal = Subtotal + Subtotal = Subtotal + • Can become complex and hard to follow ItemPrice ItemPrice • Best used to give overview of functionality. Pseudocode provides a non-technical no End of Item list? End of Item list? description of an algorithm • More detailed and closely related to yes programming codeTotal = Subtotal **VAT Total = Subtotal VAT Structure diagrams are useful to show a hierarchical overview of program modules Output: Output: • Helps to identify how the main project“Total Price = £” (Total) “Total Price = £” (Total) components will be created • Input - Processing - Output Stop Stop 3
• PseudocodePseudocode is a technique used during the designstage of developing a program.Used to translate the users requirements into a into acomplete sequence of unambiguous, logical steps.It is written in Structured English to describe thesystem operations accurately and precisely,including all the steps need to code the program.Can be understood by any programmer & coded intoany language. 4
• How to….Create an Algorithm Start with a statement of the user’s needs Then write a program specification Then write out in sentences what the program needs to do at each step All of the time, consider how a computer runs an event driven program INPUT – PROCESS – OUTPUT 5
• How to ... PseudocodeStarting with general sentences (Structured English)Remove as many of the extra words as you can - justleave the bare minimumIf values are being entered - input: use the term “read in” or “get”…..For any processing or calculations use the logical operators + - * / < > = “True”, “False”If results are being displayed - output: use the term “print”The final pseudocode should be language independent,but must avoid any ambiguity. 6
• Example: Description of the stages of a program for adding two numbers and displaying the result:The user types in Number1The user types in Number2The program adds Number1 and Number2The program displays the Total on the screen This isn’t written in pseudocode quite yet…… 7
• Example:Read in Number1Read in Number2Total = Number1 + Number2Print (Total) Now this is like program code Because of this it is called pseudocode Structured English is what it is written in 8
• Example: Verify Product 9
• Example: Verify ProductFor each Ordered Product Get Product(CatNo), Ordered(CatNo) If Product(CatNo) = Ordered (CatNo) Then Get Product (Level), Ordered (Quantity), If Product (Level) >= Ordered (Quantity) Then Order accepted = True Else Order accepted = False End If Else Print Invalid Product No End IfNext ProductPrint confirmed order 10
• Example: HND course 11
• Example: Credit Card Authorisation START Bank connection GET Total due, Card type, Card number, Expiry date GET Stolen cards list IF Stolen = True THEN Print “Retain card and destroy” ELSE LOOP WHILE Counter < 3 AND PIN = False Increment Counter GET PIN IF PIN = True THEN GET Limit, Balance IF Total Due < Limit - Balance THEN GET Ref (Transaction) Balance = Balance + Total Due PRINT “Transaction authorised” & Ref ELSE Authorised = False PRINT “Insufficient funds available” END IF EXIT Bank connection END IF END LOOP PRINT “Incorrect PIN - Retain card and refer to bank” END IF EXIT Bank connection 12