LIBS

libLIST=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libLIST.m"]<>"\n";
libNAMES=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libNAMES.m"]<>"\n";
libIO=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libIO.m"]<>"\n";
libERR=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libERR.m"]<>"\n";
libGUI=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libGUI.m"]<>"\n";
libML=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libML.m"]<>"\n";
libMISC=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libMISC.m"]<>"\n";
libGraphics=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson 2016/TRSM/QMS202/libs/libGraphics.m"]<>"\n";

libLIST=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libLIST.m"]<>"\n";
libNAMES=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libNAMES.m"]<>"\n";
libIO=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libIO.m"]<>"\n";
libERR=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libERR.m"]<>"\n";
libGUI=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libGUI.m"]<>"\n";
libML=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libML.m"]<>"\n";
libMISC=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libMISC.m"]<>"\n";
libGraphics=ReadString["C:/mathematica/Work/lossofgenerality/QMS202/QUIZES/libGraphics.m"]<>"\n";

Module Area

data1="\n"<>"textfghjkl:="<>ToString[<|

(*fghjkl. removed*)


"0"-><|
"1.1"->{"Column[{ToString[\" \"]"<>"}]"}
|>
,
(* let's use key as the option *)
"1"-><|
"1.1"->{"Column[{ToString[\"1. The county clerk wants to estimate the proportion of voters who will need special election facilities. Suppose a sample of #c voters was taken. If #d need special election facilities, calculate a #a% confidence interval for the population proportion.\"]"<>"}]",
"Column[{ToString[\"1. The county clerk wants to estimate the proportion of voters who will need special election facilities. Calculate a #a% confidence interval for the population proportion if you know that for a sample of #c voters, #d need special election facilities.\"]"<>"}]",
"Column[{ToString[\"1. The mayor of New York wants to estimate the proportion of voters who will need special election facilities in  elections for mayor. Assume a sample of #c voters was taken. If #d need special election facilities, calculate a #a% confidence interval for the population proportion.\"]"<>"}]"}
|>
,
"2"-><|

(*"2.1"->{"Column[{ToString[\"2. If (OverBar[X])=#a, σ=#b and n=#c, the #d% confidence interval estimate for the population mean μ is:\",TraditionalForm]"<>"}, Alignment->Left]"}*)

"2.1"->{"Column[{ToString[\"2. In the past, the proportion of voters, who needed spacial election facilities in a country has been estimated to be #c%. The county clerk wants to construct a #a% confidence interval for the population proportion which extends at most #d to either side of the sample proportion. How large a sample must be taken to assure these conditions are met?\",TraditionalForm]"<>"}, Alignment->Left]"}
|>

,
"3"-><|
"3.1"->{"Column[{ToString[\"3. If you want to be #a% confident in estimating the population mean with a sample of size n to within a sampling error ±#c, where #d ⩽ n ⩽ #e, the standard deviation σ must satisfy:\"]}]"}

|>
,

(*A study from the previous year on a sample of size 300 showed that 50% of office workers respond to e-mail within an hour ±0.05. What is the confidence level of this estimation?*)
"4"-><|
"4.1"->{"Column[{ToString[\"4. A study from the previous year on a sample of size #a showed that #b% of office workers respond to e-mail within an hour ±#c. What is the confidence level of this estimation?\"]"<>"}]"
}
|>
,
"5"-><|
"5.1"->{"Column[{ToString[\"5. The head librarian at the Library of Congress has asked her assistant for an interval estimate of the mean number of books checked out each day. The assistant provides the following interval estimate: from #c to #d books per day. If the head librarian knows that the population standard deviation is #e books checked out per day, and she asked her assistant for a #a% confidence interval, approximately how large was the sample her assistant used to determine the interval estimate?\"]"<>"}]"}
|>
,
"6"-><|
"6.1"->{"Column[{ToString[\"6. A confidence interval was used to estimate the proportion of statistics students who are female. A random sample of #f statistics students generated the following #c% confidence interval: (#d, #e). What sample size would be necessary if we wanted to estimate the true proportion to within #g using #a% confidence?\"]"<>"}]"}
|>



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



data2="listfghjkl:="<>


ToString[{"",""


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

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



canvas1="\n"<>ToString[Hold[Module[{vars=ertyuiop,text,text2,answers, options,locs,data},


text=vars["text"];
Grid[{

{Image[,ImageSize->125]},
{Image[]},   
{"Quiz 2,January 2016"},
{Image[]},
{"id"},
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[2]]}}]},
{Grid[{{"x1",Rasterize@" ⩽ π ⩽ ","x2"}}]},(*ANNA: I changed Z into p *)
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[3]]}}]},
{Grid[{{Rasterize@" n = ","x3"}}]},
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[4]]}}]},
{Grid[{{"x4",Rasterize@ToString[" ⩽σ⩽ ",TraditionalForm],"x5"}}]},
{Image[]},
{Image[]},

