Developing Algorithms forDeveloping Algorithms for Early ...
Algorithms
-
Upload
nickywalters -
Category
Documents
-
view
3.395 -
download
3
Transcript of Algorithms
1
Algorithms
forProgram Design
22
Process Modelling
Process modelling is performed during the design
stage of developing a new system.
Data Flow Diagrams - show WHAT the new system
must be able to do.
Process Specification - provides details of HOW the
required functionality is achieved.
Various techniques used to clarify procedures
Structure Diagrams
Flow Charts
Pseudocode / Structured English
Provides the logical design for a computer algorithm
33
Flow ChartsStartStart
• Not to be confused with Data Flow Diagrams (DFDs)
Shows steps required to achieve the correct outcome
Flow charts provide a graphical representation of an algorithm• Can become complex and hard to follow
• Best used to give overview of functionality.
Pseudocode provides a non-technical description of an algorithm• More detailed and closely related to
programming code
Structure diagrams are useful to show a hierarchical overview of program modules • Helps to identify how the main project
components will be created
• Input - Processing - Output
Subtotal = 0VAT = 1.175Subtotal = 0VAT = 1.175
Input: ItemPriceInput: ItemPrice
End of Item list?End of Item list?
Subtotal = Subtotal + ItemPrice
Subtotal = Subtotal + ItemPrice
Total = Subtotal * VATTotal = Subtotal * VAT
Output: “Total Price = £” (Total)
Output: “Total Price = £” (Total)
StopStop
nono
yesyes
44
Pseudocode
Pseudocode is a technique used during the design
stage of developing a program.
Used to translate the users requirements into a into a
complete sequence of unambiguous, logical steps.
It is written in Structured English to describe the
system operations accurately and precisely,
including all the steps need to code the program.
Can be understood by any programmer & coded into
any language.
55
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
66
How to ... Pseudocode
Starting with general sentences (Structured English)
Remove as many of the extra words as you can - just
leave the bare minimum
If 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.
77
Example:
Description of the stages of a program for adding two numbers and displaying the result:
The user types in Number1
The user types in Number2
The program adds Number1 and Number2
The program displays the Total on the screen
This isn’t written in pseudocode quite yet……
88
Example:
Read in Number1
Read in Number2
Total = Number1 + Number2
Print (Total)
Now this is like program code
Because of this it is called pseudocode
Structured English is what it is written in
99
Example: Verify Product
1010
Example: Verify Product
For 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
ElsePrint Invalid Product No
End IfNext ProductPrint confirmed order
1111
Example: HND course
1212
Example: Credit Card AuthorisationSTART Bank connection
GET Total due, Card type, Card number, Expiry dateGET Stolen cards listIF 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 IFEXIT Bank connection
END IFEND LOOP PRINT “Incorrect PIN - Retain card and refer to bank”
END IFEXIT Bank connection