Chapter 3
Chapter 3
CHAPTER 3
Syntactic
Requirements Patterns
Case (variable)
Variable = P: { statements for alternative P}
Variable = Q: { statements for alternative Q}
Variable = R: { statements for alternative R}
None of the above: { statements for default case}
end case
Example : Total =0
for subject =1 to subject =5 do
total marks=total marks +marks(subject)
write roll number, total marks
end for
STRUCTURED ENGLISH
-WHILE LOOP
while condition do
{ statements in loop }
end while
Condition Action
Represent the specific rule Represent all possible courses of
when making a decision action associated with a given set of
conditions
How many
RULES??
Employee type
(Salary,Hour)
=2 value
Hour Worked
(<40, 40, >40)
= 3 value
2 value x 3 value
= 6 rules
Reduced decision table for payroll system
Rule 1: states that if an
employee is salaried, it
doesn't matter how many
hours they worked: the
action will always be to pay
them their base salary
Rule 2: If an employee is
hourly and works less than
40 hours, pay them their
hourly wage and produce
an absence report for this
employee.
Rule 3: If an employee is
hourly and works exactly
forty hours, pay them
their hourly wage.
Rule 4: If an employee is hourly and works more than 40
hours, pay them their hourly wage and pay their
overtime claim.
Payroll System
Structured English Representation
BEGIN
BEGIN IF
IF Employee-Type is Salary
THEN PAY base salary
END IF
BEGIN IF
IF Employee-Type is Hourly
AND Hours-Worked is <40
THEN CALCULATE hourly wage AND PRODUCE Absence Report
END IF
BEGIN IF
IF Employee-Type is Hourly
AND Hours-Worked is 40
THEN CALCULATE hourly wage
END IF
BEGIN IF
IF Employee-Type is Hourly
AND Hours-Worked is >40
THEN CALCULATE hourly wage AND CALCULATE overtime
END IF
END
Rules
Delivery
Charges 1 2 3 4 5 6
Purchase <500 & <500 & <500 &
>=RM500 <=100 <=100
Amount >100 >100 >100
Preferred
Customer? -- Y N N -- --
Paid Cash? -- -- Y N Y N
Free X X
Delivery
Charge RM5 X X
Charge
X X
RM10
Use the decision table above to answer the following questions:
1.How much is delivery if a customer paid by credit card for a bill totaling RM1005.49? 1.Free delivery
2.How much is delivery if a preferred customer paid cash for a RM99.95 bill? 2.delivery is RM5
3.How much is delivery if a customer paid cash for a bill totaling RM1250.00, if they are not a preferred 3.Free delivery
customer? 4.Free delivery
4.How much is delivery if the customer's bill comes out to RM455.00, they paid by credit card, and they're a
preferred customer?
An airline offers only flights to India and Asia. Under special conditions, a
discount is offered on the normal airfare:
a) Passengers older than 18 with destinations in India are offered a
discount of 20%, as long as the departure is not on a Monday or
Friday.
b) For destinations outside of India, passengers are offered a discount
of 25%, if the departure is not on a Monday or Friday.
c) Passengers who stay at least 6 days at their destination receive an
additional discount of 10%.
d) Passengers older than 2 but younger than 18 years are offered a
discount of 40% for all destinations.
e) Children 2 and under travel for free.
f) Create the table, reduce it, and then display the action stub/entry in
Extended Entry format.
Conditions:
Destination (India, Asia)
Passenger Age (<= 2, > 2 & < 18, > 18)
Depart on Monday or Friday (Yes, No)
Stay 6 days or more (Yes, No)
Actions:
Travel Free
0% discount
10% discount
20% discount
25% discount
40% discount
Number of rules: 2 values * 3 values * 2 values * 2 values = 24 rules
Example
ABS Courier Sdn. Bhd. has just announced that it will offer free shipping
for all orders over RM250.00 in the future. Shipping charges for all orders will be prorated.
Develop a decision table; consider all the conditions and actions to get the rules.
For order less than RM250.00, For order over RM250.00,
the shipping charge will be calculated as follows: the shipping charge will be calculated as follows:
If the number of items is 3 or less: If the number of items is 3 or less:
Delivery Day Shipping Charge Delivery Day Shipping Charge
Next Day RM35.00 Next Day RM25.00
2nd Day RM15.00 2nd Day RM10.00
Standard RM10.00 Standard N * RM1.50
Number
of items 3 or less 4 or more 3 or less 4 or more
Delivery
Next 2nd Day Std. Next 2nd Day Std. Next 2nd Day Std. Next 2nd Day Std.
Day
Shipping
Charge N* N* N* N* N* N*
25 10 FREE 35 15 10
(RM) RM1.50 RM6.00 RM2.50 RM7.50 RM3.50 RM2.50
Delivery Next 2nd Std. Next 2nd Day Std. Next 2nd Day Std. Next 2nd Day Std.
Day Day
FREE x
RM10 x x
RM15 x
RM25 x
RM35 x
N* RM1.50 x
N* RM2.50 x x
N* RM3.50 x
N* RM6.00 x
N* RM7.50 x
Exercise
Sabasun Hypermarket has a promotion program for the valued customers.
Customers who shopping online for a minimum RM200 will get a 20%
discount. If customers shopping online three times a month with minimum
expenses (RM200) will have a similar discount plus 5%. In addition,
customers doing more than ten shopping online a year will get a similar
discount if expenses minimum RM200 each times.
Develop a final deduction decision table; consider all the conditions and
actions to get the rules.
Answer
Promotion Program 1 2 3 4 5 6 7 8
Spend min RM200 (Y,N) N Y N Y N Y N Y
3 times shopping a month (Y,N) N N Y Y N N Y Y
10 times shopping a year (Y,N) N N N N Y Y Y Y
No discount X X X X
20% discount X
25% discount X X X
Deduction Decision Table
Promotion Program 1 2 3 4
Spend min RM200 (Y,N) N Y Y Y
3 time shopping a month (Y,N) - N Y -
More 10 times shopping a year (Y,N) - N - Y
No discount X
20% discount X
25% discount X X
THANK YOU