(a) Since \(AB=5\) and \(BC=p\),
\( AC=5+p \).
When \(p=4\), \( AC=9 \).
In right-angled triangle \(ACD\), \( \angle A=\frac{\pi}{6} \), so
\( AD=AC\cos\frac{\pi}{6}=9\cdot\frac{\sqrt3}{2}=\frac{9\sqrt3}{2} \),
and
\( CD=AC\sin\frac{\pi}{6}=9\cdot\frac12=\frac92 \).
Also \( AE=5 \), so
\( ED=AD-AE=\frac{9\sqrt3}{2}-5 \).
The arc length \(BE\) is
\( 5\cdot\frac{\pi}{6}=\frac{5\pi}{6} \).
The perimeter of the shaded region is
\( ED+DC+CB+\text{arc }BE \).
\( =\left(\frac{9\sqrt3}{2}-5\right)+\frac92+4+\frac{5\pi}{6} \).
Answer: \( \frac{9\sqrt3}{2}+\frac72+\frac{5\pi}{6} \).
(b) The shaded area is the area of triangle \(ACD\) minus the area of sector \(ABE\).
\( AC=5+p \).
The area of triangle \(ACD\) is
\( \frac12(AC\cos\frac{\pi}{6})(AC\sin\frac{\pi}{6}) \).
\( =\frac12(5+p)^2\cdot\frac{\sqrt3}{2}\cdot\frac12 \).
\( =\frac{\sqrt3}{8}(5+p)^2 \).
The area of sector \(ABE\) is
\( \frac12(5^2)\left(\frac{\pi}{6}\right)=\frac{25\pi}{12} \).
So
\( \frac{\sqrt3}{8}(5+p)^2-\frac{25\pi}{12}=8\sqrt3-\frac{25\pi}{12} \).
\( \frac{\sqrt3}{8}(5+p)^2=8\sqrt3 \).
\( (5+p)^2=64 \).
Since \(p>0\), \(5+p=8\).
Answer: \( p=3 \).