Decision tables: Difference between revisions
Content added Content deleted
(Added JavaScript) |
(→{{header|REXX}}: rewrote the REXX program for more positive logic (as opposed to negative logice), corrected a misspelling. -- ~~~~) |
||
Line 796: | Line 796: | ||
This REXX example shows how one version of a decision table could be implemented, |
This REXX example shows how one version of a decision table could be implemented, |
||
<br>There was additional support added to the code for: |
<br>There was additional support added to the code for: |
||
* a ''no solution found'' message |
* a ''no solution found'' message |
||
* a ''don't care'' requirement (regarding the decision table) |
* a ''don't care'' requirement (regarding the decision table) |
||
* a method of specifying |
* a method of specifying requirements and not needing recoding for future queries |
||
* used a minimalistic way in expressing the decision table |
* used a minimalistic way in expressing the decision table |
||
* extra prompting when there was a user reponse error |
* extra prompting when there was a user reponse error |
||
Line 805: | Line 805: | ||
* a method of allowing the user to quit the interrogation |
* a method of allowing the user to quit the interrogation |
||
<lang rexx>/*REXX pgm demonstrates a decision table and possible corrective actions*/ |
<lang rexx>/*REXX pgm demonstrates a decision table and possible corrective actions*/ |
||
Q. = |
|||
Q.1 = 'Does the printer not print?' |
|||
Q.2 = 'Is there a red light flashing on the printer?' |
|||
Q.3 = 'Is the printer unrecognized by the software?' |
|||
Q.0 = 3 |
|||
do set=1 while ask.set\==''; end /*count the number of questions. */ |
|||
⚫ | |||
act.= /* Y = yes N = no not letter = don't care. */ |
act.= /* Y = yes N = no not letter = don't care. */ |
||
/* ┌───────◄ answer to 1st question |
/* ┌───────◄ answer to 1st question (in upper\lower\mixed case). */ |
||
/* │┌──────◄ |
/* │┌──────◄ " " 2nd " " " " " " */ |
||
/* ││┌─────◄ |
/* ││┌─────◄ " " 3rd " " " " " " */ |
||
/* │││ */ |
/* │││ */ |
||
/* ↓↓↓ */ |
/* ↓↓↓ */ |
||
act.1 = 'yny' ; pos.1 = 'Check the power cable.' |
act.1 = 'yny' ; pos.1 = 'Check the power cable.' |
||
act.2 = 'y.y' ; pos.2 = 'check the printer-computer cable.' |
act.2 = 'y.y' ; pos.2 = 'check the printer-computer cable.' |
||
act.3 = '..y' ; pos.3 = 'Ensure printer software is installed.' |
act.3 = '..y' ; pos.3 = 'Ensure printer software is installed.' |
||
act.4 = '.y.' ; pos.4 = 'Check/replace ink.' |
act.4 = '.y.' ; pos.4 = 'Check/replace ink.' |
||
act.5 = 'y.n' ; pos.5 = 'Check for paper jam.' |
act.5 = 'y.n' ; pos.5 = 'Check for paper jam.' |
||
/* act.2 could be also be set to: ynyYNY (lower/upper/mixed case).*/ |
|||
do i=1 for Q.0; ans.i=asker(i); end /*display query, get resp.*/ |
|||
call asker i /*display question, get response.*/ |
|||
⚫ | |||
say |
say |
||
possible=0 /*we'll be counting possible sols*/ |
possible=0 /*we'll be counting possible sols*/ |
||
do k=1 while act.k\=='' /*filter answers via decision tab*/ |
do k=1 while act.k\=='' /*filter answers via decision tab*/ |
||
do j=1; d=substr(act.k,j,1); upper d |
do j=1; d=substr(act.k,j,1); upper d |
||
jm=j//set; if jm==0 then jm=set |
|||
jm=j//Q.0; if jm==0 then jm=Q.0 |
|||
if |
if d==' ' then leave |
||
if \datatype(d,'U') then iterate |
|||
if d\==ans.jm then iterate k |
|||
⚫ | |||
end /*j*/ |
|||
⚫ | |||
say pos.k /*this could be a possible sol. */ |
say pos.k /*this could be a possible sol. */ |
||
possible=possible+1 /*count num of possible solutions*/ |
possible=possible+1 /*count num of possible solutions*/ |
||
Line 849: | Line 843: | ||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're done.*/ |
||
/*───────────────────────────────────ASKER subroutine───────────────────*/ |
/*───────────────────────────────────ASKER subroutine───────────────────*/ |
||
asker: arg ?; oops=0; Qprefix=copies('─',9) '(question' ? "of" |
asker: arg ?; oops=0; Qprefix=copies('─',9) '(question' ? "of" Q.0') ' |
||
howTo='(You can answer with a Yes or No [or Quit])' |
howTo = '(You can answer with a Yes or No [or Quit])' |
||
⚫ | |||
if oops then do; say; say right(howTo,79); say; oops=0; end |
|||
say Qprefix ask.? /*ask the ───────── question. */ |
|||
parse pull ans; parse upper var ans ansU . |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if oops then do; say; say right(howTo,79); say; oops=0; end |
|||
say Qprefix Q.?; parse pull x /*ask a question (after a prompt)*/ |
|||
x=space(x); parse upper var x u 1 u1 2 /*u=upper(x); u1=1st char*/ |
|||
⚫ | |||
ans.?=left(ansU,1) |
|||
⚫ | |||
return |
|||
⚫ | |||
⚫ | |||
say 'invalid response: ' x; oops=1 |
|||
⚫ | |||
'''output''' (a screen scraping using a DOS prompt window for the possible responses) |
'''output''' (a screen scraping using a DOS prompt window for the possible responses) |
||
DECISION.REX is the REXX program that produced this output. |
DECISION.REX is the REXX program that produced this output. |