Chapter 3

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 41

Writing Requirements

CHAPTER 3
Syntactic
Requirements Patterns

A syntactic requirements pattern defines as documenting requirements


in natural language and defines the meaning of keywords used in the
pattern.
Shall Requirement has to be implemented
Might Requirement is optionally implemented
Should Implementation of the requirement is
highly recommended
REMARKS:
[ ] Use the constituent optionally
{ } Choose one of the given phrases
< > Fill out the constituent
• [When] : If the camera detect movement in the house, THE SYSTEM
SHALL [Process] capture the image and send to the [Object]
dropbox.
• Functionality of the sensor will not properly work if the
device has the problem in term of connection.
[When] : If the device connection has problem, the system
sensor MIGHT [Process] not detect the [Object] image.
Structured English
From user-speak to programming

Plain Structured Pseudocode Programs


English English

User Analyst Programmer


INTRODUCTION
 Structured English is similar to a programming
language such as Pascal
 It does not have strict syntax rules as programming
language
 Intention is to give precise description of a process

 The structured English description should be


understandable to the user
Writing Structured English
• File Names
– Separate words with hyphens
– Use Title Case, e.g. Invoice-Record
• Common verbs
– READ, ACCEPT, GET, WRITE, PRINT, SORT, MOVE, MERGE, ADD, SUBTRACT,
MULTIPLY, DIVIDE
• Common nouns:
– Variable names, attributes, data flow inputs and outputs
• Focus on how the process converts the inputs to outputs
STRUCTURED ENGLISH
-DECISION STRUCTURES
If condition
then
{ Group of statements }
else
{ Group of statements }
end if

Example: if balance in account more than minimum balance


then
honor request
else
reject request
end if
STRUCTURED ENGLISH
-CASE STATEMENT

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 : Case product code


product code =1 : discount= 5%
product code =2 : discount =7%
None of the above : discount=0
end case
STRUCTURED ENGLISH
-REPETITION STRUCTURE

for index = initial to final do


{ statements in loop }
end for

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

Example : while there are student records left to do


read student record
compute total marks
find class
write total marks, class, roll no
end while
Structured English uses the following rules:

1. All statements should be clear and concise, use proper spelling


and grammar, and should not be ambiguous.
2. Use the standard programming structures: sequence, selection,
iteration.
3. One statement should contain only one logical
element/component.
4. Use proper indentation where necessary, e.g. for the body of
selection and loops.
5. Commands and actions should always use the imperative verb
form (e.g. print, select, complete, click/press, submit)
Structured English and Pseudocode

Structured English Pseudocode

PROGRAM PrintNumber: PROGRAM PrintNumber:


Read in a number and print Read A;
it out. Print A;
END. END.
Structured English and Pseudocode

Structured English Pseudocode

PROGRAM BiggerOfTwo: PROGRAM BiggerOfTwo :


Read A;
Read in a number.
Read B;
Read in a second number. IF (A>B)
If the first number is bigger, then print out that THEN Print A;
number, otherwise print out the other ELSE Print B;
number. ENDIF;
END. END.
Process description: Our store has a membership program, but some
customers are not members. Members can rent as many items as they
want and, in fact, if they rent more than 8 items at a time they get a
discount. They usually pay 3.99 per item but if they rent more than 8
items then they only pay 3.49 per item. Customers who aren't members
always pay 4.49 per item. It doesn't matter how many items they rent.
Process: Membership Policy
Begin
If a customer is a member then
     the rental cost per item is 3.99
If a customer is a member and rents more than 8 items then
     the rental cost per item is 3.49.
If a customer is not a member then
     the rental cost is 4.49 per item.
End
Decision Tables
Modeling Logic with Decision Tables

• Decision table: a matrix representation of the logic


of a decision which specifies the possible
conditions for the decision and the resulting
actions
• Best used for complicated decision logic
Decision Tables
• A tabular of conditions and actions and an indication under which
conditions, which actions must be performed
• Consists of four quadrants

Condition Stub Rules


a list of all possible conditions contains selectors which identify
that can arise within the process different combinations of the possible conditions

Action Stub Action Entries


a list of all possible actions that indicators which select the actions to be performed
occur within the process
Identifying Conditions and Their Actions

Condition Action
Represent the specific rule Represent all possible courses of
when making a decision action associated with a given set of
conditions

Watch TV until 10pm, then go to bed.

Condition: until 10pm


Action 1: You will watch TV
Action 2: You will go to bed
Modeling Logic with Decision Tables

• Condition stubs: that part of a decision table that


lists the conditions relevant to the decision
• Action stubs: that part of a decision table that lists
the actions that result for a given set of conditions
Procedure for Creating Decision Tables

1. Name the condition and the values that


each condition can assume.
2. Name all possible actions that can
occur.
3. List all possible rules.
4. Define the actions for each rule.
5. Simplify the table.
Complete decision table for payroll system

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

If the number of items is 4 or more: If the number of items is 4 or more:


Delivery Day Shipping Charge, Delivery Day Shipping Charge,
N = number of items N = number of items
Next Day N * RM7.50 Next Day N * RM6.00
2nd Day N * RM3.50 2nd Day N * RM2.50
Standard N * RM2.50 Standard FREE
Structured English
If purchase amt. more than RM250.00
Else
If number of items less than 4 then
If number of items less than 4 then If delivery date is next day then
If delivery date is next day then Delivery charge is RM35.00
Delivery charge is RM25.00 Else if delivery date is 2nd day then
Else if delivery date is 2nd day then Delivery charge is RM15.00
Delivery charge is RM10.00 Else if delivery date is standard then
Else if delivery date is standard then Delivery charge is RM10.00
Delivery charge is RM1.50 per item. End If
End If Else
Else If delivery date is next day then
If delivery date is next day then Delivery charge is RM7.5 per item
Delivery charge is RM6.00 per item Else if delivery date is 2nd day then
Else if delivery date is 2nd day then Delivery charge is $3.50 per item
Delivery charge is RM2.50 per item Else
Else Delivery is $2.50 per item
Delivery is free of charge End If
End If End If
End If End If
Decision Table
Purchase
Amount Over RM250.00 Less than RM250.00

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

Rules = 2 value *2 value *3 value


= 12
Purchase >250 >250 >250 >250 >250 >250 <250 <250 <250 <250 <250 <250
Amount
No. items <3 <3 <3 4> 4> 4> <3 <3 <3 4> 4> 4>

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

You might also like