options=ToString[SetOptions[EvaluationNotebook[],PrivateNotebookOptions->{"PluginToolbarEnabled"->False}];,InputForm]<>"\n";

CHANGE THE DIRECTORY NAME:

libLIST=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Test/libLIST.m"]<>"\n";
libNAMES=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Test/libNAMES.m"]<>"\n";
libIO=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Test/libIO.m"]<>"\n";
libERR=ReadString["C:/mathematica/Work/lossofgenerality/TRSM/TRSM Test/libERR.m"]<>"\n";

Make data column for each question in the database. The English text for the problem is also in the data:

data1="\n"<>"textfghjkl:="<>ToString[
{"fghjkl"<>".ToString[\"At @e, the ratio of @g sold to @f in a particular day is #a:#b. If #c @f were sold one day, how many @g were sold?\"]",
"fghjkl"<>".ToString[\"The ratio of @g sold to @f in a particular day is #a:#b, at @e. If #c @f were sold one day, how many @g were sold?\"]",
"fghjkl"<>".ToString[\"At @e, #a:#b is the ratio for @g sold to @f. If #c @f were sold, how many @g were sold?\"]",
"fghjkl"<>".ToString[\" #a:#b is the ratio for @g sold to @f, at @e. If #c @f were sold, how many @g were sold?\"]"},InputForm]<>";\n ";

(*Separate the data into pieces so the pecualities could be handeled e.g. geographic are specific names and data *)
data2="listfghjkl:="<>ToString[{{{"iPAD 2 tablets", "BlackBerry tablets", "Microsoft Stylus", "Sony Play Stations"},{"BestBuy", "Future Shop","Canadian Tire"}},
{{"Turkeys","Chickens", "Sacks of Rice", "Vinegar Bottles"},{"Dominion", "No Frills"}},
{{"Tires","Ski Jackets", "Winter Boots", "Snow Blowers"},{"Canadian Tire", "Sears"}}},InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];
ToExpression[data][[1]]
ToExpression[data][[2]]
(* ToExpression gets back the stringed expression *)
StringQ/@ToExpression[data]

These should be written into the database but <>data1<>data2<> needs to be concatenated separately in case the local data is changed for this case:

(* the lib and data needs to be concatenated for ToExpression work correctly*)
variation1=(*lib<>*)ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, vars,text,list,sol,question},  


list=qRandList[listfghjkl];
text=qRandList[textfghjkl];

{cc,dd}=qRandList[{nLetters[{"a","z"},2]/.{"l"->"L"},nLetters[{"α","ω"},2]/.{"π"->"A"}}];
{aa,bb}=nIntegers[not0/@Range[2,10],2];
cc=ToString[ToExpression[bb]*RandomInteger[{2,5}]];
{hh, ii}=ToString/@RandomInteger[{2,5},2];

vars={aa,bb,cc,dd,hh,ii};
sol=ToString[Simplify[ToExpression[cc]*ToExpression[aa]/ToExpression[bb]]]; 

{ff,gg}=noRepeats[qRandList[list[[1]]],list[[1]],2];
ee=qRandList[list[[2]]];

question=StringReplace[text, {"@c"->cc, "@d"->dd, "#a"->aa, "#b"->bb, "#c"->cc, "@g"->gg, "@f"->ff,"@e"->ee,"#h"->hh,"#i"->ii,"#j"->ToString[ToExpression[hh]+1],"#k"->ToString[ToExpression[ii]+2]}]; 

{{question," "},{vars}, {sol}}
]],InputForm]<>"\n ";



solution1=(*lib<>*)data1<>data2<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},



{aa,bb,cc,dd,hh,ii}=vars[[1]]; 

sol=Simplify[ToExpression[cc]*ToExpression[aa]/ToExpression[bb]];

