Presentation is loading. Please wait.

Presentation is loading. Please wait.

Decision Tables and Pseudocode

Similar presentations


Presentation on theme: "Decision Tables and Pseudocode"— Presentation transcript:

1 Decision Tables and Pseudocode
Rizwan Rehman Asstt. Professor Centre for Computer Studies

2 Decision Tables - General
Decision tables are a precise yet compact way to model complicated logic. Decision tables, like if-then-else and switch-case statements, associate conditions with actions to perform. But, unlike the control structures found in traditional programming languages, decision tables can associate many independent conditions with several actions in an elegant way.

3 Decision Tables - Usage
Decision tables make it easier to observe that all possible conditions are accounted for. Decision tables can be used for: Specifying complex program logic Generating test cases (Also known as logic-based testing) Logic-based testing is considered as: structural testing when applied to structure (i.e. control flow graph of an implementation). functional testing when applied to a specification.

4 Decision Tables - Structure
Conditions - (Condition stub) Condition Alternatives – (Condition Entry) Actions – (Action Stub) Action Entries Each condition corresponds to a variable, relation or predicate Possible values for conditions are listed among the condition alternatives Boolean values (True / False) – Limited Entry Decision Tables Several values – Extended Entry Decision Tables Don’t care value Each action is a procedure or operation to perform The entries specify whether (or in what order) the action is to be performed

5 To express the program logic we can use a limited-entry decision table consisting of 4 areas called the condition stub, condition entry, action stub and the action entry: Condition entry Rule1 Rule2 Rule3 Rule4 Condition1 Yes No Condition2 X Condition3 Condition4 Action1 Action2 Action3 Condition stub Action stub Action Entry

6 We can specify default rules to indicate the action to be taken when none of the other rules apply.
When using decision tables as a test tool, default rules and their associated predicates must be explicitly provided. Rule5 Rule6 Rule7 Rule8 Condition1 X No Yes Condition2 Condition3 Condition4 Default action

7 Decision Table - Example
Conditions Printer does not print Y N A red light is flashing Printer is unrecognized Actions Heck the power cable X Check the printer-computer cable Ensure printer software is installed Check/replace ink Check for paper jam Printer Troubleshooting

8 Pseudocode

9 Flowcharts were the first design tool to be widely used, but unfortunately they do not reflect some of the concepts of structured programming very well. Pseudocode, on the other hand, is a newer tool and has features that make it more reflective of the structured concepts. The drawback is that the narrative presentation is not as easy to understand and/or follow.

10 Rules for Pseudocode Write only one statement per line
Capitalize initial keyword Indent to show hierarchy End multiline structures Keep statements language independent

11 One Statement Per Line Each statement in pseudocode should express just one action for the computer. If the task list is properly drawn, then in most cases each task will correspond to one line of pseudocode. Task List Read name, hours worked, rate of pay Perform calculations gross = hours worked * rate of pay Write name, hours worked, gross Pseudocode READ name, hoursWorked, payRate gross = hoursWorked * payRate WRITE name, hoursWorked, gross

12 Capitalize Initial Keyword
In the example below note the words: READ and WRITE. These are just a few of the keywords to use, others include: READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE Pseudocode READ name, hoursWorked, payRate gross = hoursWorked * payRate WRITE name, hoursWorked, gross

13 Indent to Show Hierarchy
Each design structure uses a particular indentation pattern Sequence: Keep statements in sequence all starting in the same column Selection: Indent statements that fall inside selection structure, but not the keywords that form the selection Loop: Indent statements that fall inside the loop but not keywords that form the loop READ name, grossPay, taxes IF taxes > 0 net = grossPay – taxes ELSE net = grossPay ENDIF WRITE name, net

14 End Multiline Structures
READ name, grossPay, taxes IF taxes > 0 net = grossPay – taxes ELSE net = grossPay ENDIF WRITE name, net See the IF/ELSE/ENDIF as constructed above, the ENDIF is in line with the IF. The same applies for WHILE/ENDWHILE etc…

15 Language Independence
Resist the urge to write in whatever language you are most comfortable with, in the long run you will save time. Remember you are describing a logic plan to develop a program, you are not programming!

16 The Selection Structure
amount < 100 yes no interestRate = .06 interestRate = .10 IF amount < 100 interestRate = .06 ELSE Interest Rate = .10 ENDIF Pseudocode 

17 The Looping Structure In flowcharting one of the more confusing things is to separate selection from looping. This is because each structure use the diamond as their control symbol. In pseudocode we avoid this by using specific keywords to designate looping WHILE/ENDWHILE REPEAT/UNTIL

18 WHILE / ENDWHILE count = 0 WHILE count < 10 ADD 1 to count
WRITE count ENDWHILE WRITE “The End” Start count = 0 count <10 Mainline count = 0 WHILE count < 10 DO Process ENDWHILE WRITE “The End” Process ADD 1 to count WRITE count  Modular Write “The End” add 1 to count write count Stop

19 REPEAT / UNTIL count = 0 REPEAT ADD 1 to count WRITE count
Start count = 0 REPEAT ADD 1 to count WRITE count UNTIL count >= 10 WRITE “The End” count = 0 add 1 to count Mainline count = 0 REPEAT DO Process UNTIL count >= 10 WRITE “The End” Process ADD 1 to count WRITE count  Modular write count count <10 Write “The End” Stop

20 Advantages & Disadvantages
Flowchart Advantages: Standardized Visual Pseudocode Advantages Easily modified Implements structured concepts Done easily on Word Processor Flowchart Disadvantages: Hard to modify Structured design elements not implemented Special software required Pseudocode Disadvantages: Not visual No accepted standard, varies from company to company

21 Thank You


Download ppt "Decision Tables and Pseudocode"

Similar presentations


Ads by Google