On the integral $\int\sqrt{1+\cos x}\text{d} x$
The function to be integrated is $$ \sqrt{1+\cos x}=\sqrt{2}\left|\cos\frac{x}{2}\right| $$ so we can as well consider the simpler $$ \int\lvert\cos t\rvert\,dt $$ or, with $t=u+\pi/2$, the even simpler $$ \int|\sin u|\,du $$ One antiderivative is $$ \int_0^u\lvert\sin v\rvert\,dv $$ Note that the function has period $\pi$, so let $u=k\pi+u_0$, with $0\le u_0<\pi$. Then $$ \int_0^u\lvert\sin v\rvert\,dv= \int_0^{k\pi}\lvert\sin v\rvert\,dv+ \int_{k\pi}^{k\pi+u_0}\lvert\sin v\rvert\,dv \\=2k+\int_0^{u_0}\sin v\,dv= 2k+1-\cos(u-k\pi) $$ Now do the back substitution; write $k=u\bmod\pi$, if you prefer.