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 &nbsp; ''no solution found'' &nbsp; message
* a ''don't care'' requirement (regarding the decision table)
* a &nbsp; ''don't care'' &nbsp; requirement &nbsp; (regarding the decision table)
* a method of specifying requirments and not needing recoding for future queries
* 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*/
ask.=
Q. =
ask.1='Does the printer not print?'
Q.1 = 'Does the printer not print?'
ask.2='Is there a red light flashing on the printer?'
Q.2 = 'Is there a red light flashing on the printer?'
ask.3='Is the printer unrecognized by the software?'
Q.3 = 'Is the printer unrecognized by the software?'
Q.0 = 3

do set=1 while ask.set\==''; end /*count the number of questions. */

set=set-1 /*adjust SET (number of ? asked)*/

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). */
/* │┌──────◄ answer to 2nd question. */
/* │┌──────◄ " " 2nd " " " " " " */
/* ││┌─────◄ answer to 3rd question. */
/* ││┌─────◄ " " 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 set /*get responses from the prompts.*/
do i=1 for Q.0; ans.i=asker(i); end /*display query, get resp.*/
call asker i /*display question, get response.*/
end /*i*/
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
if d==' ' then leave
jm=j//Q.0; if jm==0 then jm=Q.0
if \datatype(d,'U') then iterate
if d==' ' then leave
if d\==ans.jm then iterate k
if \datatype(d,'U') then iterate
if j==set then leave
if d\==ans.jm then iterate k
if j==Q then leave
end /*j*/
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" set') '
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])'

do forever
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 words(ans)==0 then iterate /*nothing entered? Try again. */
if abbrev('QUIT',ansU,1) then exit /*the user is tired of answering.*/


do forever
if (\abbrev('YES',ansU,1) & \abbrev('NO',ansu,1)) |,
words(ans)\==1 then do; say 'invalid response: ' ans; oops=1
if oops then do; say; say right(howTo,79); say; oops=0; end
iterate
say Qprefix Q.?; parse pull x /*ask a question (after a prompt)*/
end
x=space(x); parse upper var x u 1 u1 2 /*u=upper(x); u1=1st char*/
if words(x)==0 then iterate /*nothing entered? Try again. */
ans.?=left(ansU,1)
if abbrev('QUIT',u,1) then exit /*the user is tired of answering.*/
return
if (abbrev('YES',u) | abbrev('NO',u)) & words(x)==1 then return u1
end /*forever*/</lang>
say 'invalid response: ' x; oops=1
end /*forever*/</lang>
'''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.