{Grid[{{Rasterize@ToExpression@text[[5]]}}]},
{Grid[{{"x6",Rasterize@"%"}}]},
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[6]]}}]},
{Grid[{{Rasterize@" n = ","x7"}}]},
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[7]]}}]},
{Grid[{{Rasterize@" n = ","x8"}}]},
{Image[]}

},Spacings->{0,3}]


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


canvasPRAC1="\n"<>ToString[Hold[Module[{vars=ertyuiop,text,text2,answers, options,locs,data},


text=vars["text"];
Grid[{

{Image[,ImageSize->125]},
{Image[]},   
{"Quiz 2,January 2016"},
(*{Image[]},
{"id"},*)
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[2]]}}]},
{Grid[{{"x1",Rasterize@" ⩽ π ⩽ ","x2"}}]},(*ANNA: I changed Z into p *)
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[3]]}}]},
{Grid[{{Rasterize@" n = ","x3"}}]},
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[4]]}}]},
{Grid[{{"x4",Rasterize@ToString[" ⩽σ⩽ ",TraditionalForm],"x5"}}]},
{Image[]},
{Image[]},

{Grid[{{Rasterize@ToExpression@text[[5]]}}]},
{Grid[{{"x6",Rasterize@"%"}}]},
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[6]]}}]},
{Grid[{{Rasterize@" n = ","x7"}}]},
{Image[]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[7]]}}]},
{Grid[{{Rasterize@" n = ","x8"}}]},
{Image[]}

},Spacings->{0,3}]


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





variation1=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{key,p,x,a,a1,b1,b,c,c1,c2,d,d1,e,e1,f,g,h,i,j,pr,r,z,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp, vars,text,list,sol,aabbee,k, parta, partb, partc, partd,parte,partf,question,list12,teste,sol2,sol3,t},


question=RandomChoice[textfghjkl["0"]];

(*a*)

key=RandomChoice[Keys[textfghjkl["1"]]];
text=RandomChoice[textfghjkl["1"][key]];


Which[key=="1.1", 
a=ToString@(RandomChoice@{99, 95,90,85,80,75,70,65,60});
b=ToString@N[(ToExpression@a)/100];
c=ToString@(RandomSample[Range[4,10],1][[1]]*100);
d=ToString@(ToExpression@c - RandomSample[Range[10,20]][[1]]*10);
pr=ToString@(N[ToExpression@d / ToExpression@c]);
vars={a,b,c,d,pr,r};
r={x/.NSolve[CDF[NormalDistribution[0,1],x]== (1-ToExpression@b)/2,{x}, Reals][[1]],x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-ToExpression@b)/2,{x}, Reals][[1]]};
sol={ToExpression@pr+r[[1]]*Sqrt[ToExpression@pr*(1-ToExpression@pr)/ToExpression@c],ToExpression@pr+r[[2]]*Sqrt[ToExpression@pr*(1-ToExpression@pr)/ToExpression@c]};
(*question=StringReplace[question, { "#a"->a}];*)
parta={StringReplace[text, { "#a"->a,"#b"->b, "#c"->c,"#d"->d}],vars,sol} ;

];



key=RandomChoice[Keys[textfghjkl["2"]]];
text=RandomChoice[textfghjkl["2"][key]];

Which[key=="2.1", 
a=ToString@(RandomChoice@{99, 95,90,85,80,75,70,65,60});
b=ToString@N[(ToExpression@a)/100];
c=ToString@(RandomSample[Range[11,19],1][[1]]);
c2=ToString@(ToExpression@c*0.01);
d=ToString@(RandomSample[Range[4,9],1][[1]]*0.01);
vars={a,b,c,d};
r=x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-ToExpression@b)/2,{x}, Reals][[1]];
e=Ceiling[((r)^2 *( ToExpression@c2)*(1-ToExpression@c2))/((ToExpression@d)^2)];
sol={e};

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

];


key=RandomChoice[Keys[textfghjkl["3"]]];
text=RandomChoice[textfghjkl["3"][key]];

