Step 1: Write the required area.
Since area is always positive, we take modulus where the curve is below the \(x\)-axis.
\[
A = \int_{-\frac{\pi}{2}}^{\pi} |\cos x|dx
\]
Step 2: Identify sign of \( \cos x \).
\[
\cos x \geq 0 \text{ on } \left[-\frac{\pi}{2},\frac{\pi}{2}\right]
\]
and
\[
\cos x \leq 0 \text{ on } \left[\frac{\pi}{2},\pi\right]
\]
Step 3: Split the integral.
\[
A = \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \cos x\,dx - \int_{\frac{\pi}{2}}^{\pi} \cos x\,dx
\]
Step 4: Integrate.
\[
\int \cos x\,dx = \sin x
\]
Step 5: Evaluate first integral.
\[
\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \cos x\,dx
=
\sin\frac{\pi}{2}-\sin\left(-\frac{\pi}{2}\right)
\]
\[
= 1-(-1)=2
\]
Step 6: Evaluate second integral.
\[
-\int_{\frac{\pi}{2}}^{\pi} \cos x\,dx
=
-\left[\sin x\right]_{\frac{\pi}{2}}^{\pi}
\]
\[
=-(0-1)=1
\]
Step 7: Final conclusion.
\[
A = 2+1=3
\]
\[
\boxed{3 \text{ sq units}}
\]