For 1D Schrödinger equation, $n$th stationary state wavefunction has exactly $n-1$ zeroes. Thus, $k$th excited state wavefunction has exactly $k$ zeroes. Now if you look at your wavefunction, it's composed from two stationary states:

Count their zeroes (don't take borders into account — they are because of infinite height of well). You'll see that you're right, these states are 1st and 2nd excited states. Your book most likely has a typo.
In more general case, as asked in comments, you have to deal with your wavefunction by definition of superposition of states. Let your function $\psi$ be as follows:
$$\psi=
A\left[ \cos \left(\frac{7 \pi x}{d}\right) + \frac{1}{3}\sin \left(\frac{4 \pi x}{d}\right)\right]$$
And your eigenfunctions are:
$$\phi_k=B_k\sin\left(\frac{k\pi x}d\right)$$
To find how much of $\phi_k$ is in your $\psi$, you find scalar product:
$$\left<\psi|\phi_k\right>=\int_V \psi^*\phi_k dx=\int_0^d AB_k \sin\left(\frac{k\pi x}d\right)\left[\cos\left(\frac{7\pi x}d\right)+\frac13\sin\left(\frac{4\pi x}d\right)\right]dx$$
As $\cos(x)$ is not orthogonal to any $\sin(ax)$ on $[0,d]$, you will have infinitely many non-zero $\left<\psi|\phi_k\right>$:

For comparison let's see what this method gives for original question where there's just a superposition of states 2 & 3:

Here only these 2nd and 3rd states are non-zero.