$\int_0^{\frac{\pi}{2}} \frac{cos(x)}{p\sin(x) + q\cos(x)}dx$, where $p,q$ are positive constants

The form of the second linear combination in (i) suggests the correct coefficients for (ii): $$pI-qJ=\int_0^{\pi/2}\frac{p\cos x-q\sin x}{p\sin x+q\cos x}\,dx=\ln\frac pq$$ This leads to a linear system with determinant $p^2+q^2>0$ for $I,J$ which can be easily solved: $$I=\frac{q\pi+2p\log p/q}{2(p^2+q^2)}\qquad J=\frac{p\pi-2q\log p/q}{2(p^2+q^2)}$$


You have defined$$I=\int_0^{\pi/2}\frac{\cos(x)}{p\sin(x)+q\cos(x)}\,\mathrm dx.$$If you do $x=\frac\pi2-y$ and $\mathrm dx=-\mathrm dy$, then you deduce that$$I=-\int_{\pi/2}^0\frac{\sin(y)}{p\cos(y)+q\sin(y)}\,\mathrm dy=\int_0^{\pi/2}\frac{\sin(x)}{q\sin(x)+p\cos(x)}\,\mathrm dx.$$By the same argument,$$J=\int_0^{\pi/2}\frac{\cos(x)}{q\sin(x)+p\cos(x)}\,\mathrm dx,$$and therefore$$pI-qJ=\int_0^{\pi/2}\frac{p\sin(x)-q\cos(x)}{q\sin(x)+p\cos(x)}\,\mathrm dx.$$And now if you differentiate the denominator, you get minus the numerator. So,$$pI-qJ=\log(p)-\log(q).$$Since $qI+pJ=\frac\pi2$, you get that$$I=\frac{-2p\log(q)+2p\log(p)+\pi q}{2\left(p^2+q^2\right)}\quad\text{and that}\quad J=\frac{-2q\log(p)+2q\log(q)+\pi p}{2 \left(p^2+q^2\right)}.$$