View
240
Download
0
Category
Tags:
Preview:
Citation preview
1
CHAPTER 10Decision Tables
2
Content Introduction construction Types of Decision Tables
Limited Entry Extended Entry
Combining of Rules General Rule Q & A
3
Introduction Some programs require solution using
multiple decisions to produce the correct output.
This can be a difficult task as this is not always readily apparent
Decision Tables is a problem-analysis tool used to solved complex decision logic
Decision tables offer a complete, concise and logical way of relating combinations of actions to combinations of conditions
4
Introduction all appropriate conditions must be
satisfied before the conclusion is drawn and the specified action or actions taken
The basic concept of the decision table is therefore the IF…and IF…THEN… relationship.
Decision Table is constructed before
flow chart or structure chart is drawn
5
Construction
The four basic elements of the decision table are known as: The condition stub The condition
entries/rules The action stub The action entries
Condition stub
Condition entries
Action stub
Action entries
Decision Tables Quadrants
6
Construction The condition stub describe the
conditions to be tested Condition entries describes the
possible combination of Boolean values (Yes/No or simply Y/N) for the conditions
The action stub contains possible actions based on the conditions
and action entries describe the actions to be taken which correspond to each Boolean value of each condition.
7
Construction Steps
1. List all possible conditions 2. Determine how many possible
Boolean values combinations/rules. Since each condition has 2
outcomes (T/F), therefore the number of rules is determined by
2n where n is the number of conditionse.g. with 3 conditions, there must be 6
rules - boolean columns
3. List all possible actions4. For each rule, select the
appropriate action/s. Indicate with ‘X’ or tick.
8
Example Consider the following simple logical
situation If it is cold and wet, I will take my
sweater and umbrella. If it is cold, I will take my
sweater. If it is wet, I will take my
umbrella. If it is neither cold nor wet, I will
take neither.
9
Example of construction STEP 1 : List all possible conditions
1. Is it cold?2. Is it wet?
STEP 2 : Determine how many possible Boolean values combinations/rules
Conditions - 2 Thus rules = 22 , which is 4
10
Example of construction
State of weather Rule 1 Rule 2 Rule 3 Rule 4
YesYes
YesNo
NoYes
NoNo
Condition entriesCondition stub
Is it cold?Is it wet?
11
Example of construction STEP 3 : List all possible actions
1. Take sweater2. Take umbrella3. Take neither
12
Example of construction
STEP 4 : For each rule, select the appropriate action/s indicated by ‘X’ or tick. The situation is expressed in a decision table as follows:
State of weather Rule 1 Rule 2 Rule 3 Rule 4
Is it cold?Is it wet?
YesYes
YesNo
NoYes
NoNo
Take sweaterTake umbrellaTake neither
Action stub Action entries
13
Types of Decision Tables 2 Types:-
Limited Entry Table Extended Entry Table
14
Limited Entry Table expresses each condition in the
condition stub as a question which can be answered ‘Yes’ or ‘No’ (2 states) – indicated by Y/N
If condition is inapplicable for any particular rule, entry is indicated by a dash/blank
The number of condition rules required is determine by the formula 2n
15
Example Determine the rate of discount allowed and
whether or not there is free delivery according to the purchaser and/or type of purchase. If the goods are assumed to be televisions with either 23 or 29 inches screens, dealers being approved or non-approved and the sets themselves being either walnut or plastic finish, solve the problem using a decision table if:1. Non-approved dealers are allowed 5% discount.2. Approved dealers are allowed –
a. free delivery on 29 inch setsb. 25% discount on 29 inch walnutc. 20% on other sets
16
Solution
DiscountRule
1Rule
2Rule
3Rule
4Rule
5Rule
6Rule
7Rule
8
Approved dealer? Y Y Y Y N N N N
Walnut finish? Y Y N N Y Y N N
29” screen? Y N Y N Y N Y N
5% discount X X X X
20% discount X X X
25% discount X
Free delivery X X
17
Extended Entry Tables Also known as Mixed Entry Table. Used when the condition entry contains
not a straight forward ‘Yes’ or ‘No’ answer
For example, a condition might be ‘DIRECTION’ and the condition entries ‘North’, ‘South’, ‘East’ and ‘West’.
18
Extended Entry Tables The number of condition rules
required is determine by the multiplying the number of outcome of each conditions.
E.g. condition1 has 2 outcome (Y/N) condition2 has 3 outcome
(100,200,300) condition3 has 2 outcome (Y/N)
Therefore no. of rules required 2x3x2 = 12 rules
19
Example An order will be approved if a
guarantee is available and credit is $100, or if there is no guarantee but credit is $200 in which case special clearance does not apply, or if credit is $100, there is no guarantee and special clearance is given, or if credit is $300, there is no guarantee and no special clearance. If there is no guarantee, credit is $100 and special clearance is not given, the order is not approved and is returned to the client.
20
solution
Order approval
1 2 3 4 5 6 7 8 9 10 11 12
Guarantee? Y Y Y Y Y Y N N N N N N
Credit? 100 200 300 100 200 300 100 200 300 100 200 300
Specialclearance?
Y N Y N Y N Y N Y N Y N
Pass X X X X
Return X
21
General Rules of combining rules If, for any combination of rules, the
condition entries are identical except for one row and the action entries are also identical, the two rules can be combined, a dash being inserted in place of the conditions which are not the same .
22
Combining of Rules
It is possible to combine rules if they are having the same actions.
E.g. If it is cold or wet, I will take my jacket
Weather 1 Rule 1 Rule 2 Rule 3 Rule 4
Is it cold?Is it wet?
YesYes
YesNo
NoYes
NoNo
Take jacketTake nothing
X X XX
23
Combination of rules
It will be noted that for rules 1 and 2 in which the status of the first condition is Yes, the status of the second is immaterial. The action to be taken is the same whether the answer is Yes or No. This is indicated by a dash.
The new table will be:
Weather 2 Rule 1 Rule 2 Rule 3
Is it cold?Is it wet?
Yes-
NoYes
NoNo
Take jacketTake nothing
X XX
24
Combination of rules
The new table for the problem on “Discount” is: Discount Rule 1 Rule 2 Rule 3 Rule 4
Approved dealer? Y Y Y N
Walnut finish? Y - N N
29” screen? Y N Y N
5% discount X
20% discount X X
25% discount X
Free delivery X X
25
Class Exercise – Create a decision table for the following problem:
A carpenter needs a program that computes the price of any desk a customer orders based on the following input fields; order number, desk length in inches and width in inches (3 digits each, no decimals), type of wood (assumed valid type is entered), and a number of drawers (2 digits). The price is computed as follows:
1. The charge for all desk minimum is $2002. If the surface area is over 750 sq. in., add $503. If the wood is “mahogany” add $150; for “oak”
add $125. No charge is added for “pine”4. For every drawer in the desk, there is an
additional $30 charge
Recommended