body={ 
{ToString[aa/bb,TraditionalForm]<>" = "<>ToString["x"/cc,TraditionalForm],
ToString[bb,TraditionalForm]<>" x"<>" = "<>ToString[ToString[cc,TraditionalForm]<>"("<>ToString[aa,TraditionalForm]<>")",TraditionalForm],
"x = "<>ToString[(ToString[ToString[cc,TraditionalForm]<>"("<>ToString[aa,TraditionalForm]<>")",TraditionalForm])/bb,TraditionalForm],
(*"Use the criss-cross formula "<>ToString["a"/"b",TraditionalForm]<>"="<>ToString["c"/"x",TraditionalForm]<>"⟹ x="<>ToString["bc"/"a",TraditionalForm],*)
"x ="<>ToString[(ToString[Simplify[ToExpression[cc]*ToExpression[aa]],TraditionalForm])/bb,TraditionalForm],
"x ="<>ToString[sol,TraditionalForm]},
{Null ,Null, Null,Null,Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint1=(*lib<>*)ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},


body={
{"Use cross multiplication: "<>ToString["a"/"b",TraditionalForm]<>"="<>ToString["x"/"c",TraditionalForm]<>"⟹ x="<>ToString["ac"/"b",TraditionalForm], 
"",
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data="\n"<>"textfghjkl:="<>ToString[
{"Column[{fghjkl"<>".ToString[\"Solve for @a:\"]"<>","<>"ToString[\"#b@a-#c(#a-#d)=#e-#g@a\",TraditionalForm]}]",
"Column[{fghjkl"<>".ToString[\"Find the value for @a:\"]"<>","<>"ToString[\"#b@a-#c(#a-#d)=#e-#g@a\",TraditionalForm]}]"},InputForm]<>";\n ";

variation2=data<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, vars,text,list,sol},


text=qRandList[textfghjkl];

{aa}=qRandList[{nLetters[{"a","z"},1]/.{"l"->"L"},nLetters[{"α","ω"},1]/.{"π"->"A"}}];
(* bb*m +cc*(m-dd)=ee-gg*m *)
{bb,cc,dd,ee,gg}=nIntegers[not0/@Range[2,10],5];


vars={aa,bb,cc,dd,ee,gg};
sol=Solve[ToExpression[bb]*x-ToExpression[cc]*(x-ToExpression[dd])==ToExpression[ee]-ToExpression[gg]*x,x];



{StringReplace[text, {"#c"->cc, "#d"->dd, "#a"->aa, "@a"->aa,"#b"->bb, "#c"->cc, "#g"->gg, "#e"->ee}],vars,If[Length[sol]≠0,ToString[x/.sol[[1]],InputForm], "No Solution"]} (* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution2=data<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},



{aa,bb,cc,dd,ee,gg}=vars;
sol=Solve[ToExpression[bb]*x-ToExpression[cc]*(x-ToExpression[dd])==ToExpression[ee]-ToExpression[gg]*x,x];




body={
{If[Length[sol]≠0,ToString[x/.sol[[1]],InputForm], "No Solution"],
" ",
" "},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint2=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},


body={
{"Use the criss-cross formula ",
"",
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data="\n"<>"textfghjkl:="<>ToString[{
{"Column[{ToString[\"fghjkl. Answer the following:\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]","Column[{ToString[\"fghjkl. Answer each question:\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},

{"Column[{ToString[\"FGHJKLabc)Solve for @a:\"]"<>","<>"ToString[\"#b@a-#c(#a-#d)=#e-#g@a\",TraditionalForm]}]",
"Column[{ToString[\"FGHJKLabc)Find the value for @a:\"]"<>","<>"ToString[\"#b@a-#c(#a-#d)=#e-#g@a\",TraditionalForm]}]"},

{"Column[{ToString[\"FGHJKLabc)Solve for @g and @h\",TraditionalForm]"<>","<>
"Column[{
If[ToExpression[\"#b\"]>=0,
ToString[\"#a @g + #b @h = #c\",TraditionalForm],
ToString[\"#a @g #b @h = #c\",TraditionalForm]
]
,
If[ToExpression[\"#e\"]>=0,
ToString[\"#d @g + #e @h = #f\",TraditionalForm],
ToString[\"#d @g #e @h = #f\",TraditionalForm]
]
}]"<>"}]"},

{"Column[{ToString[\"FGHJKLabc)Solve for @g: \",TraditionalForm]"<>","<>"If[ToExpression[\"#d\"]>=0,
ToString[ToString[(\"#a @g\")/(\"#b \"),TraditionalForm]<>\" = \"<>ToString[(\"(#c @g-#d)\")/\"#e\",TraditionalForm],TraditionalForm],
ToString[ToString[(\"#a @g\")/(\"#b \"),TraditionalForm]<>\" = \"<>ToString[(ToString[\"#c @g + \"<>ToString[Abs[ToExpression[#d]],TraditionalForm],TraditionalForm])/\"#e\",TraditionalForm],TraditionalForm]
]"<>"}]"}  
},InputForm]<>";\n ";

variation3=data<>ToString[Hold[Module[{p,x,a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, vars,text,list,sol, parta, partb, partc, partd,question},


question=qRandList[textfghjkl[[1]]];

text=qRandList[textfghjkl[[2]]];

{aa}=qRandList[{nLetters[{"a","z"},1]/.{"l"->"L"},nLetters[{"a","z"},1]/.{"l"->"L"}}]; 
(* bb*m +cc*(m-dd)=ee-gg*m *)
{bb,cc,dd,ee}=nIntegers[not0/@Range[2,10],4];

(* use String@ to conver to String for 1 number, String/@{...} to covert a list *)
gg=ToString@(Abs[-ToExpression[bb]+ToExpression[cc]]+RandomInteger[{1,3}]);
vars={aa,bb,cc,dd,ee,gg};
sol=Solve[ToExpression[bb]*x-ToExpression[cc]*(x-ToExpression[dd])==ToExpression[ee]-ToExpression[gg]*x,x];



parta={StringReplace[text, {"#c"->cc, "#d"->dd, "#a"->aa, "@a"->aa,"#b"->bb, "#c"->cc, "#g"->gg, "#e"->ee}],vars,If[Length[sol]≠0,ToString[x/.sol[[1]],InputForm], "No Solution"]} ;


(*b*)
text=qRandList[textfghjkl[[3]]];

{g,h}=qRandList[{nLetters[{"a","z"},2]/.{"l"->"L"},nLetters[{"a","z"},2]/.{"l"->"L"}(*nLetters[{"α","ω"},2]/.{"π"->"A"}*)}]; 

p={1(*aa*),1(*ee*),1(*bb*),1(*dd*)};
(*CRAMER'S RULE: determinant of matrix: aa*ee - bb*dd*) 
While[p[[1]]*p[[2]]-p[[3]]*p[[4]]==0,p={not0[RandomInteger[{-10,10}]],not0[RandomInteger[{-10,10}]],not0[RandomInteger[{-10,10}]],not0[RandomInteger[{-10,10}]]}];
{aa,ee,bb,dd}=ToString/@p;

(*aa=ToString[not0[RandomInteger[{-10,10}]]];
bb=ToString[not0[RandomInteger[{-10,10}]]];
dd=ToString[not0[RandomInteger[{-10,10}]]];
ee=ToString[not0[RandomInteger[{-10,10}]]];*)
gg=ToString[not0[RandomInteger[{-10,10}]]];
hh=ToString[not0[RandomInteger[{-10,10}]]];
cc=ToString[ToExpression[aa]*ToExpression[gg]+ToExpression[bb]*ToExpression[hh]];
ff=ToString[ToExpression[dd]*ToExpression[gg]+ToExpression[ee]*ToExpression[hh]];

vars={aa,bb,cc,dd,ee,ff,gg,hh,g,h};

partb={StringReplace[text, {"#c"->cc, "#d"->dd, "#a"->aa, "@g"->g,"@h"->h,"#b"->bb,   "#e"->ee,"#f"->ff,"#h"->hh}],vars,ToString[{ToExpression[gg],ToExpression[hh]},InputForm]} ;


(*c*)
text=qRandList[textfghjkl[[4]]];

{g}=qRandList[{nLetters[{"a","z"},1]/.{"l"->"L"},nLetters[{"a","z"},1]/.{"l"->"L"}}]; 


Off[Infinity::indet];



bb=ToString[not0[RandomInteger[{-5,5}]]];
ee=ToString[not0[RandomInteger[{-10,10}]]];
cc=ToString[not0[RandomInteger[{-5,5}]]];
aa=ToString[ToExpression[bb]*ToExpression[cc]*not0[RandomInteger[{2,3}]]]; 

dd=ToString[(-ToExpression[cc]+(ToExpression[aa]*ToExpression[ee]/ToExpression[bb]))*not0[RandomInteger[{-3,3}]]];
gg=Which[(-ToExpression[bb]*ToExpression[dd])==0&&(ToExpression[aa]*ToExpression[ee]-ToExpression[bb]*ToExpression[cc])≠0,"Infinity",
(-ToExpression[bb]*ToExpression[dd])==0&&(ToExpression[aa]*ToExpression[ee]-ToExpression[bb]*ToExpression[cc])==00, "Indeterminate",

True,ToString[Simplify[(-ToExpression[bb]*ToExpression[dd])/(ToExpression[aa]*ToExpression[ee]-ToExpression[bb]*ToExpression[cc])],InputForm]
]; 

vars={aa,bb,cc,dd,ee,gg,g,h};

partc={StringReplace[text, {"#c"->cc, "#d"->dd, "#a"->aa, "@g"->g,"#b"->bb,   "#e"->ee}],vars,gg} ;

{{question,parta[[1]], partb[[1]],partc[[1]]},{parta[[2]], partb[[2]],partc[[2]]}, {parta[[3]], partb[[3]],partc[[3]]}}

(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution3=data<>ToString[Hold[Module[{x, aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,g,h},





varsa=vars[[1]];
varsb=vars[[2]];
varsc=vars[[3]];

{aa,bb,cc,dd,ee,gg}=varsa;
sol=Solve[ToExpression[bb]*x-ToExpression[cc]*(x-ToExpression[dd])==ToExpression[ee]-ToExpression[gg]*x,x];



body={
{options[[1]]<>": \n"<>If[Length[sol]≠0,
(*1*)ToString[bb*aa-cc*(aa-dd),TraditionalForm]<>" = "<>ToString[ee-gg*aa,TraditionalForm]<>"\n "<>
(*2*)ToString[bb*aa-cc*aa,TraditionalForm]<>" + "<>ToString[ToExpression[cc]*ToExpression[dd],TraditionalForm]<>" = "<>ToString[ee-gg*aa,TraditionalForm]<>"\n "<>
(*3*)ToString[ToString[bb*aa,TraditionalForm]<>" - "<>ToString[ cc*aa,TraditionalForm]<>" + "<>ToString[gg*aa,TraditionalForm],TraditionalForm]<>" = "<>ToString[ee,TraditionalForm]<>"-"<>ToString[ToExpression[cc]*ToExpression[dd],TraditionalForm]<>"\n "<>
(*4*)ToString[(ToExpression[bb]-ToExpression[cc] + ToExpression[gg])*aa,TraditionalForm]<>" = "<>ToString[ToExpression[ee]-ToExpression[cc]*ToExpression[dd],TraditionalForm]<>"\n "<>
(*5*)If[(ToExpression[bb]-ToExpression[cc] +ToExpression[gg])== 1  ," ",ToString[aa,TraditionalForm]<>" = "<> ToString[(ToString[ToExpression[ee]-ToExpression[cc]*ToExpression[dd],TraditionalForm])/(ToString[ToExpression[bb]-ToExpression[cc] +ToExpression[gg],TraditionalForm]),TraditionalForm]]<>"\n "<>
(*6*)If[Numerator[x/.sol[[1]]]≠0,If[Numerator[x/.sol[[1]]]≠  (ToExpression[ee]-ToExpression[cc]*ToExpression[dd]),ToString[aa,TraditionalForm]<>" = "<>ToString[x/.sol[[1]],TraditionalForm]<>"\n",""],ToString[aa,TraditionalForm]<>" = 0"]
, "No Solution"],

(*b*)
{aa,bb,cc,dd,ee,ff,gg,hh,g,h}=varsb; 
options[[2]]<>": \n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>If[ToExpression[bb]>0," + ",""]<>ToString[bb,TraditionalForm]<>ToString[h,TraditionalForm]<>" = "<>ToString[cc,TraditionalForm]<>"·····1 \[Cross] "<>ToString[dd,TraditionalForm]<>"\n"<>
ToString[dd,TraditionalForm]<>ToString[g,TraditionalForm]<>If[ToExpression[ee]>0," + ",""]<>ToString[ee,TraditionalForm]<>ToString[h,TraditionalForm]<>" = "<>ToString[ff,TraditionalForm]<>"·····2 \[Cross] "<>ToString[aa,TraditionalForm]<>"\n"
ToString[ToExpression[dd]*ToExpression[aa],TraditionalForm]<>ToString[g,TraditionalForm]<>If[(ToExpression[dd]*ToExpression[bb])>0," + ",""]<>ToString[ToExpression[dd]*ToExpression[bb],TraditionalForm]<>ToString[h,TraditionalForm]<>" = "<>ToString[ToExpression[dd]*ToExpression[cc],TraditionalForm]<>"·····1"<>"\n"<>
ToString[ToExpression[aa]*ToExpression[dd],TraditionalForm]<>ToString[g,TraditionalForm]<>If[(ToExpression[aa]*ToExpression[ee])>0," + ",""]<>ToString[ToExpression[aa]*ToExpression[ee],TraditionalForm]<>ToString[h,TraditionalForm]<>" = "<>ToString[ToExpression[aa]*ToExpression[ff],TraditionalForm]<>"·····2"<>"\n"<>
"Substraction: 1 - 2 : \n"<>
ToString[ToExpression[dd]*ToExpression[bb]-ToExpression[aa]*ToExpression[ee],TraditionalForm]<>ToString[h,TraditionalForm]<>" = "<>ToString[ToExpression[dd]*ToExpression[cc] -ToExpression[aa]*ToExpression[ff] ,TraditionalForm]<>"\n"<>
ToString[h,TraditionalForm]<>" = "<>ToString[hh,TraditionalForm]<>"\n\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>If[ToExpression[bb]>0," + ",""]<>ToString[bb,TraditionalForm]<>"("<>ToString[hh(*gg*),TraditionalForm]<>") = "<>ToString[cc,TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>ToString[cc,TraditionalForm]<>If[ToExpression[hh]*ToExpression[bb]>0," - "," + "]<>ToString[Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>If[ToExpression[hh]*ToExpression[bb]>0,ToString[ToExpression[cc]-Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm],ToString[ToExpression[cc]+Abs[ToExpression[hh]*ToExpression[bb]],TraditionalForm]]<>"\n"<>
ToString[g,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]<>"\n\n"<>
ToString[g,TraditionalForm]<>", "<>ToString[h,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]<>" "<>ToString[hh,TraditionalForm]<>"\n",  

(*c*)
{aa,bb,cc,dd,ee,gg,g,h}=varsc; 
options[[3]]<>": \n"<>
ToString[(ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm])/ToString[bb,TraditionalForm],TraditionalForm]<>" = "<>ToString[(ToString[cc*g,TraditionalForm]<>If[ToExpression[dd]>0," - "<>ToString[dd,TraditionalForm]," + "<>ToString[Abs[ToExpression[dd]],TraditionalForm]])/(ToString[ee,TraditionalForm]),TraditionalForm]<>"\n"<>
ToString[ee,TraditionalForm]<>"("<>ToString[aa,TraditionalForm]<>ToString[g,TraditionalForm]<>") = "<>ToString[bb,TraditionalForm]<>"("<>ToString[cc*g,TraditionalForm]<>If[ToExpression[dd]>0," - "<>ToString[dd,TraditionalForm]," + "<>ToString[Abs[ToExpression[dd]],TraditionalForm]]<>")\n"<>
(*3*)
ToString[ToExpression[ee]*ToExpression[aa],TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>ToString[ToExpression[cc]*ToExpression[bb],TraditionalForm]<>ToString[g,TraditionalForm]<>If[(ToExpression[dd]>0 && ToExpression[bb]>0)||(ToExpression[bb]<0 && ToExpression[dd]<0)," - "<>ToString[Abs[ToExpression[bb]*ToExpression[dd]],TraditionalForm]," + "<>ToString[Abs[ToExpression[bb]*ToExpression[dd]],TraditionalForm]]<>"\n"<>
(*4*)
ToString[ToExpression[ee]*ToExpression[aa]-ToExpression[cc]*ToExpression[bb],TraditionalForm]<>ToString[g,TraditionalForm]<>" = "<>If[(ToExpression[dd]>0 && ToExpression[bb]>0)||(ToExpression[bb]<0 && ToExpression[dd]<0)," - "<>ToString[Abs[ToExpression[bb]*ToExpression[dd]],TraditionalForm],ToString[Abs[ToExpression[bb]*ToExpression[dd]],TraditionalForm]]<>"\n"<>
ToString[g,TraditionalForm]<>" = "<>ToString[gg,TraditionalForm]}, 
{Null ,Null, Null} 
};


Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint3=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},  


body={ 
{options[[1]]<>": \n"<>"Expand and collect like terms.\nVariables on one side = Number of on the other\n", 
options[[2]]<>": \n"<>"Use Method of Substitution or Method of Elimination.\n",
options[[3]]<>": \n"<>"Use either cross-multiplication or find the common denominator of the two terms.\n"},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data="\n"<>"textfghjkl:="<>ToString[{

(* top question*)
{"Column[{ToString[\"fghjkl. The formula for the monthly profit, @a,is written in terms of the number of customers, @b,and
the amount spent on @c, @d, and is given by the formula, @a = #e @b - \",TraditionalForm]<>ToString[ (\"@d\"/\"#f\"),TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"}, 

(*a*)
{"Column[{ToString[\"FGHJKLabc)In @g, the amount spent on @c was $#d and the profit was $#a. How many customers were there in @g\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},


(*b*)
{"Column[{ToString[\"FGHJKLabc)In @h, the @c budget increased by #i% from @g and the profit decreased by #j%. Determine the number of customers they had in @h.\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},

(*c*)
{"Column[{ToString[\"FGHJKLabc)Determine the percentage increase or decrease in the number of customers from @g to @h (round percent to two decimal places)\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},


(*d*)
{"Column[{ToString[\"FGHJKLabc)In @k, the advertising budget was $100 000. Find the number of customers required for the company to break-even in @k? If necessary round your answer to the nearest person. \",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"} 

},InputForm]<>";\n ";

variation4=data<>ToString[Hold[Module[{a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, vars,text,list,sol, parta, partb, partc, partd,question,b2},


question=qRandList[textfghjkl[[1]]];

text=qRandList[textfghjkl[[2]]];

(* aa for names, a for values *)
{aa,bb, dd}=qRandList[{nLetters[{"a","z"},3]/.{"l"->"L"},nLetters[{"A","Z"},3]}];
gg=qRandList[qMonths];
hh=qMonths[[not0[Mod[Position[qMonths,gg][[1]][[1]]+1,13]]]];
kk=qMonths[[not0[Mod[Position[qMonths,gg][[1]][[1]]+2,13]]]];
cc= qRandList[{"advertising", "online marketing", "print advertisement", "advertisement", "tele-marketing","banner ads"}];
{a,b,f}={ToString[RandomInteger[{1,10}]*10000],ToString[RandomInteger[{2,5}]*5000],ToString[RandomInteger[{2, 5}]]};
e=qRandList[{ToString[20],ToString[50],ToString[100],ToString[10]}];

d=ToString[ToExpression[f]*(ToExpression[e]*ToExpression[b]-ToExpression[a])];

vars={aa,bb,cc,dd,gg,a,b,d, e, f};

question=StringReplace[question, {"@a"->aa, "@b"->bb, "@c"->cc, "@d"->dd, "@g"->gg,"#a"->a,"#b"->b, "#c"->c,"#d"->d, "#e"->e, "#f"->f}];

parta={StringReplace[text, {"@a"->aa, "@b"->bb, "@c"->cc, "@d"->dd, "@g"->gg,"#a"->a,"#b"->b, "#c"->c,"#d"->d, "#e"->e, "#f"->f}],vars,b} ;


(* part b*)
text=qRandList[textfghjkl[[3]]];
i=ToString[RandomInteger[{1,10}]];
j=ToString[RandomInteger[{1,30}]];

b2=ToString[(ToExpression[a]*(1-(ToExpression[j]/100))*ToExpression[f]+(ToExpression[d]*(1+(ToExpression[i]/100))))/(ToExpression[e]*ToExpression[f])];
vars={aa,bb,cc,dd,gg,hh,a,b,d, e, f,i,j,b2};

partb={StringReplace[text, {"@a"->aa, "@b"->bb, "@c"->cc, "@d"->dd, "@g"->gg,"@h"->hh,"#a"->a,"#b"->b, "#c"->c,"#d"->d, "#e"->e, "#f"->f,"#i"->i,"#j"->j}],vars,b2} ;


(* part c*)
text=qRandList[textfghjkl[[4]]];

vars={aa,bb,cc,dd,gg,hh,a,b,d, e, f,i,j,b2,ToString[N[100*(ToExpression[b2]-ToExpression[b])/ToExpression[b]]]};

partc={StringReplace[text, {"@a"->aa, "@b"->bb, "@c"->cc, "@d"->dd, "@g"->gg,"@h"->hh,"#a"->a,"#b"->b, "#c"->c,"#d"->d, "#e"->e, "#f"->f,"#i"->i,"#j"->j}],vars,ToString[N[100*(ToExpression[b2]-ToExpression[b])/ToExpression[b]]]} ;



(* part d*)
text=qRandList[textfghjkl[[5]]];



d=ToString[N[((100000)/(ToExpression[f]*ToExpression[e]))]];



vars={aa,bb,cc,dd,gg,hh,a,b,d, e, f,i,j,kk};

partd={StringReplace[text, {"@a"->aa, "@b"->bb, "@c"->cc, "@d"->dd, "@g"->gg,"@h"->hh,"#a"->a,"#b"->b, "#c"->c,"#d"->d, "#e"->e, "#f"->f,"#i"->i,"#j"->j,"@k"->kk}],vars,d} ;

{{question,parta[[1]], partb[[1]],partc[[1]],partd[[1]]},{parta[[2]], partb[[2]],partc[[2]],partd[[2]]}, {parta[[3]], partb[[3]],partc[[3]],partd[[3]]}}



(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution4=data<>ToString[Hold[Module[{a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,b2,b3},



varsa=vars[[1]];
varsb=vars[[2]];
varsc=vars[[3]];
varsd=vars[[4]];

{aa,bb,cc,dd,gg,a,b,d, e, f}=varsa;



body={
{options[[1]]<>": \n"<>ToString[aa]<>"="<>ToString[a]<>"\n"<>
ToString[dd]<>" = "<>ToString[d]<>"\n\n"<>
ToString[a]<>" = "<>ToString[e*bb]<>"-"<>ToString[d/f,TraditionalForm]<>"\n"<>
ToString[a]<>" + "<>ToString[ToExpression[d]/ToExpression[f],TraditionalForm]<>" = "<>ToString[e*bb]<>"\n"<>ToString[(ToExpression[a]+(ToExpression[d]/ToExpression[f]))/ToString[e,TraditionalForm],TraditionalForm]<>" = "<>ToString[bb,TraditionalForm]<>"\n"<>
ToString[bb,TraditionalForm]<>" = "<>ToString[b]<>" customers\n",

{aa,bb,cc,dd,gg,hh,a,b,d, e, f,i,j,b2}=varsb;
options[[2]]<>":\n"<>
ToString[hh]<>" - Advertising"<>"\n"<> 
ToString[d]<>"("<>ToString[N[(1+ToExpression[i]/100)],TraditionalForm]<>") = "<>ToString[ToExpression[d]*(1+ToExpression[i]/100),TraditionalForm]<>"\n"<>
ToString[hh]<>" - Profit"<>"\n"<>
ToString[a]<>"("<>ToString[N[(1-ToExpression[j]/100)],TraditionalForm]<>") = "<> ToString[ToExpression[a]*(1-ToExpression[j]/100),TraditionalForm]<>"\n\n"<>
ToString[ToExpression[a]*(1-ToExpression[j]/100),TraditionalForm]<>" = "<>ToString[e*bb]<>"-"<>ToString[(ToExpression[d]*(1+ToExpression[i]/100))/f,TraditionalForm]<>"\n"<>
ToString[ToExpression[a]*(1-ToExpression[j]/100),TraditionalForm]<>" + "<>ToString[(ToExpression[d]*(1+ToExpression[i]/100))/ToExpression[f],TraditionalForm]<>" = "<>ToString[e*bb]<>"\n"<>
ToString[((ToExpression[a]*(1-ToExpression[j]/100))+(ToExpression[d]*(1+ToExpression[i]/100))/ToExpression[f] )/ e,TraditionalForm]<>" = "<>ToString[bb]<>"\n"<>
ToString[bb]<>" = "<>ToString[b2]<>" customers\n",

{aa,bb,cc,dd,gg,hh,a,b,d, e, f,i,j,b2,b3}=varsc;
options[[3]]<>":\n"<>If[ToExpression[b3]≥ 0,"Percentage  increase ","Percentage decrease "]<>" \n "<>ToString[(b2 - b)/b,TraditionalForm]<>" × 100% =\n = "<>ToString[qTrunc6[ToExpression[b3]]]<>" %\n",   

{aa,bb,cc,dd,gg,hh,a,b,d, e, f,i,j,kk}=varsd;
options[[4]]<>":\n"<>
ToString[dd]<>" = 100 000\n"<> 
ToString[aa]<>" = 0\n\n"<>
"0 = "<>ToString[e*bb]<>" - "<>ToString["100 000"/f,TraditionalForm]<>"\n"<>
ToString[e*bb]<>" = "<>ToString["100000"/ToExpression[f],TraditionalForm]<>"\n"<> 
ToString[bb]<>" = "<>ToString[("100000")/(ToExpression[f]*ToExpression[e]),TraditionalForm]<>"\n"<>
ToString[bb]<>" = "<>ToString[qTrunc7[ToExpression[d]],TraditionalForm]<>" customers to break-even"},
{Null ,Null, Null,Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint4=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},


body={ 
{options[[1]]<>": \n"<>"Identify which variables are given and which is the unknown.\n",
options[[2]]<>": \n"<>"Given percent increase/decrease:\n Final amount = original amount (1 + "<>ToString[("increase")/"100",TraditionalForm]<>")\n"<> "Final amount = original amount (1 - "<>ToString[("decrease")/"100",TraditionalForm]<>")\n", 
options[[3]]<>": \n"<>"Percent increase/decrease = "<>ToString[("final - original")/"original",TraditionalForm]<>" × 100%\n", 
options[[4]]<>": \n"<>"Break even means set profit = 0.\n"},
{Null ,Null, Null,Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data1="\n"<>"textfghjkl:="<>ToString[
{"fghjkl"<>".ToString[\"The ratio of @g to @f in a @e is #a:#b. If there are #c @f were sold one day, determine the number of @g?\"]",
"fghjkl"<>".ToString[\"In a @e, #a:#b is the ratio of @g to @f.  If #c @f, then how many @g? \"]"},InputForm]<>";\n ";

(*Separate the data into pieces so the pecualities could be handeled e.g. geographic are specific names and data *)
data2="listfghjkl:="<>ToString[{{{"people with winning tickets", "losing tickets"},{"lottery","dog race"}},
{{"winning bets", "losing bets"},{"casino","kino shop"}},
{{"Pass students","Fail students"},{"examination","road test"}}},InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];
(*ToExpression[data][[1]]
ToExpression[data][[2]]
(* ToExpression gets back the stringed expression *)
StringQ/@ToExpression[data]*)


(* the lib and data needs to be concatenated for ToExpression work correctly*)
variation5=(*lib<>*)ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, vars,text,list,sol,question},


list=qRandList[listfghjkl];
text=qRandList[textfghjkl];

{cc,dd}=qRandList[{nLetters[{"a","z"},2]/.{"l"->"L"},nLetters[{"α","ω"},2]/.{"π"->"A"}}];
{aa,bb}=nIntegers[not0/@Range[2,10],2];
cc=ToString[ToExpression[bb]*RandomInteger[{2,5}]];
{hh, ii}=ToString/@RandomInteger[{2,5},2];

vars={aa,bb,cc,dd,hh,ii};
sol=Simplify[ToExpression[cc]*ToExpression[aa]/ToExpression[bb]];

{ff,gg}=noRepeats[qRandList[list[[1]]],list[[1]],2];
ee=qRandList[list[[2]]];

question=StringReplace[text, {"@c"->cc, "@d"->dd, "#a"->aa, "#b"->bb, "#c"->cc, "@g"->gg, "@f"->ff,"@e"->ee,"#h"->hh,"#i"->ii,"#j"->ToString[ToExpression[hh]+1],"#k"->ToString[ToExpression[ii]+2]}]; 

 {{question," "},{vars}, {sol}} 
]],InputForm]<>"\n ";




solution5=data1<>data2<>ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},



{aa,bb,cc,dd,hh,ii}=vars[[1]]; 

sol=Simplify[ToExpression[cc]*ToExpression[aa]/ToExpression[bb]];

body={
{ToString[aa/bb,TraditionalForm]<>" = "<>ToString["x"/cc,TraditionalForm],
ToString[bb,TraditionalForm]<>" x"<>" = "<>ToString[ToString[cc,TraditionalForm]<>"("<>ToString[aa,TraditionalForm]<>")",TraditionalForm],
"x = "<>ToString[(ToString[ToString[cc,TraditionalForm]<>"("<>ToString[aa,TraditionalForm]<>")",TraditionalForm])/bb,TraditionalForm],
"x ="<>ToString[(ToString[Simplify[ToExpression[cc]*ToExpression[aa]],TraditionalForm])/bb,TraditionalForm],
"x ="<>ToString[sol,TraditionalForm]},
{Null,Null , Null,Null,Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint5=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},


body={
{"Use cross multiplication: "<>ToString["a"/"b",TraditionalForm]<>"="<>ToString["x"/"c",TraditionalForm]<>"⟹ x="<>ToString["ac"/"b",TraditionalForm], 
"",
""},
{Null ,Null, Null}
};


Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data1="\n"<>"textfghjkl:="<>ToString[
{"fghjkl"<>".ToString[\"At @e,the ratio of the number of @f sold to @g is #a:#b. If @p sells for $#f while the @q sells for $#g at this store and the combined revenue is $#i, determine the total number of @j sold.\"]",
"fghjkl"<>".ToString[\"The ratio #a:#b is the number of @f sold to @g. Determine the total number of @j sold, if @p sells for $#f while the @q sells for $#g at this store and the combined revenue is $#i.\"]"},InputForm]<>";\n ";

(*Separate the data into pieces so the pecualities could be handeled e.g. geographic are specific names and data *)
data2="listfghjkl:="<>

(*{specific name, abbriviated name, name of the type of thing, location name}*)

ToString[{{{"Xbox 360 home entertainment system", "Nintendo Wii home entertainment system"},{"Xbox 360", "Nintendo Wii"},{"home entertainment systems","video game consoles"},{"a certain store","Future Shop", "Circuit City"}},

{{"Car stereo system", "winter tires"},{"stereo", "tires"},{"these car parts","these accessories"},{"a certain store","Jiffy Lube", "Sears"}}
},InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];



(* the lib and data needs to be concatenated for ToExpression work correctly*)
variation6=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{a,b,c,d,i,f,g,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, vars,text,list,sol,sol1,question}, 


list=qRandList[listfghjkl];
text=qRandList[textfghjkl];

{a,b}=nIntegers[not0/@Range[2,10],2];
{f,g}={ToString[RandomInteger[{100,400}]],ToString[RandomInteger[{100,400}]]};
sol=RandomInteger[{300,500}];
sol1=ToString[ToExpression[b]*sol + ToExpression[a]*sol]; 
i=ToString[ToExpression[a]*ToExpression[sol]*ToExpression[f]+ToExpression[b]*ToExpression[sol]*ToExpression[g]];


{ff,gg}=noRepeats[qRandList[list[[1]]],list[[1]],2];
{pp,qq}=noRepeats[qRandList[list[[2]]],list[[2]],2];
jj=qRandList[list[[3]]];
ee=qRandList[list[[4]]];

vars={ff,gg,pp,qq,jj,ee,a,b,f,g,i,ToString@sol,sol1};

question=StringReplace[text, { "@f"->ff, "@g"->gg, "@p"->pp, "@q"->qq, "@j"->jj,"@e"->ee,"#a"->a,"#b"->b,"#f"->f,"#g"->g,"#i"->i}];

 {{question," "},{vars}, {sol1}} 
]],InputForm]<>"\n ";




solution6=data1<>data2<>ToString[Hold[Module[{a,b,f,g,i,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, text,list,sol, sol1,body={},vars=ertyuiop},


{ff,gg,pp,qq,jj,ee,a,b,f,g,i,sol,sol1}=vars[[1]];  


body={{"", 
makeTextTable[{{"","Actual # of items","Price/item","Total Revenue"},
{ToString[ff,TraditionalForm],ToString[ToExpression[a]*"x",TraditionalForm],ToExpression[f],ToString[ToExpression[f],TraditionalForm]<>"("<>ToString[ToExpression[a]*"x"]<>") = "<>ToString[(ToExpression[f]*ToExpression[a])*"x"]},
{ToString[gg,TraditionalForm],ToString[ToExpression[b]*"x",TraditionalForm],ToExpression[g],ToString[ToExpression[g],TraditionalForm]<>"("<>ToString[ToExpression[b]*"x"]<>") = "<>ToString[(ToExpression[g]*ToExpression[b])*"x"]},
{"Total"," "," ",ToExpression[i]}}], 
ToString[(ToExpression[f]*ToExpression[a])*"x"]<>" + "<>ToString[(ToExpression[g]*ToExpression[b])*"x"]<>" = "<>ToString[i,TraditionalForm]<>"\n"<>
ToString[(ToExpression[f]*ToExpression[a]+ ToExpression[g]*ToExpression[b])*"x"]<>" = "<>ToString[i,TraditionalForm]<>"\n"<>
"x"<>" = "<>ToString[(ToExpression[i])/(ToExpression[f]*ToExpression[a]+ ToExpression[g]*ToExpression[b]),TraditionalForm]<>"\n"<>
ToString[ff,TraditionalForm]<>"="<>ToString[ToString[ToExpression[a],TraditionalForm]<>"("<>ToString[sol,TraditionalForm]<>")",TraditionalForm]<>"="<>ToString[ToExpression[a]*ToExpression[sol],TraditionalForm]<>"\n"<> 
ToString[gg,TraditionalForm]<>"="<>ToString[ToString[ToExpression[b],TraditionalForm]<>"("<>ToString[sol,TraditionalForm]<>")",TraditionalForm]<>"="<>ToString[ToExpression[b]*ToExpression[sol],TraditionalForm]<>"\n"<>
"Total number: " ToString[sol1,TraditionalForm]},  
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint6=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol,sol1, body={},vars=ertyuiop},


body={ 
{"Set up the unit price number of item and revenue table",
ToString[Style[("Ratio")/("a:b"),20],TraditionalForm]<>"                 "<>ToString[Style[("Actual")/("ax:bx"),20],TraditionalForm],
""},
{Null ,Null, Null}
};
Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data1="\n"<>"textfghjkl:="<>ToString[
{"fghjkl"<>".ToString[\"Simple interest is used to calculate the amount of depreciation on a @a that was purchased for $#a on @b 1. Assuming that the annual rate of depreciation on this @a is #c%, determine the amount of depreciation on the @a for the remainder of the year. (Note that #d days have passed from January 1 to end of @b.)\"]",
"fghjkl"<>".ToString[\"On @b 1 a @a was purchased. Simple interest is used to calculate the amount of depreciation. Determine the amount of depreciation on the @a for the remainder of the year, assuming that the annual rate of depreciation on this @a is #c% , while #d days have passed from January 1 to end of @b.\"]"},InputForm]<>";\n "; 

(*Separate the data into pieces so the pecualities could be handeled e.g. geographic are specific names and data *)
data2="listfghjkl:="<>

(*{specific name, abbriviated name, name of the type of thing, location name}*)

ToString[{"car","motorcycle", "boat", "SUV"


},InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];


variation7=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{a,b,c,d,i,f,g,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, vars,text,list,sol,question},


aa=qRandList[listfghjkl];
text=qRandList[textfghjkl];

{a,b, c}=ToString/@{RandomInteger[{2,5}]*10000, RandomInteger[{3,7}], RandomInteger[{15,25}]};
d = ToString[30*ToExpression[b]]; 
sol=ToString[N[ToExpression[a]*(ToExpression[c]/100)*((365-30*ToExpression[b])/365)]]; 

bb=qMonths[[ToExpression[b]]];

vars={aa,bb,a,b,c,d, sol};

question=StringReplace[text, { "@a"->aa,"@b"->bb,"#a"->a,"#b"->b,"#c"->c,"#d"->d}]; 

{{question," "},{vars}, {sol}}  
]],InputForm]<>"\n ";




solution7=data1<>data2<>ToString[Hold[Module[{a,b,c,f,g,i,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, text,list,sol, body={},vars=ertyuiop,d},




{aa,bb,a,b,c,d, sol}=vars[[1]]; 


body={
{"", 
"I = "<>ToString[ToExpression[a],TraditionalForm]<>"("<>ToString[N[(ToExpression[c]/100)],TraditionalForm] <>")"<>"("<>ToString[(365-30*ToExpression[b])/ToString["365",TraditionalForm],TraditionalForm]<>")",
"I = "<>ToString[qTrunc6[ToExpression[sol]],TraditionalForm]},   
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint7=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},


body={
{"", 
"I= P r t", 
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data1="\n"<>"textfghjkl:="<>ToString[
{"fghjkl"<>
".ToString[\"@e invested $#a in @c for @d years. At the end of the investment period, the @c were worth $#b. Find the annual rate of compound interest earned on the @c. (Write your answer as a percent rounded to two decimal places.)\"]",
"fghjkl"<>".ToString[\"Find the annual rate of compound interest earned on @c, principal $#a for @d years, at the end of the investment period, the @c were worth $#b.(Write your answer as a percent rounded to two decimal places.) \"]"},InputForm]<>";\n "; 

(*Separate the data into pieces so the pecualities could be handeled e.g. geographic are specific names and data *)
data2="listfghjkl:="<>

(*{specific name, abbriviated name, name of the type of thing, location name}*)

ToString[{"bonds","government bons", "corporate bonds", "callable bonds", "savings bonds"


},InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];


(* the lib and data needs to be concatenated for ToExpression work correctly*)
variation8=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{a,b,c,d,i,f,g,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, vars,text,list,sol,r,question}, 


cc=qRandList[listfghjkl];
text=qRandList[textfghjkl];

ee=qRandList[qNamesList][[1]];

{a,d}=ToString/@{RandomInteger[{2,5}]*10000, RandomInteger[{2,10}]};
b=ToString[ToExpression[a]+RandomInteger[{3,9}]*1000];

dd=IntegerName[ToExpression[d]];

sol=NSolve[ToExpression[b]==ToExpression[a]*(1+r)^ToExpression[d], r,Reals];
sol=ToString[Max[r/.sol]];


vars={cc,dd,ee,a,b,d,sol};

question=StringReplace[text, { "@c"->cc,"@d"->dd,"@e"->ee,"#a"->a,"#b"->b,"#d"->d}]; 

{{question," "},{vars}, {sol}} 
]],InputForm]<>"\n ";




solution8=data1<>data2<>ToString[Hold[Module[{a,d,c,b,f,g,i,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, text,list,sol, body={},vars=ertyuiop},



{cc,dd,ee,a,b,d,sol}=vars[[1]];


body={
{"",
ToString[b,TraditionalForm]<>" = "<>ToString[a,TraditionalForm]<>""<>ToString[(("(1 + r)")^(ToString[d,TraditionalForm])),TraditionalForm]<>"\n"<>
ToString[qTrunc8[SetPrecision[ToExpression[b]/ToExpression[a],10],6], TraditionalForm]<>" = "<>ToString[(("(1 + r)")^(ToString[d,TraditionalForm])),TraditionalForm]<>"\n"<>
ToString[(((qTrunc8[SetPrecision[ToExpression[b]/ToExpression[a],10],6]))^(1/(ToString[d,TraditionalForm]))),TraditionalForm]<> " = "<>ToString["1 + r",TraditionalForm]<>"\n"<>
ToString[qTrunc8[ToExpression[ToString[SetPrecision[(ToExpression[b]/ToExpression[a])^(1/ToExpression[d]),10]]],6],TraditionalForm]<>" - 1 = r\n"<> 
"r = "<>ToString[qTrunc6[ToExpression[sol]],TraditionalForm]}, 
{Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint8=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},



body={
{"", 
"A = P (1 + r)^n", 
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data1="\n"<>"textfghjkl:="<>ToString[
{"fghjkl"<> 
".ToString[\"@e invested $#a in @c which earn #r% per annum, calculated as a compound interest. How long would it take @e’s initial investment to double in value? Round your answer to two decimal places.\"]",
"fghjkl"<>".ToString[\"How long did it take @e’s initial investment of $#a in @c to double in value, calculated as a compound interest at #r% per annum? Round your answer to two decimal places. \"]"},InputForm]<>";\n ";


(*Separate the data into pieces so the pecualities could be handeled e.g. geographic are specific names and data *)
data2="listfghjkl:="<>

(*{specific name, abbriviated name, name of the type of thing, location name}*)

ToString[{"bonds","government bons", "corporate bonds", "callable bonds", "savings bonds"


},InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];


(* the lib and data needs to be concatenated for ToExpression work correctly*)
variation9=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{a,b,c,d,i,f,g,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, vars,text,list,sol,r,question}, 


cc=qRandList[listfghjkl];
text=qRandList[textfghjkl];

ee=qRandList[qNamesList][[1]];

{a,r}=ToString/@{RandomInteger[{2,5}]*10000, RandomInteger[{2,10}]};

sol=NSolve[2==(1+(ToExpression[r]/100))^d, d,Reals];
sol=ToString[Max[d/.sol]];


vars={cc,ee,a,r,sol};

question=StringReplace[text, {"@c"-> cc,"@e"->ee,"#a"->a,"#r"->r}];  

{{question," "},{vars}, {sol}} 
]],InputForm]<>"\n ";




solution9=data1<>data2<>ToString[Hold[Module[{a,d,c,b,f,g,r, i,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, text,list,sol, body={},vars=ertyuiop},




{cc,ee,a,r,sol}=vars[[1]];


body={ 
{"",
ToString[2*ToExpression[a],TraditionalForm]<>" = "<>ToString[a,TraditionalForm]<>""<>ToString[((ToString[ToString["(1 + ",TraditionalForm]<>ToString[N[ToExpression[r]/100],TraditionalForm]<>")",TraditionalForm])^(ToString["n",TraditionalForm])),TraditionalForm]<>"\n"<>
"2 = "<>ToString[((ToString[N[1+(ToExpression[r]/100)],TraditionalForm])^(ToString["n",TraditionalForm])),TraditionalForm]<>"\n"<>
"n = "<>ToString[("log 2")/(ToString["log"<>ToString[N[1+(ToExpression[r]/100)],TraditionalForm],TraditionalForm]),TraditionalForm]<>"\n"<>
"n = "<>ToString[qTrunc6[ToExpression[sol]],TraditionalForm],

""},
{Null ,Null, Null}
};
Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint9=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},

body={
{"", 
"A = P (1 + r)^n", 
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data1="\n"<>"textfghjkl:="<>ToString[
{"fghjkl"<>
".ToString[\"A sum of money invested for a @a-year period at #r% interest, compounded monthly. After the @a-year period, the final accumulated value of the investment is $#b. Determine the initial amount invested, round to two decimal places.\"]",
"fghjkl"<>".ToString[\"After the @a-year period, a sum of money invested at #r% interest, compounded monthly,has final accumulated value of $#b. Round to two decimal places, the initial amount of investment. \"]"},InputForm]<>";\n ";

(*Separate the data into pieces so the pecualities could be handeled e.g. geographic are specific names and data *)
data2="listfghjkl:="<>

(*{specific name, abbriviated name, name of the type of thing, location name}*)

ToString[{"",""

},InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];



(* the lib and data needs to be concatenated for ToExpression work correctly*)
variation10=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{a,b,c,d,i,f,g,aa,bb,cc,dd,ee, ff, gg, hh,h, ii, jj,pp,qq, vars,text,list,sol,tmp1,tmp2,tmp3,tmp4,r,question},


cc=qRandList[listfghjkl];
text=qRandList[textfghjkl];

{a,b,r}=ToString/@{RandomInteger[{2,10}],RandomInteger[{2,5}]*100000, RandomInteger[{2,10}]};

aa=IntegerName[ToExpression[a]];


tmp1=SetPrecision[12*ToExpression[a],30];
tmp2= SetPrecision[((ToExpression[r]/100))/12,30];
tmp3=SetPrecision[1+tmp2,30];
tmp4 = ToString[SetPrecision[tmp3^tmp1,7]];
sol=ToString[SetPrecision[b/ToExpression[tmp4],30]];


vars={aa,a,b,c,r,sol};

question=StringReplace[text, {"@a"->aa,"#a"->a,"#b"->b,"#c"->c,"#r"->r}];
{{question," "},{vars}, {sol}} 

]],InputForm]<>"\n ";




solution10=data1<>data2<>ToString[Hold[Module[{a,d,c,b,f,g,r,i,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, text,list,sol, body={},vars=ertyuiop},



{aa,a,b,c,r,sol}=vars[[1]];

body={
{"",
ToString[b,TraditionalForm]<>" = P "<>ToString[(((ToString["(1 + "<>ToString[(ToString[N[ToExpression[r]/100],TraditionalForm])/"12",TraditionalForm]<>")",TraditionalForm]))^(ToString[(12*ToExpression[a]),TraditionalForm])),TraditionalForm]<>"\n"<>
ToString[b,TraditionalForm]<>" = "<>ToString[qTrunc8[N[(1+((ToExpression[r]/100))/12)^(12*ToExpression[a]),10],6],TraditionalForm]<>" P"<>"\n"<>
"P = "<>ToString[qTrunc8[ToExpression[sol],2],TraditionalForm]<>"\n",
""},
{Null ,Null,Null} (*ANNA added Null*)
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint10=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},


body={
{"",
"A = P (1 + (r/12)\!\(\*SuperscriptBox[\()\), \(12\\ n\)]\)",
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data1="\n"<>"textfghjkl:="<>ToString[
{"fghjkl"<>
".ToString[\"@a charges a monthly membership and an optional locker fee (for those who wish to have a designated locker). The total amount charged in one month for @b memberships and #c lockers is $#d. The total charged for @e memberships and #f lockers is $#g. Determine the cost of the locker fee per month.\"]",
"fghjkl"<>".ToString[\"Determine the cost of the locker fee per month, if the total amount charged in one month for @b memberships and #c lockers is $#d and the total charged for @e memberships and #f lockers is $#g. Note that there are a monthly membership and an optional locker fee (for those who wish to have a designated locker).  \"]"},InputForm]<>";\n ";

(*Separate the data into pieces so the pecualities could be handeled e.g. geographic are specific names and data *)
data2="listfghjkl:="<>

(*{specific name, abbriviated name, name of the type of thing, location name}*)

ToString[{"Ryerson Fitness Club","LA Fitness", "Gold Gym", "Life Fitness"

},InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];



(* the lib and data needs to be concatenated for ToExpression work correctly*)
variation11=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{p,a,b,c,d,e,i,f,g,x,y,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, vars,text,list,sol,r,question},


aa=qRandList[listfghjkl];
text=qRandList[textfghjkl];

p={1(*b*),1(*f*),1(*e*),1(*c*)};
(*CRAMER'S RULE: determinant of matrix: b*f - e*c*) 
While[p[[1]]*p[[2]]-p[[3]]*p[[4]]==0,p={not0[RandomInteger[{2,6}]],not0[RandomInteger[{2,6}]],not0[RandomInteger[{2,6}]],not0[RandomInteger[{2,6}]]}];
{b,f,e,c}=ToString/@p;

(*b=ToString[not0[RandomInteger[{2,6}]]];
c=ToString[not0[RandomInteger[{2,6}]]];
e=ToString[not0[RandomInteger[{2,6}]]];
f=ToString[not0[RandomInteger[{2,6}]]];*)
x=ToString[not0[RandomInteger[{10,50}]]];
y=ToString[not0[RandomInteger[{10,20}]]];

d=ToString[ToExpression[b]*ToExpression[x]+ToExpression[c]*ToExpression[y]];
g=ToString[ToExpression[e]*ToExpression[x]+ToExpression[f]*ToExpression[y]];

bb=IntegerName[ToExpression[b]];
ee=IntegerName[ToExpression[e]];


sol=y;
vars={aa,b,c,e,f,x,y,d,g,sol};

question=StringReplace[text, {"@a"->aa,"@b"->bb,"@e"->ee,"#b"->b,"#c"->c,"#e"->e,"#f"->f,"#x"->x,"#y"->y,"#d"->d,"#g"->g}]; 

{{question," "},{vars}, {sol}} 
]],InputForm]<>"\n ";




solution11=data1<>data2<>ToString[Hold[Module[{e,x,y,a,d,c,b,f,g,r,i,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp,qq, text,list,sol, body={},vars=ertyuiop},



{aa,b,c,e,f,x,y,d,g,sol}=vars[[1]]; 


body={
{"Let x represents monthly membership fee \n Let y represents the cost of locker per month \n\n", 
ToString[b,TraditionalForm]<>" x + "<>ToString[c,TraditionalForm]<>" y = "<>ToString[d,TraditionalForm]<>"······1 × "<>ToString[e,TraditionalForm]<>"\n"<> 
ToString[e,TraditionalForm]<>" x + "<>ToString[f,TraditionalForm]<>" y = "<>ToString[g,TraditionalForm]<>"······2 × "<>ToString[b,TraditionalForm]<>"\n"<> 
ToString[ToExpression[b]*ToExpression[e],TraditionalForm]<>" x + "<>ToString[ToExpression[c]*ToExpression[e],TraditionalForm]<>" y = "<>ToString[ToExpression[e]*ToExpression[d],TraditionalForm]<>"······1 "<>"\n"<>
ToString[ToExpression[e]*ToExpression[b],TraditionalForm]<>" x + "<>ToString[ToExpression[f]*ToExpression[b],TraditionalForm]<>" y = "<>ToString[ToExpression[g]*ToExpression[b],TraditionalForm]<>"······2 "<>"\n"<>
If[ToExpression[c]*ToExpression[e]≥ ToExpression[f]*ToExpression[b],
ToString["Substract: 1 - 2 ",TraditionalForm]<>"\n"<>ToString[ToExpression[c]*ToExpression[e]-ToExpression[f]*ToExpression[b],TraditionalForm]<>"y = "<>ToString[ToExpression[e]*ToExpression[d] - ToExpression[g]*ToExpression[b],TraditionalForm],
ToString["Substract: 2 - 1 ",TraditionalForm]<>"\n"<>ToString[ToExpression[f]*ToExpression[b] -ToExpression[c]*ToExpression[e] ,TraditionalForm]<>"y = "<>ToString[ToExpression[g]*ToExpression[b] - ToExpression[e]*ToExpression[d],TraditionalForm]
]<>"\n"<>
"y = "<>ToString[sol,TraditionalForm]<>"\n\n"<>
"The locker costs $"<>ToString[sol,TraditionalForm]<>" per month.",
""},
{Null ,Null, Null}
};
Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint11=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop},


body={ 
{"",
"Use either Method of Substitution or Method of Ellimination.",
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

(* TODO: add more variations *)
data="\n"<>"textfghjkl:="<>ToString[{

(* question *)
{"Column[{ToString[\"fghjkl. Given that @a represents the amount of time, in hours, a student studies for a particular test, and @b represents the resulting test scores. Assume there is a linear relationship between the hours of studies and test scores, use the data provided in the chart to answer the following:\",TraditionalForm]"<>","<>"makeTextTable[{{\"@a hours of studies\",\"@b test scores\"},{0,\" \"},{#i1,#j1},{#i2,#j2},{\" \",#j3}}]"<>"}]",

"Column[{ToString[\"fghjkl. Given that @a represents the amount of time, in hours, a student studies for a particular test, and @b represents the resulting test scores. Assume there is a linear relationship between the hours of studies and test scores, use the data provided in the chart to answer the following:\",TraditionalForm]"<>","<>"makeTextTable[{{\"@a hours \",\"@b scores\"},{0,\" \"},{#i1,#j1},{#i2,#j2},{\" \",#j3}}]"<>"}]"},


(* a *)
{"Column[{ToString[\"FGHJKLabc)Find a formula for this relationship in the form @b = m@a+b\"]"<>","<>"ToString[\"Type  m b e.g. 2 5\",TraditionalForm]}]", 
"Column[{ToString[\"FGHJKLabc)Compute the equation of the line in the form @b = m@a+b:\"]"<>","<>"ToString[\"Type  m b e.g. 3 1\",TraditionalForm]}]"},

{"ToString[\"FGHJKLabc)Determine the number of hours of studies for a student who wants to get #f on the test (if necessery round your answer to two deciaml places).\",TraditionalForm]", "ToString[\"FGHJKLabc)To get #f on the test, how many hours of studies required? Round your answer to two deciaml places if necessary.\",TraditionalForm]"}, 

{"ToString[\"FGHJKLabc)Explain what the slope means in the context of this question.\",TraditionalForm]"}
},InputForm]<>";\n ";

variation12=data<>ToString[Hold[Module[{p,a,b,c,d,e,f,g,h,i,j,i1,i2,j1,j2,j3,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, vars,text,list,sol, parta, partb, partc, partd,question,x},


question=qRandList[textfghjkl[[1]]];

text=qRandList[textfghjkl[[2]]];

p={"a","a"};
While[p[[1]]===p[[2]],p=nLetters[{"a","z"},2] /.{"b"->"c","m"->"n"}]; 
{aa,bb}=p;

(*y=cx+d, in table x = 1 and x = e*)
{c,d}=nIntegers[not0/@Range[2,10],2];
e=ToString[RandomInteger[{3,7}]];
{i1,j1,i2,j2,j3}=ToString/@{1,ToExpression[c]*1+ToExpression[d],ToExpression[e],ToExpression[c]*ToExpression[e]+ToExpression[d],ToExpression[c]*(ToExpression[e]+3)+ToExpression[d]};



sol= ToString[{ToExpression[c],ToExpression[d]},InputForm];
vars={aa,bb,c,d,e,i1,j1,i2,j2,j3,sol};

question=StringReplace[question, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#i1"->i1,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#j3"->j3}];

parta={StringReplace[text, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#i1"->i1,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#j3"->j3}],vars,sol} ;


(* b *)
text=qRandList[textfghjkl[[3]]];

f=ToString[RandomInteger[{50,100}]];
sol=NSolve[ToExpression[f]==ToExpression[c]*x+ToExpression[d], x];
sol=ToString[Max[x/.sol]]; 

vars={aa,bb,c,d,e,f,i1,j1,i2,j2,j3,sol};

partb={StringReplace[text, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#f"->f,"#i1"->i1,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#j3"->j3}],vars,sol} ;



text=qRandList[textfghjkl[[4]]];


vars={aa,bb,c,d,e,f,i1,j1,i2,j2,j3,sol};
sol=c;

partc={StringReplace[text, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#f"->f,"#i1"->i1,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#j3"->j3}],vars,sol} ;

{{question,parta[[1]], partb[[1]],partc[[1]]},{parta[[2]], partb[[2]],partc[[2]]}, {parta[[3]], partb[[3]],partc[[3]]}}

(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution12=data<>ToString[Hold[Module[{aa,bb,cc,dd,ee, c,d,e,ff,f, gg, hh, ii, jj,i1,i2,j1,j2,j3, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc},





varsa=vars[[1]];
varsb=vars[[2]];
varsc=vars[[3]];

body={
{{aa,bb,c,d,e,i1,j1,i2,j2,j3,sol}=varsa;options[[1]]<>": \n"<>
"m = "<>ToString[(j2 - j1)/(i2 - i1),TraditionalForm]<>" = "<>ToString[Simplify[(ToExpression[j2] -ToExpression[ j1])/(ToExpression[i2] - ToExpression[i1])],TraditionalForm]<>"\n\n"<>
ToString[bb,TraditionalForm]<>" = "<> ToString[c,TraditionalForm]<>ToString[aa,TraditionalForm]<>" + b\n"<>
ToString[j2,TraditionalForm]<>" = "<>ToString[c,TraditionalForm]<>" ("<>ToString[i2,TraditionalForm]<>") + b\n"<> 
ToString[j2,TraditionalForm]<>" - "<>ToString[ToExpression[c]*ToExpression[i2],TraditionalForm]<>" = b\n"<>
"b = "<>ToString[Simplify[ToExpression[j2] - (ToExpression[c]*ToExpression[i2])],TraditionalForm]<>"\n\n"<>
"Equation of line: "<>ToString[bb,TraditionalForm]<>" = "<> ToString[c,TraditionalForm]<>ToString[aa,TraditionalForm]<>" + "<>ToString[d,TraditionalForm]<>"\n",
(*b*)
{aa,bb,c,d,e,f,i1,j1,i2,j2,j3,sol}=varsb;options[[2]]<>": \n"(*<>sol<>"\n"*)<>
ToString[f,TraditionalForm]<>" = "<>ToString[c,TraditionalForm]<>ToString[aa,TraditionalForm]<>" + "<>ToString[d,TraditionalForm]<>"\n"<>
ToString[f,TraditionalForm]<>" - "<>ToString[d,TraditionalForm]<>" = "<>ToString[c,TraditionalForm]<>ToString[aa,TraditionalForm]<>"\n"<>
ToString[c,TraditionalForm]<>ToString[aa,TraditionalForm]<>" = "<>ToString[ToExpression[f]-ToExpression[d],TraditionalForm]<>"\n"<>
ToString[aa,TraditionalForm]<>" = "<>ToString[qTrunc6[ToExpression[sol]],TraditionalForm]<>"\n",  
(*c*)
{aa,bb,c,d,e,f,i1,j1,i2,j2,j3,sol}=varsc;options[[3]]<>":\n Sample:\nThe score increases by " <>c<>"\n marks per hour of studies. \n"},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint12=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},


body={
{options[[1]]<>": \nEquation of line: y = mx + b\n m = "<>ToString[("(Subscript[y, 2]) - (Subscript[y, 1])")/("(Subscript[x, 2]) - (Subscript[x, 1])"),TraditionalForm], 
options[[2]]<>": \nIdentify which variable is given. Solve for unknown.", 
options[[3]]<>": \nThink \"Rate\""}, 
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data="\n"<>"textfghjkl:="<>ToString[{

(* top question*)
{"Column[{ToString[\"fghjkl. A university did a study on the relationship between student gender and exercise:\",TraditionalForm]"<>","<>"Column[{ToString[\"● #f% of all students surveyed do not exercise regularly \"],ToString[\"● #g% of those who do not exercise regularly were female \"],ToString[\"● #h% of all students surveyed were female.\n \"]}]"<>"}]"},

(*a*)
{"ToString[\"FGHJKLabc)Use the information shown above to fill in the chart below:\"]"},


(*b*)
{"Column[{ToString[\"FGHJKLabc)Determine the probability that a student chosen exercise regularly.\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},

(*c*)
{"Column[{ToString[\"FGHJKLabc)Determine the probability that student chosen is female, given that the person chosen does not exercise regularly.\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"}
},InputForm]<>";\n ";


variation13=data<>ToString[Hold[Module[{a,b,c,d,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, vars,text,list,sol, parta, partb, partc, partd,question,b2,table,vec}, 


question=qRandList[textfghjkl[[1]]];

text=qRandList[textfghjkl[[2]]];


(*a=all Regular Exercise, b=No Regular Exercise, c= #female regular, d=#male regular*)

vec = {50,70,20};
While[100*vec[[1]]/100*vec[[2]]/100>(vec[[3]]/100)*100,
vec[[1]]=RandomInteger[{1,7}]*10;
vec[[2]]=RandomInteger[{1,7}]*10;
vec[[3]] = RandomInteger[{1,5}]*10];
{f,g,h}=ToString/@vec;

(*{f,g,h}=ToString/@{RandomInteger[{1,7}]*10,RandomInteger[{1,7}]*10,RandomInteger[{1,5}]*10};*)
a=ToString@(RandomInteger[{1,8}]*10);
b=ToString@(100-ToExpression[a]);
c=ToString@((100-ToExpression[g])*ToExpression[a]/100);
d=ToString@(ToExpression[a]-ToExpression[c] );


(*"\"-\""*)
table={
{"\"All in %\"","\"Regular Exercise\"","\"No Regular Exercise\"","\"Total\""},
{"\"Male\"","\"-\"","\"-\"","\"-\""},
{"Female","\"-\"","\"-\"","\"-\""},
{"Total","\"-\"",f,"100"}};




question=StringReplace[question, {"#a"->a,"#b"->b, "#c"->c,"#d"->d,"#f"->f,"#g"->g,"#h"->h}];


(*{{2,2},{2,3},{2,4},{3,2},{3,3},{3,4},{4,2},{4,3},{4,4}} are the entries where the answers are supposed to be in the table *)
sol={(*first row*)
N[100-(N[ToExpression[h]/100*100])-((N[ToExpression[f]/100*100])-N[((ToExpression[g]/100)*(ToExpression[f]/100))*100])],N[(N[ToExpression[f]/100*100])-N[((ToExpression[g]/100)*(ToExpression[f]/100))*100]],N[100-(N[ToExpression[h]/100*100])],
(*second row*)
N[(N[ToExpression[h]/100*100])- N[((ToExpression[g]/100)*(ToExpression[f]/100))*100]],N[((ToExpression[g]/100)*(ToExpression[f]/100))*100],N[ToExpression[h]/100*100],
(*third row*)
N[100-(N[ToExpression[f]/100*100])],N[ToExpression[f]/100*100],100};
vars={ToString@table,ToString@{{2,2},{2,3},{2,4},{3,2},{3,3},{3,4},{4,2},{4,3},{4,4}},a,b,c,d,f,g,h};
parta={text,vars,sol} ;


(* part b*)
text=qRandList[textfghjkl[[3]]];

sol=(100-(N[ToExpression[f]/100*100]))/100; 

vars={a,b, c,f,g,h,ToString@sol};

partb={StringReplace[text, {"#a"->a,"#b"->b, "#c"->c,"#d"->d}],vars,sol} ;



(* part c*)
text=qRandList[textfghjkl[[4]]];

sol=(N[((ToExpression[g]/100)*(ToExpression[f]/100))*100])/(N[ToExpression[f]/100*100]); 

vars={a,b, c,f,g,h,ToString@sol};

partc={StringReplace[text, {"#a"->a,"#b"->b, "#c"->c,"#d"->d}],vars,sol} ;

{{question,parta[[1]], partb[[1]],partc[[1]]},{parta[[2]], partb[[2]],partc[[2]]}, parta[[3]]~Join~{ partb[[3]],partc[[3]]}}(*KLUDGE: part 3 all wrong*)



(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution13=data<>ToString[Hold[Module[{a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,b2,b3,table,locs},



varsa=vars[[1]];
varsb=vars[[2]];
varsc=vars[[3]];


{table,locs,a,b,c,d,f,g,h}=varsa;



body={
{options[[1]]<>": \n" ,
"Based on the percents from the task:",
makeTextTable[{{"All in %","Regular Exercise","No Regular Exercise","Total"}, 
{"Male","-","-","-"},
{"Female","-",ToString[ToString[(N[ToExpression[g]/100]),TraditionalForm]<>"\[Cross]"<> ToString[qTrunc6[(ToExpression[f]/100)*100],TraditionalForm]<>"="<>ToString[qTrunc6[((ToExpression[g]/100)*(ToExpression[f]/100))*100],TraditionalForm],TraditionalForm],ToString[ToString[(N[ToExpression[h]/100]),TraditionalForm]<>"\[Cross]100 = "<>ToString[(qTrunc6[ToExpression[h]/100*100]),TraditionalForm],TraditionalForm]},{"Total","-",ToString[ToString[(N[ToExpression[f]/100]),TraditionalForm]<>"\[Cross]100 = "<>ToString[(qTrunc6[ToExpression[f]/100*100]),TraditionalForm],TraditionalForm],"100"}}],
"\nNext part of table full fill using substraction:",
makeTextTable[{{"All in %","Regular Exercise","No Regular Exercise","Total"},
{"Male",ToString[qTrunc6[100-(N[ToExpression[h]/100*100])],TraditionalForm]<>"-"<>ToString[qTrunc6[(N[ToExpression[f]/100*100])-N[((ToExpression[g]/100)*(ToExpression[f]/100))*100]],TraditionalForm]<>"="<>ToString[qTrunc6[100-(N[ToExpression[h]/100*100])-((N[ToExpression[f]/100*100])-N[((ToExpression[g]/100)*(ToExpression[f]/100))*100])],TraditionalForm],ToString[(qTrunc6[ToExpression[f]/100*100]),TraditionalForm]<>"-"<>ToString[qTrunc6[((ToExpression[g]/100)*(ToExpression[f]/100))*100],TraditionalForm]<>"="<>ToString[qTrunc6[(N[ToExpression[f]/100*100])-N[((ToExpression[g]/100)*(ToExpression[f]/100))*100]],TraditionalForm],"100-"<>ToString[(qTrunc6[ToExpression[h]/100*100]),TraditionalForm]<>"="<>ToString[qTrunc6[100-(N[ToExpression[h]/100*100])],TraditionalForm]},

{"Female",ToString[(qTrunc6[ToExpression[h]/100*100]),TraditionalForm]<>"-"<>ToString[qTrunc6[((ToExpression[g]/100)*(ToExpression[f]/100))*100],TraditionalForm]<>"="<>ToString[qTrunc6[(N[ToExpression[h]/100*100])- N[((ToExpression[g]/100)*(ToExpression[f]/100))*100]],TraditionalForm],Style[ToString[qTrunc6[((ToExpression[g]/100)*(ToExpression[f]/100))*100],TraditionalForm],Blue],Style[ToString[(qTrunc6[ToExpression[h]/100*100]),TraditionalForm],Blue]},

{"Total",ToString["100-"<>ToString[(qTrunc6[ToExpression[f]/100*100]),TraditionalForm]<>"="<>ToString[qTrunc6[100-(N[ToExpression[f]/100*100])],TraditionalForm],TraditionalForm],Style[ToString[(qTrunc6[ToExpression[f]/100*100]),TraditionalForm],Blue],Style["100",Blue]}}],
"",
(*b*)
{a,b, c,f,g,h,sol}=varsb;options[[2]]<>":\n"<>"Number of all students: 100"<>"\n"<>"Number of students which exercise regularly: "<>ToString[qTrunc6[100-(N[ToExpression[f]/100*100])],TraditionalForm]<>"\n\n"<>ToString[(ToString[qTrunc6[100-(N[ToExpression[f]/100*100])],TraditionalForm])/"100",TraditionalForm]<>"="<>ToString[qTrunc6[(100-(N[ToExpression[f]/100*100]))/100],TraditionalForm]<>"\n",

(*c*)
{a,b, c,f,g,h,sol}=varsc;options[[3]]<>":\n"<>"Number of students which do not exercise regularly: "<>ToString[(qTrunc6[ToExpression[f]/100*100]),TraditionalForm]<>"\n"<>"Number of female which do not exercise regularly: "<>ToString[qTrunc6[((ToExpression[g]/100)*(ToExpression[f]/100))*100],TraditionalForm]<>"\n\n"<>ToString[(ToString[qTrunc6[((ToExpression[g]/100)*(ToExpression[f]/100))*100],TraditionalForm])/(ToString[(qTrunc6[ToExpression[f]/100*100]),TraditionalForm]),TraditionalForm]<>"="<>ToString[qTrunc6[(N[((ToExpression[g]/100)*(ToExpression[f]/100))*100])/(N[ToExpression[f]/100*100])],TraditionalForm]},

{Null,Null,Null,Null ,Null, Null,Null,Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint13=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},


body={
{options[[1]]<>": \n The first and the third clues are standalone cluses. \nThe second clue has something to do with the first clue given.\n", 
options[[2]]<>": \n P( an event happening ) = "<>ToString[("n( event )")/"n( all possibilities with no restrictions )",TraditionalForm]<>"\n", 
options[[3]]<>": \n Think \"Conditional Probability\" \n P(A|B) = "<>ToString[("P(A ⋂ B)")/"P(B)",TraditionalForm]}, 
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

Make a GUI table and write qpanel :

(* Separate the Module name from the Module[] *)



(*KLUDGE, needs to be generalized *)
qpanelMultiTABLE=ToString[Hold[DynamicModule[{pn,proc,err,level0,max,mult,diag0,answer,myEnabled,A1,answerStudent,A2,a1,a2,level1,stateH=False,state=False,vars,xxx,yyy,text,sol,prev,again, variation,variation2,hint, solution, procs,first=True,options,io,answers},


Panel[Column[{

Panel[Row[{OpenerView[{Button["Try Again",
(*AppendTo[level1[[3]],prev];*)
first=ConstantArray[True,mult0+9];
level1=again;
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];Table[A2[[i]]=ToString[bigNumber];A1[[i]]=Null;myEnabled[[i]]=True,{i,1,mult0+9}];], ""}],
OpenerView[{Button["Hint",stateH=Not[stateH],Method->"Queued"],Dynamic[If[stateH==True,ReleaseHold[ToExpression[StringReplace[hint,{"ertyuiop"->ToString[vars,InputForm],ToUpperCase["ertyuiop"]->ToString[options,InputForm]}]]]]]},Dynamic[stateH]],
OpenerView[{Button["Solution",state=Not[state],Method->"Queued"],Dynamic[If[state==True,ReleaseHold[ToExpression[StringReplace[solution,{"ertyuiop"->ToString[vars,InputForm],ToUpperCase["ertyuiop"]->ToString[options,InputForm]}]]]]]},Dynamic[state]]}]],



Column[{Dynamic[ReleaseHold[ToExpression[text[[1]]/.{"fghjkl"->pn}]]]}~Join~{Dynamic[ReleaseHold[ToExpression[StringReplace[text[[2]],{"FGHJKLabc"->options[[1]]}]]]]}~Join~{(answers=Table[With[{i=i},


Column[{
Dynamic[A2[[i]]=If[TrueQ[A1[[i]]==Null], ToString[bigNumber],A1[[i]]];

(*FIXME: need a much better parsing and filtering, problem is with 6.6 and . as dot in a sentence *)
If[Length[StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]]]==1, a2=StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]][[1]],a2=StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]]];If[ToExpression[a2]===bigNumber,"", myEnabled[[i]]=False;
(*errNo set to the first for all *)
""<>Which[err[[1]][sol[[i]],a2,A1[[i]]]==True&&ToExpression[a2]=!=bigNumber, (*a2=!=ToString[bigNumber] to Avoid ToExpression*)


(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[i]]==True,"Correct",
diag00==1,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"Correct",True, ""],

err[[1]][sol[[i]],a2,A1[[i]]]==False&&ToExpression[a2]=!=bigNumber,

Which[diag00==0&&first[[i]]==True,"Incorrect",
diag00==1,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"Incorrect",True, ""],True,""]]],

Deploy@InputField[Dynamic[A1[[i]]],String,Enabled->Dynamic[myEnabled[[i]]],FieldSize->inputsize0[[1]],FieldHint->"       ?",FieldHintStyle->{Red}]}] (*inputsize has to be written over here*)

],{i, 1,9}]);Dynamic@makeTextTable2[ToExpression[vars[[1]][[1]]],answers,ToExpression[vars[[1]][[2]]]]}],


Column[Table[With[{i=i},


Column[{If[mult0>1,Dynamic[ReleaseHold[ToExpression[StringReplace[text[[i+2-9]],{"FGHJKLabc"->options[[i+1-9]]}]]]]," "] ,
Dynamic[A2[[i]]=If[TrueQ[A1[[i]]==Null], ToString[bigNumber],A1[[i]]];

(*FIXME: need a much better parsing and filtering, problem is with 6.6 and . as dot in a sentence *)
If[Length[StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]]]==1, a2=StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]][[1]],a2=StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]]];If[ToExpression[a2]===bigNumber,"\nAnswer?", myEnabled[[i]]=False;"\nAnswer: "<>Which[err[[i+1-9]][sol[[i]],a2,A1[[i]]]==True&&ToExpression[a2]=!=bigNumber,  (*a2=!=ToString[bigNumber] to Avoid ToExpression*)


(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[i]]==True,"Correct",
diag00==1,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"Correct",True, ""],

err[[i+1-9]][sol[[i]],a2,A1[[i]]]==False&&ToExpression[a2]=!=bigNumber,

Which[diag00==0&&first[[i]]==True,"Incorrect",
diag00==1,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"Incorrect",True, ""],True,""]]],

Deploy@InputField[Dynamic[A1[[i]]],String,Enabled->Dynamic[myEnabled[[i]]],FieldSize->inputsize0[[i-9]]]}] (*inputsize has to be written over here*)

],{i, 10,10+1}]]

}]],
(*{{level,Dynamic[level1[[1]]]},Range[max],ControlType->PopupMenu},*)
(*TrackedSymbols->Manipulate,(* SaveDefinitions->True,*)AppearanceElements->None,SynchronousUpdating->False,ContinuousAction->False,*)
Initialization:>(stateH=False;state=False;


libs; (* add the needed functions and constants *)


(* these are the parameters that used to be passed as argument list *)
(* FIXME: mult0 has to be written over by replacement and cannot be initialized here *)
pn=pn0;proc=proc0;err=ToExpression[err0];level0=level00;max=max0;mult=mult0+9;diag0=diag00;
io=ToExpression[IO00];

SetOptions[EvaluationNotebook[],DynamicEvaluationTimeout->100];
(* changing of the DynamicUpdateInterval did not alter anythin *)
(*SetOptions[EvaluationNotebook[],"DynamicUpdateInterval"->0.2];*)


(* the rest here sets up the math for the question *)
answer=ConstantArray[" ",mult];
A1=ConstantArray["",mult];
A2=ConstantArray[ToString[bigNumber],mult];
answerStudent=ConstantArray[" ",mult];
myEnabled=ConstantArray[True,mult];
first=ConstantArray[True,mult];

Table[A2[[i]]=ToString[bigNumber];A1[[i]]=Null;myEnabled[[i]]=True,{i,1,mult}];
If[mult> 1,options=qRandList[{CharacterRange["a","z"][[1;;mult-9]],CharacterRange["A","Z"][[1;;mult-9]]}],options={" "}]; 


{again, variation, hint, solution}=proc;
again=ToExpression[again];
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];


level1=again;

)

]],InputForm]<>"\n";




qpanelMulti2=ToString[Hold[DynamicModule[{pn,proc,err,level0,max,mult,diag0,answer,myEnabled,A1,answerStudent,A2,a1,a2,level1,stateH=False,state=False,vars,xxx,yyy,text,sol,prev,again, variation,variation2,hint, solution, procs,first=True,options,io},


Panel[Column[{

Panel[Row[{OpenerView[{Button["Try Again",
(*AppendTo[level1[[3]],prev];*)
first=ConstantArray[True,mult0];
level1=again;
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];Table[A2[[i]]=ToString[bigNumber];A1[[i]]=Null;myEnabled[[i]]=True,{i,1,mult0}];], ""}],
OpenerView[{Button["Hint",stateH=Not[stateH],Method->"Queued"],Dynamic[If[stateH==True,ReleaseHold[ToExpression[StringReplace[hint,{"ertyuiop"->ToString[vars,InputForm],ToUpperCase["ertyuiop"]->ToString[options,InputForm]}]]]]]},Dynamic[stateH]],
OpenerView[{Button["Solution",state=Not[state],Method->"Queued"],Dynamic[If[state==True,ReleaseHold[ToExpression[StringReplace[solution,{"ertyuiop"->ToString[vars,InputForm],ToUpperCase["ertyuiop"]->ToString[options,InputForm]}]]]]]},Dynamic[state]]}]],



Column[{Dynamic[ReleaseHold[ToExpression[text[[1]]/.{"fghjkl"->pn}]]]}~Join~Table[With[{i=i},


Column[{If[mult0>1,Dynamic[ReleaseHold[ToExpression[StringReplace[text[[i+1]],{"FGHJKLabc"->options[[i]]}]]]]," "] ,
Dynamic[A2[[i]]=If[TrueQ[A1[[i]]==Null], ToString[bigNumber],A1[[i]]];

(*FIXME: need a much better parsing and filtering, problem is with 6.6 and . as dot in a sentence *)
If[Length[StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]]]==1, a2=StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]][[1]],a2=StringSplit[StringReplace[A2[[i]],{","->" ",";"->" ",":"->" ","."->" "}]]];If[ToExpression[a2]===bigNumber,"\nAnswer?", myEnabled[[i]]=False;"\nAnswer: "<>Which[err[[i]][sol[[i]],a2,A1[[i]]]==True&&ToExpression[a2]=!=bigNumber, prev=True; (*a2=!=ToString[bigNumber] to Avoid ToExpression*)


(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[i]]==True,"Correct",
diag00==1,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"Correct",True, ""],

err[[i]][sol[[i]],a2,A1[[i]]]==False&&ToExpression[a2]=!=bigNumber,prev=False;

Which[diag00==0&&first[[i]]==True,"Incorrect",
diag00==1,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,A1[[i]], diag00]];first[[i]]=False;"Incorrect",True, ""],True,""]]],

Deploy@InputField[Dynamic[A1[[i]]],String,Enabled->Dynamic[myEnabled[[i]]],FieldSize->inputsize0[[i]]]}] (*inputsize has to be written over here*)

],{i, 1,mult0}]]

}]],
(*{{level,Dynamic[level1[[1]]]},Range[max],ControlType->PopupMenu},*)
(*TrackedSymbols->Manipulate,(* SaveDefinitions->True,*)AppearanceElements->None,SynchronousUpdating->False,ContinuousAction->False,*)
Initialization:>(stateH=False;state=False;


libs; (* add the needed functions and constants *)


(* these are the parameters that used to be passed as argument list *)
(* FIXME: mult0 has to be written over by replacement and cannot be initialized here *)
pn=pn0;proc=proc0;err=ToExpression[err0];level0=level00;max=max0;mult=mult0;diag0=diag00;
io=ToExpression[IO00];

SetOptions[EvaluationNotebook[],DynamicEvaluationTimeout->100];
(* changing of the DynamicUpdateInterval did not alter anythin *)
(*SetOptions[EvaluationNotebook[],"DynamicUpdateInterval"->0.2];*)


(* the rest here sets up the math for the question *)
answer=ConstantArray[" ",mult];
A1=ConstantArray["",mult];
A2=ConstantArray[ToString[bigNumber],mult];
answerStudent=ConstantArray[" ",mult];
myEnabled=ConstantArray[True,mult];
first=ConstantArray[True,mult];

Table[A2[[i]]=ToString[bigNumber];A1[[i]]=Null;myEnabled[[i]]=True,{i,1,mult}];
If[mult> 1,options=qRandList[{CharacterRange["a","z"][[1;;mult]],CharacterRange["A","Z"][[1;;mult]]}],options={" "}]; 


{again, variation, hint, solution}=proc;
again=ToExpression[again];
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];
(*hint=ReleaseHold[ToExpression[hint]];*)

level1=again;

)

]],InputForm]<>"\n";



qpanelMulti=ToString[Hold[DynamicModule[{pn,proc,level0,max,mult,diag0,answer,myEnabled,A1,answerStudent,A2,a1,a2,level1,stateH=False,state=False,vars,xxx,yyy,text,sol,prev,again, variation,variation2,hint, solution, procs,first=True,options,io},


Panel[Column[{

If[diag00==0 ||diag00==2,Panel[Row[{OpenerView[{Button["Try Again",
(*AppendTo[level1[[3]],prev];*)

first=ConstantArray[True,mult0];
level1=again;
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];Table[A2[[i]]=ToString[bigNumber];A1[[i]]=Null;myEnabled[[i]]=True,{i,1,mult0}];(*setFocus[EvaluationNotebook[],"AA2"];*)], ""}],
OpenerView[{Button["Hint",stateH=Not[stateH],Method->"Queued"],Dynamic[If[stateH==True,hint]]},Dynamic[stateH]],
OpenerView[{Button["Solution",state=Not[state],Method->"Queued"],Dynamic[If[state==True,ReleaseHold[ToExpression[StringReplace[solution,{"ertyuiop"->ToString[vars,InputForm],ToUpperCase["ertyuiop"]->ToString[options,InputForm]}]]]]]},Dynamic[state]]}]],""],



Column[{Dynamic[ReleaseHold[ToExpression[text[[1]]/.{"fghjkl"->pn}]]]}~Join~Table[With[{i=i},

(* what the student sees all together for the question and answer and verification *)
Column[{Dynamic[ReleaseHold[ToExpression[StringReplace[text[[i+1]],{"FGHJKLabc"->options[[i]]}]]]] ,

Dynamic[A2[[i]]=If[TrueQ[A1[[i]]==Null], ToString[bigNumber],A1[[i]]];
If[Length[StringSplit[A2[[i]]]]==1, a2=StringSplit[A2[[i]]][[1]],a2=StringSplit[A2[[i]]]];If[ToExpression[a2]===bigNumber,"\nAnswer?", myEnabled[[i]]=False;"\nAnswer: "<>Which[ToExpression[sol[[i]]]===ToExpression[a2]&&ToExpression[a2]=!=bigNumber, prev=True;

(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[i]]==True,"Correct",
diag00==1,If[first[[i]]==True,io[pn,i,True,a2, diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,a2, diag00]];first[[i]]=False;"Correct",True, ""],

ToExpression[sol[[i]]]=!=ToExpression[a2]&&ToExpression[a2]=!=bigNumber,prev=False;
Which[diag00==0&&first[[i]]==True,"Incorrect",
diag00==1,If[first[[i]]==True,io[pn,i,True,a2, diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,a2, diag00]];first[[i]]=False;"Incorrect",True, ""],True,""]]],

If[i==1,InputField[Dynamic[A1[[i]]],String,Enabled->Dynamic[myEnabled[[i]]],FieldSize->5(*,BoxID->"AA2"*)],InputField[Dynamic[A1[[i]]],String,Enabled->Dynamic[myEnabled[[i]]],FieldSize->5]]}]

],{i, 1,mult0}]]

}]],
(*{{level,Dynamic[level1[[1]]]},Range[max],ControlType->PopupMenu},*)
(*TrackedSymbols->Manipulate,(* SaveDefinitions->True,*)AppearanceElements->None,SynchronousUpdating->False,ContinuousAction->False,*)
Initialization:>(stateH=False;state=False;


libs; (* add the needed functions and constants *)


(* these are the parameters that used to be passed as argument list *)
(* FIXME: mult0 has to be written over by replacement and cannot be initialized here *)
pn=pn0;proc=proc0;level0=level00;max=max0;mult=mult0;diag0=diag00;
io=ToExpression[IO00];


SetOptions[EvaluationNotebook[],DynamicEvaluationTimeout->100];

(*setFocus[nb_,ID_]:=MathLink`CallFrontEnd[FrontEnd`BoxReferenceFind[FE`BoxReference[nb,{{ID}},FE`BoxOffset->{FE`BoxChild[1]},FE`SearchStart->"StartFromBeginning"]]];
setFocus[EvaluationNotebook[],"AA2"];*)

(* the rest here sets up the math for the question *)
answer=ConstantArray[" ",mult];
A1=ConstantArray["",mult];
A2=ConstantArray[ToString[bigNumber],mult];
answerStudent=ConstantArray[" ",mult];
myEnabled=ConstantArray[True,mult];
first=ConstantArray[True,mult];

Table[A2[[i]]=ToString[bigNumber];A1[[i]]=Null;myEnabled[[i]]=True,{i,1,mult}];
options=qRandList[{CharacterRange["a","z"][[1;;mult]],CharacterRange["A","Z"][[1;;mult]]}];


{again, variation, hint, solution}=proc;
again=ToExpression[again];
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];
hint=ReleaseHold[ToExpression[hint]];

level1=again;

)

]],InputForm]<>"\n";




qpanel=ToString[Hold[DynamicModule[{pn,proc,level0,max,mult,diag0,io,answer,myEnabled,A1,answerStudent,A2,a1,a2,level1,stateH=False,state=False,vars,xxx,yyy,text,sol,prev,again, variation,variation2,hint, solution, procs,first=True,options},


Panel[Column[{

If[diag00==0 ||diag00==2,Panel[Row[{OpenerView[{Button["Try Again",
(*AppendTo[level1[[3]],prev];*)
level1=again;
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];A2=ToString[bigNumber];A1=Null;myEnabled=True;first=True;], ""}],
OpenerView[{Button["Hint",stateH=Not[stateH],Method->"Queued"],Dynamic[If[stateH==True,hint]]},Dynamic[stateH]],
OpenerView[{Button["Solution",state=Not[state],Method->"Queued"],Dynamic[If[state==True,ReleaseHold[ToExpression[StringReplace[solution,{"ertyuiop"->ToString[vars,InputForm],ToUpperCase["ertyuiop"]->ToString[options,InputForm]}]]]]]},Dynamic[state]]}]],""],



Column[{Dynamic[ReleaseHold[ToExpression[text/.{"fghjkl"->pn}]]],

(* what the student sees all together for the question and answer and verification *)


Dynamic[A2=If[TrueQ[A1==Null], ToString[bigNumber],A1];
If[Length[StringSplit[A2]]==1, a2=StringSplit[A2][[1]],a2=StringSplit[A2]];If[ToExpression[a2]===bigNumber,"\nAnswer?", myEnabled=False;"\nAnswer: "<>Which[ToExpression[sol]===ToExpression[a2]&&ToExpression[a2]=!=bigNumber, prev=True;

Which[diag00==0&&first==True,"Correct",
diag00==1,If[first==True,io[pn,0,True,a2, diag00]];first=False;"",
diag00==2,If[first==True,io[pn,0,True,a2, diag00]];first=False;"Correct",True, ""],

ToExpression[sol]=!=ToExpression[a2]&&ToExpression[a2]=!=bigNumber,prev=False;

Which[diag00==0&&first==True,"Incorrect",
diag00==1,If[first==True,io[pn,0,False,a2, diag00]];first=False;"",
diag00==2,If[first==True,io[pn,0,False,a2, diag00]];first=False;"Incorrect",True, ""],True,""]]],

InputField[Dynamic[A1],String,Enabled->Dynamic[myEnabled],FieldSize->5]}]



}]],
(*{{level,Dynamic[level1[[1]]]},Range[max],ControlType->PopupMenu},*)
(*TrackedSymbols->Manipulate,(* SaveDefinitions->True,*)AppearanceElements->None,SynchronousUpdating->False,ContinuousAction->False,*)
Initialization:>(stateH=False;state=False;


libs; (* add the needed functions and constants *)


(* these are the parameters that used to be passed as argument list *)
(* FIXME: mult0 has to be written over by replacement and cannot be initialized here *)
pn=pn0;proc=proc0;level0=level00;max=max0;diag0=diag00;
io=ToExpression[IO00];


SetOptions[EvaluationNotebook[],DynamicEvaluationTimeout->100];
(* changing of the DynamicUpdateInterval did not alter anythin *)
(*SetOptions[EvaluationNotebook[],"DynamicUpdateInterval"->0.2];*)


(* the rest here sets up the math for the question *)
answer=" ";
A1="";
A2=ToString[bigNumber];
answerStudent=" ";
myEnabled=True;
first=True;

A2=ToString[bigNumber];A1=Null;myEnabled=True;

{again, variation, hint, solution}=proc;
again=ToExpression[again];
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];
hint=ReleaseHold[ToExpression[hint]];

level1=again;

)

]],InputForm]<>"\n";

title="qTitle[]:="<>ToString[DynamicModule[{x},
Manipulate[ 

"",AppearanceElements->None,Initialization:>(x=my`procs[[RandomSample[Range[Length[my`procs]]]]];
my`procs2=x;)]],InputForm]<>"\n";

CONFIGURATION AREA

proc1=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation4,hint4,solution4},InputForm]<>";\n";
proc2=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation3,hint3,solution3},InputForm]<>";\n";
proc3=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation1,hint1,solution1},InputForm]<>";\n";
proc4=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation5,hint5,solution5},InputForm]<>";\n";
proc5=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation6,hint6,solution6},InputForm]<>";\n";
proc6=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation7,hint7,solution7},InputForm]<>";\n";
proc7=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation8,hint8,solution8},InputForm]<>";\n";
proc8=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation9,hint9,solution9},InputForm]<>";\n";
proc9=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation10,hint10,solution10},InputForm]<>";\n";
proc10=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation11,hint11,solution11},InputForm]<>";\n";
proc11=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation12,hint12,solution12},InputForm]<>";\n";
proc12=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation13,hint13,solution13},InputForm]<>";\n";

“diag00”->”x”:

0 practice Module no record, 1 test Module record, 2 practice module record 


make sure you have included “IO00”->”qClick” .

panelsMIX={ 
StringReplace[qpanelMulti2,{"pn0"->ToString[1],"proc0"->proc1,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{errNO,errNO,err2,err3}", "inputsize0"->"{5,5,5,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"4","diag00"->"2","IO00"->"qClick"}], 
StringReplace[qpanelMulti2,{"pn0"->ToString[2],"proc0"->proc2,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{errNO,errNO,errNO}","inputsize0"->"{5,5,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"3","diag00"->"2","IO00"->"qClick"}],
StringReplace[qpanelMulti2,{"pn0"->ToString[3],"proc0"->proc3,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{errNO}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick"}],
StringReplace[qpanelMulti2,{"pn0"->ToString[4],"proc0"->proc4,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{errNO}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick"}],
StringReplace[qpanelMulti2,{"pn0"->ToString[5],"proc0"->proc5,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{errNO}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick"}],
StringReplace[qpanelMulti2,{"pn0"->ToString[6],"proc0"->proc6,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{err2}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick"}],
StringReplace[qpanelMulti2,{"pn0"->ToString[7],"proc0"->proc7,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{err2}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick"}],
StringReplace[qpanelMulti2,{"pn0"->ToString[8],"proc0"->proc8,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{err2}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick"}],

(* TO DO: changed qPanel do qPanelMulti2 proc9 *) 
StringReplace[qpanelMulti2,{"pn0"->ToString[9],"proc0"->proc9,"libs"->(libLIST<>"\n"<>libNAMES),"err0"->"{err4}","inputsize0"->"{9}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick"}],

StringReplace[qpanelMulti2,{"pn0"->ToString[10],"proc0"->proc10,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{errNO}","inputsize0"->"{5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick"}],
StringReplace[qpanelMulti2,{"pn0"->ToString[11],"proc0"->proc11,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{errNO,err2,err1}","inputsize0"->"{5,5,30}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"3","diag00"->"2","IO00"->"qClick"}],
StringReplace[qpanelMultiTABLE,{"pn0"->ToString[12],"proc0"->proc12,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR),"err0"->"{err2,err2,err2}","inputsize0"->"{5,5,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"3","diag00"->"2","IO00"->"qClick"}] 

};

CDFDeploy[ToFileName[{$UserDocumentsDirectory},"TRSMMULTI.cdf"],Column[Table[ReleaseHold[ToExpression[panelsMIX[[i]]]],{i,1,Length[panelsMIX]}]],
"Method"->"Standalone"];

TEST AREA

Column[Table[ReleaseHold[ToExpression[panelsMIX[[i]]]],{i,1,Length[panelsMIX]}]]