Which[key=="3.1", 

a=ToString@(RandomChoice@{99, 95,90,85,80,75,70,65,60});
b=ToString@N[(ToExpression@a)/100];
c=ToString@(RandomSample[Range[4,9],1][[1]]);
d=ToString@(RandomSample[Range[2,5],1][[1]]*10);
e=ToString@(RandomSample[Range[6,10],1][[1]]*10);

vars={a,b,c,d,e};
sol2=x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-ToExpression@b)/2,{x}, Reals][[1]];
sol={ToExpression@c * Sqrt[ToExpression@d]/sol2,ToExpression@c * Sqrt[ToExpression@e]/sol2};

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

];


key=RandomChoice[Keys[textfghjkl["4"]]];
text=RandomChoice[textfghjkl["4"][key]];

Which[key=="4.1", 
(*ANNA old varaibles*)
(*{b1,d1,c1,a1}=RandomChoice@{{0.5,0.5,0.05,RandomChoice[{200,300}]},{0.6,0.4,0.01,2400},{0.7,0.3,0.01,2100},{0.8,0.2,0.01,1600},{0.9,0.1,0.01,900}};
b=ToString@(IntegerPart[b1*100]);
a=ToString@(a1);
c=ToString@(c1);

vars={a,b,c};

f=ToString@Sqrt[a1*c1^2/(b1*d1)];
g=x/.NSolve[CDF[NormalDistribution[0,1],ToExpression[f]]==1- (1-x)/2,{x}, Reals][[1]];
sol2=(ToExpression@g)*100;
sol={sol2};*)

{b1,d1,c1,a1}=RandomChoice@{{0.5,0.5,0.05,RandomInteger[{10,30}]*10},{0.6,0.4,0.01,RandomInteger[{24,48}]*100},{0.7,0.3,0.01,RandomInteger[{14,21}]*100},{0.8,0.2,0.01,RandomInteger[{16,24}]*100},{0.9,0.1,0.01,RandomInteger[{9,18}]*100}};
b=ToString@(IntegerPart[b1*100]);
a=ToString@(a1);
c=ToString@(c1);
vars={a,b,c};
f=ToString@Sqrt[a1*c1^2/(b1*d1)];
g=x/.NSolve[CDF[NormalDistribution[0,1],ToExpression[f]]==1- (1-x)/2,{x}, Reals][[1]];
sol2=(ToExpression@g)*100;
sol={sol2};



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

key=RandomChoice[Keys[textfghjkl["5"]]];
text=RandomChoice[textfghjkl["5"][key]];

Which[key=="5.1", 
a=ToString@(RandomChoice@{99, 95,90,85,80,75,70,65,60});
b=ToString@N[(ToExpression@a)/100];
f=ToString@(RandomSample[Range[3,9],1][[1]]*10);
c=ToString@(RandomSample[Range[40,80],1][[1]]*10);
d=ToString@(2*ToExpression@f+ ToExpression@c);
e=ToString@(4*ToExpression@f+RandomChoice@{10,-10,20,-20,30});
vars={a,b,c,d,e};
r=x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-ToExpression@b)/2,{x}, Reals][[1]];
sol2=ToString@(Ceiling[Power[(r*ToExpression@e)/ToExpression@f,2]]);
sol={sol2};

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

key=RandomChoice[Keys[textfghjkl["6"]]];
text=RandomChoice[textfghjkl["6"][key]];
];

Which[key=="6.1", 
{a,c}=ToString/@(RandomChoice@{{99,95}, {95,90},{90,85},{85,80},{80,75},{75,70},{70,65},{65,60}});
b=ToString@N[(ToExpression@a)/100];
d1=ToString@(RandomSample[Range[540,700],1][[1]]*0.001);
1-ToExpression@d1;
e1=ToString@(RandomSample[Range[81,95],1][[1]]*0.001);
d=ToString@(ToExpression@d1-ToExpression@e1);
e=ToString@(ToExpression@d1+ToExpression@e1);
f=ToString@(RandomSample[Range[70,97],1][[1]]);
g=ToString@(RandomSample[Range[5,9],1][[1]]*0.01);
vars={a,b,c,d,e,f,g};
r=x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-ToExpression@b)/2,{x}, Reals][[1]];
sol2=Ceiling[((r^2 )* ToExpression@d1*(1-ToExpression@d1))/((ToExpression@g)^2)];
sol={sol2};
partf={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d,"#e"->e,"#f"->f,"#g"->g}],vars,sol} ;

];



