Manipulate[
u=Range[0,2,2/n];

(*piecewise defined approximating functions*)
left=Piecewise[
Table[{g[u[[k]]],u[[k]]<=x<=u[[k+1]]},{k,1,Length[u]-1}]];
mid=Piecewise[
Table[{g[(u[[k]]+u[[k+1]])/2],u[[k]]<=x<=u[[k+1]]},{k,1,Length[u]-1}]];
right=Piecewise[
Table[{g[u[[k+1]]],u[[k]]<=x<=u[[k+1]]},{k,1,Length[u]-1}]];
trap=Piecewise[
Table[{Interpolation[{{u[[k]],g[u[[k]]]},{u[[k+1]],g[u[[k+1]]]}},InterpolationOrder->1][x],u[[k]]<x<u[[k+1]]},{k,1,Length[u]-1}]];
simp=Piecewise[
Table[{Interpolation[{{u[[2k+1]],g[u[[2k+1]]]},{u[[2k+2]],g[u[[2k+2]]]},{u[[2k+3]],g[u[[2k+3]]]}},InterpolationOrder->2][x],u[[2k+1]]≤x<=u[[2k+3]]},{k,0,Length[u]/2 -3/2}]];
approxgraph[x_]:=Switch[method,"left sum",left,"right sum",right,"midpoint",mid,"trapezoid",trap,"Simpson",simp];

(*area approximation calculations*)
leftarea=N[Sum[g[u[[i]]]*(2/n),{i,1,Length[u]-1}]];
rightarea=N[Sum[g[u[[i+1]]]*(2/n),{i,1,Length[u]-1}]];
midarea=N[Sum[g[(u[[i]]+u[[i+1]])/2]*(2/n),{i,1,Length[u]-1}]];
traparea=N[Sum[(g[u[[i]]]+g[u[[i+1]]])/2*(2/n),{i,1,Length[u]-1}]];
simparea=N[(g[u[[1]]]+g[u[[Length[u]]]]+Sum[4*g[u[[i]]]*Mod[i+1,2],{i,2,Length[u]-1}]+Sum[2*g[u[[i]]]*Mod[i,2],{i,2,Length[u]-1}])*(2/n)/3];
approxarea=Switch[method,"left sum",leftarea,"right sum",rightarea,"midpoint",midarea,"trapezoid",traparea,"Simpson",simparea];
exactarea=N[Integrate[g[x],{x,0,2}]];

(*points on curve used in each method*)
endpt=Table[{u[[k]],g[u[[k]]]},{k,1,Length[u]}];
endptline=Table[{{u[[k]],0},{u[[k]],g[u[[k]]]}},{k,1,Length[u]}];
midpt=Table[{(u[[k]]+u[[k+1]])/2,g[(u[[k]]+u[[k+1]])/2]},{k,1,Length[u]-1}];
simpline=Table[{{u[[2k+1]],0},{u[[2k+1]],g[u[[2k+1]]]}},{k,0,Length[u]/2 -3/2}];
dots=ListPlot[Switch[method,"left sum",endpt,"right sum",endpt,"midpoint",midpt,"trapezoid",endpt,"Simpson",endpt]];
segments=ListLinePlot[Switch[method,"left sum",endptline,"right sum",endptline,"midpoint", endptline,"trapezoid",endptline,"Simpson",simpline],PlotRange->All];

(*magnified graphics*)
yscale=Which[g[x]===Sin[x],.5,g[x]===2x+1,2.5,g[x]===x^2,2,g[x]===Exp[-2x],.5,g[x]===5x^(1/3),3.2,True,1];
If[zoom==False,a={1,yscale},Null];
zoomgraph=
Show[{
Plot[{g[x],approxgraph[x]},
{x,a[[1]]-.1,a[[1]]+.1},PlotRange->{a[[2]]-.1*yscale,a[[2]]+.1*yscale},Frame->True,FrameTicks->None,FrameStyle->Thick,Background->White,Filling->Bottom,PlotPoints->100,Axes->False],
dots,
segments}];

(*graphics to Manipulate*)
Grid[
(*plots - first row*)
{{Show[{
Plot[{g[x],approxgraph[x]},{x,0,2},Filling->Axis,PlotPoints->300,PlotRange->{0,Automatic}],
dots,
segments,
If[zoom==True,Graphics[Inset[zoomgraph,{a[[1]],a[[2]]},Automatic]],Graphics[Inset[" ",{0,0}]]]
},ImageSize->{550,300}]},


(*text - second row*)
{Framed@Text@Column[{
Style[Row[{"(∫_0^2)",TraditionalForm[g[x]],"",Style["dx",Italic]}],Black,16],
Row[{
Style[Row[{"approximate area = ",NumberForm[approxarea,{6,5}]}],Purple,16],
"    ",
Style[Row[{"exact area = ",NumberForm[exactarea,{6,5}]}],Blend[{Gray,Blue},1/2],16]
}],
Style[Row[{"|error| = ",ScientificForm[Abs[approxarea-exactarea],3]}],16]
},Alignment->Center]
}
}],

(*parameters for Manipulate*)
{{g,((Exp[-2*#])&),"function"},
{Sin->TraditionalForm[Sin[x]],
((2*#+1)&)->TraditionalForm[2*x+1],
((#^2)&)->TraditionalForm[x^2],
((Exp[-2*#])&)->TraditionalForm[Exp[-2*x]],
((5*#^(1/3))&)->TraditionalForm[5*x^(1/3)],
((2/(#^2+1))&)->TraditionalForm[2/(x^2+1)]},
ControlType->PopupMenu},
{{zoom,False,"magnifying tool"},{True,False}},
{{a,{.865,.46}},PlotRange->1,Locator,
Enabled->zoom,Appearance->None},
{{n,4,"subintervals"},2,40,2,Appearance->"Labeled"},
{{method,"midpoint"},{"left sum","right sum","midpoint","trapezoid","Simpson"}},
AutorunSequencing->{2,3,4},
TrackedSymbols->True]