Answer
$$\int (x^2+2x)\cos xdx=(x^2+2x)\sin x+2\cos x(x+1)-2\sin x+C$$
Work Step by Step
$$A=\int (x^2+2x)\cos xdx$$
We would choose $u=x^2+2x$ and $dv=\cos xdx$
For $u=x^2+2x$, $du=(2x+2)dx=2(x+1)dx$
For $dv=\cos xdx$, $v=\sin x$
Apply Integration by Parts to A, we have $$A=uv-\int vdu$$ $$A=(x^2+2x)\sin x-\int\sin x[2(x+1)dx]$$ $$A=(x^2+2x)\sin x-2\int(x+1)\sin xdx$$
We now choose $u'=x+1$ and $dv'=\sin xdx$
For $u'=x+1$, $du'=dx$.
For $dv'=\sin xdx$, $v'=-\cos x$
Apply Integration by Parts a second time to A, we have $$A=(x^2+2x)\sin x-2[u'v'-\int v'du']$$ $$A=(x^2+2x)\sin x-2[-\cos x(x+1)-\int-\cos xdx]$$ $$A=(x^2+2x)\sin x-2[-\cos x(x+1)+\int\cos xdx]$$ $$A=(x^2+2x)\sin x-2[-\cos x(x+1)+\sin x+C]$$ $$A=(x^2+2x)\sin x+2\cos x(x+1)-2\sin x+C$$