Since I see variables $(p,q)$ I suppose you are dealing with a 2-dimensional phase space with standard symplectic structure $\Omega=dq\wedge dp$. So you have
$$ \{f,g\}=\Omega(X_f,X_g) $$ and this could be a way to compute the bracket, where $X_f,X_g$ are the Hamiltonian vector fields of the two functions.
Otherwise you can just use the coordinate based definition
$$ \{f,g\} = (\partial_q f)(\partial_pg)-(\partial_pf)(\partial_qg). $$
So in the first exercise you have
$$\{f,g\}=(1)(3p^2+1)=3p^2+1, $$
while in the second one you have
$$\{f,g\}=(\cos{q})(-sin{p})=-\cos{(q)}\sin{(p)}. $$
Just to complete my answer, starting from the characterization $\{f,g\}=\Omega(X_f,X_g)$ you can think about the Poisson bracket even in geometrical terms and hence complete the computations in an alternative way:
$$\Omega(X_f,X_g)=i_{X_f}X_g=df(X_g)=\mathcal{L}_{X_g}f$$
which is the Lie derivative of $f$ along $X_g$.
Let's do again the computations for the first example with this approach, just to check they are alternative procedures:
$$ X_g = \begin{bmatrix} 3p^2+1 \\ 0 \end{bmatrix} $$
$$ \nabla f = \begin{bmatrix} 1 \\ 0 \end{bmatrix} $$
$$\{f,g\}=\mathcal{L}_{X_g}f=X_g\cdot \nabla f = 3p^2+1, $$
which confirms the previous (and easier) computation.