Answer
$g'\left( x \right) = 3 - {x^2}\sin x + 2x\cos x$
Work Step by Step
$$\eqalign{
& g\left( x \right) = 3x + {x^2}\cos x \cr
& {\text{Differentiating}} \cr
& g'\left( x \right) = \frac{d}{{dx}}\left[ {3x + {x^2}\cos x} \right] \cr
& {\text{Use sum rule for derivatives}} \cr
& g'\left( x \right) = \frac{d}{{dx}}\left[ {3x} \right] + \frac{d}{{dx}}\left[ {{x^2}\cos x} \right] \cr
& g'\left( x \right) = 3\frac{d}{{dx}}\left[ x \right] + \frac{d}{{dx}}\left[ {{x^2}\cos x} \right] \cr
& {\text{for }}\frac{d}{{dx}}\left[ {{x^2}\cos x} \right]{\text{ use the product rule for derivatives}} \cr
& g'\left( x \right) = 3\frac{d}{{dx}}\left[ x \right] + {x^2}\frac{d}{{dx}}\left[ {\cos x} \right] + \cos x\frac{d}{{dx}}\left[ {{x^2}} \right] \cr
& {\text{Use the Derivatives of Trigonometric Functions and}} \cr
& {\text{the basic rules for derivatives }}\frac{d}{{dx}}\left[ x \right] = 1,{\text{ }}\frac{d}{{dx}}\left[ {{x^n}} \right] = n{x^{n - 1}} \cr
& g'\left( x \right) = 3\left( 1 \right) + {x^2}\left( { - \sin x} \right) + \cos x\left( {2x} \right) \cr
& {\text{Simplify}} \cr
& g'\left( x \right) = 3 - {x^2}\sin x + 2x\cos x \cr} $$