vars=ToString[<|"text"->{question, parta[[1]],partb[[1]],partc[[1]],partd[[1]],parte[[1]],partf[[1]]},"vars"->{ parta[[2]],partb[[2]],partc[[2]],partd[[2]],parte[[2]],partf[[2]]}, "sol"->{ parta[[3]],partb[[3]],partc[[3]],partd[[3]],parte[[3]],partf[[3]]}|>,InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{question, parta[[1]],partb[[1]],partc[[1]],partd[[1]],parte[[1]],partf[[1]]},{ parta[[2]],partb[[2]],partc[[2]],partd[[2]],parte[[2]],partf[[2]]}, { parta[[3]],partb[[3]],partc[[3]],partd[[3]],parte[[3]],partf[[3]]}}


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


solution1=data1<>data2<>ToString[Hold[Module[{x, a,b,c,d,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,varse,varsf,g,h,pp,teste,bb1,list123,pos1,t11,t12,t21,t22,s1,s2,sum1,sum2,k},





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



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


body={
{"",""

}, 
{Null ,Null} 
};


Panel[Grid[Transpose[body]]]

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


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


body={ 
{""
},
{Null}
};

Panel[Grid[Transpose[body]]]

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

Cloud Area

(* all err functions need to be called here since the Send is entirely happens in one unit *)

sendTEST[a0_]:=If[CloudSymbol["Q2QMS202"]==1,send[a0,True],"Test Disabled"];

sendPRAC[a0_]:=send[a0,False];

send[a0_,test_]:=Module[{a,b,c,d,e,sol0,canvas0,err,err2,err3,err4,err5,err6,resF,canvas,vars,sol,sol1,sol2,sol3,sol4,sol5,sol6,μ,σ,g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,n,xbar,d1,d2,x,df,col, body={},gr,arrow,pr,r,text,url},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
ToExpression@libGraphics;
If[ test==True, body={a0["id"]}, body={}];


{canvas,text,vars,sol}=ReleaseHold[ToExpression[a0["q"],InputForm]];
sol1=Sort[(ToExpression@sol)[[1]],Less];
{a,b,c,d,pr,r}=(ToExpression@vars)[[1]];

μ=pr;
σ=Sqrt[pr*(1-pr)/c];

err=If[Norm[{ToExpression@(a0["x1"]),ToExpression@(a0["x2"])}-sol1]<0.01, 1, 0];

g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-3*σ+μ,3*σ+μ},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"μ="<>ToString[μ]<>", σ="<>ToString[σ], PlotRange->Full,AxesOrigin->{μ,0}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,sol1[[1]],sol1[[2]]},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"μ="<>ToString[μ]<>", σ="<>ToString[σ], PlotRange->Full,AxesOrigin->{μ,0},FillingStyle->{Red}];


sol2=ToExpression@sol[[2]];
err2=If[Abs[(ToExpression@(a0["x3"]))-sol2[[1]]]<0.01, 1, 0];

AppendTo[body, err];
AppendTo[body, err2];

col={

Image[,ImageSize->125],
" ",
"F16 QMS 202",
"Practice Questions for Lecture 2\nJanuary 2016",
Image[],
" ",
If[test==True,"Student ID:"<>a0["id"],Nothing],
" ",
" ",
ToExpression@text[[1+1]],
If[err==1, "Correct",Style["Incorrect",Red]],"Your answers:",Row@{a0["x1"],", ",a0["x2"]},"Solutions:",Row@{sol1[[1]],", ",sol1[[2]]},plotCONF[μ,σ,sol1[[1]],sol1[[2]]],
\[SelectionPlaceholder],
" ",
ToExpression@text[[1+2]],
If[err2==1, "Correct", Style["Incorrect",Red]],"Your answers:",a0["x3"],"Solutions:",sol2[[1]],"Visualization:",gr={"Determining Sample Size\nfor the Proportion"->TraditionalForm["e=(Subscript[Z, (α/2)])(Sqrt[((π (1 - π))/n)])"],TraditionalForm["e=(Subscript[Z, (α/2)])(Sqrt[((π (1 - π))/n)])"]->"Now solve\n for n to get","Now solve\n for n to get"->TraditionalForm["n=((((Subscript[Z, (α/2)])^2) π (1 - π))/(e^2))"]};arrow=;
LayeredGraphPlot[gr,VertexLabeling->True,EdgeRenderingFunction->({Line[#],Inset[arrow,Mean[#1],Automatic,Automatic,#[[2]]-#[[1]],Background->White]}&),PlotRangePadding->0.4,ImageSize->320],

\[SelectionPlaceholder],
" ",

sol3=Sort[(ToExpression@sol)[[3]],Less];
err3=If[Norm[{ToExpression@(a0["x4"]),ToExpression@(a0["x5"])}-sol3]<0.01, 1, 0];
{a,b,c,d,e}=(ToExpression@vars)[[3]];
df=b;
ToExpression@text[[1+3]],
If[err3==1, "Correct",Style["Incorrect",Red]],
"Your answers:",Row@{a0["x4"],", ",a0["x5"]},"Solutions:",Row@{sol3[[1]],", ",sol3[[2]]},
μ=0;
σ=Mean@sol3;
plotCONFLINE[μ,σ, -c,c],
\[SelectionPlaceholder],
" ",
(*sol4=(sol)[[4]],*) (* no ToExpression for text *)
sol4=(ToExpression@sol)[[4]];
err4=If[Abs[(ToExpression@(a0["x6"]))-sol4[[1]]]<0.01, 1, 0];
(*"4. "<>If[MemberQ[sol4[[1]],a0["x6" ]]==True, err4=1;"Correct",err4=0;"Incorrect"],*)
ToExpression@text[[1+4]],
If[err4==1, "Correct", Style["Incorrect",Red]],"Your answers:",Row@{a0["x6"],"%"},"Solutions:",Row@{sol4[[1]],"%"},
\[SelectionPlaceholder],
" ",
sol5=ToExpression@sol[[5]];
err5=If[Abs[(ToExpression@(a0["x7"]))-sol5[[1]]]<0.01, 1, 0];
ToExpression@text[[1+5]],
If[err5==1, "Correct", Style["Incorrect",Red]],"Your answers:",a0["x7"],"Solutions:",sol5[[1]],
\[SelectionPlaceholder],
" ",
sol6=ToExpression@sol[[6]];
err6=If[Abs[(ToExpression@(a0["x8"]))-sol6[[1]]]<0.01, 1, 0];
ToExpression@text[[1+6]],
If[err6==1, "Correct", Style["Incorrect",Red]],"Your answers:",a0["x8"],"Solutions:",sol6[[1]],
\[SelectionPlaceholder],
" "(*,
"Review:",
gr={"Determining Sample Size"->"For the Proportion",
"Determining Sample Size"->"For the Mean",

"For the Mean"->Row[{"(OverBar[X])±",Labeled["(Subscript[Z, (α/2)])(σ/(Sqrt[n]))", "e",Frame->True,LabelStyle->Red,FrameStyle->Directive[Top,Red]]}],

Row[{"(OverBar[X])±",Labeled["(Subscript[Z, (α/2)])(σ/(Sqrt[n]))", "e",Frame->True,LabelStyle->Red,FrameStyle->Directive[Top,Red]]}]->"Now solve\n for n to get ",
"Now solve\n for n to get "->TraditionalForm["n=((((Subscript[Z, (α/2)])^2)(σ^2))/(e^2))"],
"For the Proportion"->TraditionalForm["e=(Subscript[Z, (α/2)])(Sqrt[((π(1 - π))/n)])"],TraditionalForm["e=(Subscript[Z, (α/2)])(Sqrt[((π(1 - π))/n)])"]->"Now solve\n for n to get","Now solve\n for n to get"->TraditionalForm["n=((((Subscript[Z, (α/2)])^2)π(1 - π))/(e^2))"]};arrow=;
LayeredGraphPlot[gr,VertexLabeling->True,EdgeRenderingFunction->({Line[#],Inset[arrow,Mean[#1],Automatic,Automatic,#[[2]]-#[[1]],Background->White]}&),PlotRangePadding->0.4,ImageSize->320]*)

 };

AppendTo[body,err3];
AppendTo[body,err4];
AppendTo[body,err5];
AppendTo[body,err6];

AppendTo[body,"Q2"];
AppendTo[body,"QMS202"];
AppendTo[body,"BOZA"];

url=CloudExport[Column@col,"PNG",Permissions->"Public"][[1]];

AppendTo[body,ToString@url];

If[test==True,resF=URLFetch["http://symbolicexams.lossofgenerality.com/wp-content/plugins/test-receiver/results.php","Parameters"->{"results"->(ToString@body)},"ReadTimeout"->10,"ConnectTimeout"->50,"Method"->"POST"]];

(*URLFetch["https://datadrop.wolframcloud.com/api/v1.0/Add?bin=9ojl2NtL&data="<>(ToString@body)(*,"Username"->"wayne@compclassnotes.com", "Password"->"Wolf!123"*)];*)

If[test==True,DatabinAdd[Databin["9ojl2NtL"],body]];
HTTPRedirect@url
];








(* all err functions need to be called here since the Send is entirely happens in one unit *)
sendLOCAL[a0_]:=Module[{a,b,c,d,e,sol0,canvas0,err,err2,err3,err4,err5,err6,resF,canvas,vars,sol,sol1,sol2,sol3,sol4,sol5,sol6,μ,σ,g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,n,xbar,d1,d2,x,df,col, body={}},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
body={a0["id"]};

μ=0;σ=1;
{canvas,vars,sol}=ReleaseHold[ToExpression[a0["q"],InputForm]];
sol1=Sort[(ToExpression@sol)[[1]],Less];

err=If[Norm[{ToExpression@(a0["x1"]),ToExpression@(a0["x2"])}-sol1]<0.01, 1, 0];

g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-3,3},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"μ="<>ToString[μ]<>", σ="<>ToString[σ], PlotRange->Full,AxesOrigin->{μ,0}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,sol1[[1]],sol1[[2]]},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"μ="<>ToString[μ]<>", σ="<>ToString[σ], PlotRange->Full,AxesOrigin->{μ,0},FillingStyle->{Red}];
g3=Plot[PDF[NormalDistribution[μ,σ],x],{x,sol1[[1]]-0.2,sol1[[2]]+0.2},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"μ="<>ToString[μ]<>", σ="<>ToString[σ], PlotRange->Full,AxesOrigin->{(sol1[[1]]+sol1[[2]])/2,0}];
g4=Plot[PDF[NormalDistribution[μ,σ],x],{x,sol1[[1]],sol1[[2]]},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"μ="<>ToString[μ]<>", σ="<>ToString[σ], PlotRange->Full,AxesOrigin->{(sol1[[1]]+sol1[[2]])/2,0},FillingStyle->{Red}];




sol2=ToExpression@sol[[2]];
err2=If[Abs[(ToExpression@(a0["x3"]))-sol2[[1]]]<0.01, 1, 0];

AppendTo[body, err];
AppendTo[body, err2];

col={

Image[,ImageSize->125],
" ",
"F16 QMS 202",
"Practice Questions for Lecture 2\nJanuary 2016",
Image[],
" ",
"1. "<>If[err==1, "Correct","Incorrect"],"Your answers:",Row@{a0["x1"],", ",a0["x2"]},"Solutions:",Row@{sol1[[1]],", ",sol1[[2]]},Column@{Show[g1,g2,ImageSize->400],"Magnify Red region:",Show[g3,g4,ImageSize->400]},

"2. "<>If[err2==1, "Correct", "Incorrect"],"Your answers:",a0["x3"],"Solutions:",sol2[[1]],"Visualization:",gr={"Determining Sample Size"->"For the Proportion","For the Proportion"->TraditionalForm["e=Z(Sqrt[((π (1 - π))/n)])"],TraditionalForm["e=Z(Sqrt[((π (1 - π))/n)])"]->"Now solve\n for n to get","Now solve\n for n to get"->TraditionalForm["n=(((Z^2) π (1 - π))/(e^2))"],
"Now solve\n for n to get"->"?"};arrow=;
LayeredGraphPlot[gr,VertexLabeling->True,EdgeRenderingFunction->({Line[#],Inset[arrow,Mean[#1],Automatic,Automatic,#[[2]]-#[[1]],Background->White]}&),PlotRangePadding->0.4,ImageSize->320],


" ",

sol3=Sort[(ToExpression@sol)[[3]],Less];

err3=If[Norm[{ToExpression@(a0["x4"]),ToExpression@(a0["x5"])}-sol3]<0.01, 1, 0];

(*sol3=(ToExpression@sol)[[3]];
err3=If[ToExpression@(a0["x5"])-(Abs[sol3[[1]]])<0.01, 1, 0];*)
{a,b,c,d,e}=ToExpression@vars[[3]];
df=b;
(*g8=Plot[PDF[StudentTDistribution[df],x],{x,-8,8},Filling->Axis,PlotRange->All];
g9=Plot[PDF[StudentTDistribution[df],x],{x,sol3[[2]],8},Filling->Axis,PlotStyle->Red, AxesOrigin->{0,0},PlotRange->All];
g10=Plot[PDF[StudentTDistribution[df],x],{x,-8,sol3[[1]]},Filling->Axis,PlotStyle->Red, AxesOrigin->{0,0},PlotRange->All];*)
"3. "<>If[err3==1, "Correct","Incorrect"],
"Your answers:",Row@{a0["x4"],", ",a0["x5"]},"Solutions:",Row@{sol3[[1]],", ",sol3[[2]]}
(*,
Show[g8,g9,g10, ImageSize->400],*)
" ",
(*sol4=(sol)[[4]],*) (* no ToExpression for text *)
sol4=(ToExpression@sol)[[4]];
err4=If[Abs[(ToExpression@(a0["x6"]))-sol4[[1]]]<0.01, 1, 0];
(*"4. "<>If[MemberQ[sol4[[1]],a0["x6" ]]==True, err4=1;"Correct",err4=0;"Incorrect"],*)
"4. "<>If[err4==1, "Correct", "Incorrect"],"Your answers:",Row@{a0["x6"],"%"},"Solutions:",Row@{sol4[[1]],"%"},

" ",
sol5=ToExpression@sol[[5]];
err5=If[Abs[(ToExpression@(a0["x7"]))-sol5[[1]]]<0.01, 1, 0];
"5. "<>If[err5==1, "Correct", "Incorrect"],"Your answers:",a0["x7"],"Solutions:",sol5[[1]],
" ",
sol6=ToExpression@sol[[6]];
err6=If[Abs[(ToExpression@(a0["x8"]))-sol6[[1]]]<0.01, 1, 0];
"6. "<>If[err6==1, "Correct", "Incorrect"],"Your answers:",a0["x8"],"Solutions:",sol6[[1]],
" "

 };


AppendTo[body,err3];
AppendTo[body,err4];
AppendTo[body,err5];
AppendTo[body,err6];


local`body=Column@{body,col}
];





genFormLOCAL[]:=Module[{a,sol0,canvas0,err,resF,canvas,vars,sol,f,ans},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
f[]:=(ToString[ReleaseHold[ToExpression[StringReplace[variation1,{"canvasZ"->canvas1,"fghjkl"->ToString[1]}]]],InputForm]); (* InputForm must be here or some problems occurs in ToExpression@variation *)
ans={
{"x1",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x2",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x3",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x4",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x5",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x6",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "96.7",  "Help" -> ""|>,
{"x7",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x8",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"id",""}-><|"Interpreter"->"String","Help" -> "","Hint"->"Enter Student ID"|>,
"q"->"String"};

FormFunction[ans,sendLOCAL,  AppearanceRules-><|"SubmitLabel" -> "Send Answers"|>,

FormLayoutFunction->Function[


(* we need to use sol in send[] in order to see if the student input is correct or not?*)

{canvas,text,vars,sol}=ReleaseHold[ToExpression[Setting@#["q"][[1]][[1]][[2]][[1]]]];

ReleaseHold[ToExpression[canvas,InputForm]/.{"x1"->#["x1"],"x2"->#["x2"],"x3"->#["x3"],"x4"->#["x4"],"x5"->#["x5"],"x6"->#["x6"],"x7"->#["x7"],"x8"->#["x8"],"id"->#["id"]}]


], FormTheme -> "Blue"]["q"->f[]]






];

genFormTEST[a0_]:=Module[{a,sol0,canvas0,err,resF,canvas,vars,sol,f,ans,text},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
f[]:=(ToString[ReleaseHold[ToExpression[StringReplace[variation1,{"canvasZ"->canvas1,"fghjkl"->ToString[1]}]]],InputForm]); (* InputForm must be here or some problems occurs in ToExpression@variation *)
ans={
{"x1",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x2",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x3",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x4",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x5",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x6",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "96.7",  "Help" -> ""|>,
{"x7",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x8",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"id",""}-><|"Interpreter"->"String","Help" -> "","Hint"->"Enter Student ID"|>,
"q"->"String"};

HTTPRedirect@CloudDeploy[FormFunction[ans,sendTEST,  AppearanceRules-><|"SubmitLabel" -> "Send Answers"|>,

FormLayoutFunction->Function[


(* we need to use sol in send[] in order to see if the student input is correct or not?*)

{canvas,text,vars,sol}=ReleaseHold[ToExpression[Setting@#["q"][[1]][[1]][[2]][[1]]]];

ReleaseHold[ToExpression[canvas,InputForm]/.{"x1"->#["x1"],"x2"->#["x2"],"x3"->#["x3"],"x4"->#["x4"],"x5"->#["x5"],"x6"->#["x6"],"x7"->#["x7"],"x8"->#["x8"],"id"->#["id"]}]


], FormTheme -> "Blue"]["q"->f[]], 

Permissions->"Public"][[1]]







];

genFormPRAC[a0_]:=Module[{a,sol0,canvas0,err,resF,canvas,vars,sol,f,ans,text},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
f[]:=(ToString[ReleaseHold[ToExpression[StringReplace[variation1,{"canvasZ"->canvasPRAC1,"fghjkl"->ToString[1]}]]],InputForm]); (* InputForm must be here or some problems occurs in ToExpression@variation *)
ans={
{"x1",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x2",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x3",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x4",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x5",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x6",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "96.7",  "Help" -> ""|>,
{"x7",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x8",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
(*{"id",""}-><|"Interpreter"->"String","Help" -> "","Hint"->"Enter Student ID"|>,*)
"q"->"String"};

HTTPRedirect@CloudDeploy[FormFunction[ans,sendPRAC,  AppearanceRules-><|"SubmitLabel" -> "Send Answers"|>,

FormLayoutFunction->Function[


(* we need to use sol in send[] in order to see if the student input is correct or not?*)

{canvas,text,vars,sol}=ReleaseHold[ToExpression[Setting@#["q"][[1]][[1]][[2]][[1]]]];

ReleaseHold[ToExpression[canvas,InputForm]/.{"x1"->#["x1"],"x2"->#["x2"],"x3"->#["x3"],"x4"->#["x4"],"x5"->#["x5"],"x6"->#["x6"],"x7"->#["x7"],"x8"->#["x8"](*,"id"->#["id"]*)}]


], FormTheme -> "Blue"]["q"->f[]], 

Permissions->"Public"][[1]]







];

DEPLOY TEST

DeleteFile[c];
c=CloudDeploy[FormFunction[{},
genFormTEST,  AppearanceRules-><|"SubmitLabel" -> "Start"|>,

FormLayoutFunction->Function[



(* we need to use sol in send[] in order to see if the student input is correct or not?*)

Column[{Image[,ImageSize->125],  
Spacer@100,
"F16 QMS 202",
"Practice Questions for Lecture 2\nJanuary 2016",
Image[,ImageSize->5],
Spacer@100,

"Press Start button to start the test"
}]




], FormTheme -> "White"], 

Permissions->"Public"]

DEPLOY PRAC

DeleteFile[c];
c=CloudDeploy[FormFunction[{},
genFormPRAC,  AppearanceRules-><|"SubmitLabel" -> "Start"|>,

FormLayoutFunction->Function[



(* we need to use sol in send[] in order to see if the student input is correct or not?*)

Column[{Image[,ImageSize->125],
Spacer@100,
"F16 QMS 202",
"Practice Questions for Lecture 2\nJanuary 2016",
Image[,ImageSize->5],
Spacer@100,

"Press Start button to start the test"
}]




], FormTheme -> "White"], 

Permissions->"Public"]

LOCAL TEST AREA

The local form is slow, take a second to refresh the input fields. Also the Send Answer Button might not chave colour properly.

genFormLOCAL[]

local`body

ON-Off

ON

$Permissions = "Public";
on[]:=Module[{},CloudSymbol["Q2QMS202"]=1;SetPermissions[CloudObject[MouseOver], "Public"]];
CloudDeploy[

APIFunction[{},on[]&],Permissions->"Public"]

Off

$Permissions = "Public";
off[]:=Module[{},CloudSymbol["Q2QMS202"]=0;SetPermissions[CloudObject[MouseOver], "Private"]];
CloudDeploy[

APIFunction[{},off[]&],Permissions->"Public"]

Statistics Report

f[date_]:=Module[{grades,mean},grades=Values[Databin["9ojl2NtL"]][[All,2;;7]];

If[grades!={},
grades=Table[If[NumberQ[#]&/@grades[[i]]=={True,True,True,True,True,True},grades[[i]],Nothing], {i,1,Length@grades}],grades={{0,0,0,0,0,0}}];
mean=Mean@grades;
PieChart3D[N@mean, ChartLabels->Range[6],LabelingFunction->"VerticalCallout",PlotLabel->"QMS202, Quiz2\nProf Tasic\n"<>date,ImageSize->400]]

InputForm[CloudDeploy[Delayed[f[DateString[]]], Permissions->"Public"][[1]]]