Decision tables: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added/changed whitespace and comments, elided deadcode, added highlighting to the output, added a template for the output section.)
Line 1,758: Line 1,758:
::*   a method of allowing the user to quit (opt-out of) the interrogation
::*   a method of allowing the user to quit (opt-out of) the interrogation
<lang rexx>/*REXX program demonstrates a (query) decision table and possible corrective actions.*/
<lang rexx>/*REXX program demonstrates a (query) decision table and possible corrective actions.*/
Q.=; Q.1 = 'Does the printer not print?'
Q.=; Q.1 = 'Does the printer not print?'
Q.2 = 'Is there a red light flashing on the printer?'
Q.2 = 'Is there a red light flashing on the printer?'
Q.3 = 'Is the printer unrecognized by the software?'
Q.3 = 'Is the printer unrecognized by the software?'
Q.0 = 3
action.= /* Y=yes N=no if character isn't a letter = don't care.*/
action.= /* Y=yes N=no if character isn't a letter = don't care.*/


Line 1,769: Line 1,768:
/* │││ */
/* │││ */
/* ↓↓↓ */
/* ↓↓↓ */
action.1 = 'yny' ; pos.1 = 'Check the power cable.'
action.1 = 'yny' ; pos.1 = "═════════ Check the power cable."
action.2 = 'y.y' ; pos.2 = 'check the printer-computer cable.'
action.2 = 'y.y' ; pos.2 = "═════════ check the printer-computer cable."
action.3 = '..y' ; pos.3 = 'Ensure printer software is installed.'
action.3 = '..y' ; pos.3 = "═════════ Ensure printer software is installed."
action.4 = '.y.' ; pos.4 = 'Check/replace ink.'
action.4 = '.y.' ; pos.4 = "═════════ Check/replace ink."
action.5 = 'y.n' ; pos.5 = 'Check for paper jam.'
action.5 = 'y.n' ; pos.5 = "═════════ Check for paper jam."


do i=1 for Q.0; ans.i=asker(i); end /*display the question, obtain response*/
do i=1 while Q.i\==''; ans.i= asker(i) /*display the question, obtain response*/
end /*i*/; Q.0= i - 1 /*adjust Q.0 for the DO loop indexing. */
say /*display a blank line before questions*/
say /*display a blank line before questions*/
possible=0 /*we'll be counting possible solutions.*/
possible= 0 /*we'll be counting possible solutions.*/


do k=1 while action.k\=='' /*filter the answers via decision table*/
do k=1 while action.k\=='' /*filter the answers via decision table*/


do j=1; d=substr(action.k, j, 1); upper d
do j=1; d= substr(action.k, j, 1); upper d
jm=j//Q.0; if jm==0 then jm=Q.0
jm= j//Q.0; if jm==0 then jm= Q.0
if d==' ' then leave
if d==' ' then leave
if \datatype(d, 'U') then iterate
if \datatype(d, 'U') then iterate
if d\==ans.jm then iterate k
if d\==ans.jm then iterate k
if j==Q then leave
end /*j*/
end /*j*/
say pos.k /*this could be a possible solution. */
say pos.k /*this could be a possible solution. */
possible=possible+1 /*count number of possible solutions. */
possible= possible + 1 /*count number of possible solutions. */
end /*k*/
end /*k*/


if possible==0 then say 'No solutions given for the information supplied.'
if possible==0 then say '═════════ There are no solutions for the information supplied.'
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
asker: arg ?; oops=0; Qprefix=copies('─', 9) '(question' ? "of" Q.0') '
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
do forever
if oops then do; say; say right(howTo,79); say; oops=0; end
if oops then do; say; say right(howTo, 79); say; oops= 0
end
say Qprefix Q.?; parse pull x /*ask question (after prompt)*/
x=strip(space(x),,'.'); parse upper var x u 1 u1 2 /*u1=1st character of answer.*/
say Qprefix Q.?; parse pull x /*ask question (after prompt)*/
if words(x)==0 then iterate /*Nothing entered? Try again.*/
x= strip(space(x), , .); parse upper var x u 1 u1 2 /*u1=1st character of answer.*/
if abbrev('QUIT',u,1) then exit /*user is tired of answering.*/
if words(x)==0 then iterate /*Nothing entered? Try again.*/
if (abbrev('YES',u) | abbrev("NO",u)) & words(x)==1 then return u1
if abbrev('QUIT', u,1) then exit /*user is tired of answering.*/
say 'invalid response: ' x; oops=1
if (abbrev('YES', u) | abbrev("NO", u)) & words(x)==1 then return u1
say 'invalid response: ' x; oops= 1
end /*forever*/</lang>
end /*forever*/</lang>
'''output''' &nbsp; (a screen scraping using a DOS prompt window for the possible responses)
{{out|output|text=&nbsp; (a screen scraping using a DOS prompt window for some of the possible responses):}}

DECISION.REX is the REXX program that produced this output.
('''decision.rex''' &nbsp; is the name of the REXX program that produced this output.)
<pre style="height:50ex">
<pre style="height:50ex">
D:\►rexx decision
D:\►rexx decision
Line 1,819: Line 1,820:
n
n


No solutions given for the information supplied.
═════════ There are no solutions for the information supplied.


D:\►rexx decision
D:\►rexx decision
Line 1,829: Line 1,830:
yes
yes


Ensure printer software is installed.
═════════ Ensure printer software is installed.


D:\►rexx decision
D:\►rexx decision
Line 1,839: Line 1,840:
n
n


Check/replace ink.
═════════ Check/replace ink.


D:\►rexx decision
D:\►rexx decision
Line 1,849: Line 1,850:
yes
yes


Ensure printer software is installed.
═════════ Ensure printer software is installed.
Check/replace ink.
═════════ Check/replace ink.


D:\►rexx decision
D:\►rexx decision
Line 1,860: Line 1,861:
no
no


Check for paper jam.
═════════ Check for paper jam.


D:\►rexx decision
D:\►rexx decision
Line 1,870: Line 1,871:
y
y


Check the power cable.
═════════ Check the power cable.
check the printer-computer cable.
═════════ check the printer-computer cable.
Ensure printer software is installed.
═════════ Ensure printer software is installed.


D:\►rexx decision
D:\►rexx decision
Line 1,882: Line 1,883:
n
n


Check/replace ink.
═════════ Check/replace ink.
Check for paper jam.
═════════ Check for paper jam.


D:\►rexx decision
D:\►rexx decision
Line 1,893: Line 1,894:
y
y


check the printer-computer cable.
═════════ check the printer-computer cable.
Ensure printer software is installed.
═════════ Ensure printer software is installed.
Check/replace ink.
═════════ Check/replace ink.


D:\►
D:\►