Example. The maximum and minimum values of the function $y=\cos ^{2} x+2 p \sin x+q$ are 10 and 7, respectively. Find the values of $p$ and $q$.
$$
\begin{array}{l}
\text { Solve } y=-(\sin x-p)^{2}+p^{2}+q+1 . \\
\text { i) If } -p>1, y_{\text { max }}=-(-1-p)^{2} \\
+p^{2}+q+1=-2 p+q, \quad y_{\text { min }}=-(1-p)^{2} \\
+p^{2}+q+1=2 p+q .
\end{array}
$$

Solve $-2 p+q=10, 2 p+q=7$, we get $p=-\frac{3}{4}$ which contradicts $p<-1$.
ii) If $-p<-1$, similarly, we get $p=\frac{3}{4}$, which is a contradiction.
iii) If $-1 \leqslant -p \leqslant 1$, i.e., $-1 \leqslant p \leqslant 1$, $y_{\text { max }}=p^{2}+q+1$.

Assume $-1 \leqslant -p<0, y_{\text { min }}=-2 p+q$, then from $\left\{\begin{array}{l}p^{2}+q+1=10, \\ -2 p+q=7\end{array}\right.$ we solve $\left\{\begin{array}{l}p=-1+\sqrt{3}, \\ q=5+2 \sqrt{3} ;\end{array}\right.$

If $0 \leqslant -p \leqslant 1, y_{\text { min }}=2 p+q$, we can solve $\left\{\begin{array}{l}p^{2}+q+1=10, \\ 2 p+q=7\end{array}\right.$ to get $\left\{\begin{array}{l}p=1-\sqrt{3}, \\ q=5+2 \sqrt{3}\end{array}\right.$
(Author's address: Fuzhou No.1 High School, ShaoWu, Fujian)
$$