Assuming $u(t,x)=T(t)X(x)$, the separated equations are
$$
\frac{T''}{c^2 T} = \lambda, \;\; \lambda = \frac{X''}{X}, \; X'(0)=X'(\pi)=0.
$$
The $X$ solutions dictate the values of $\lambda$ to be $-n^2$ for $n=1,2,3,\cdots$, and the corresponding eigenfunctions are unique up to multiplicative constants, and are given by
$$
X_n(x) = \cos(n x),\;\;\; n=0,1,2,3,\cdots.
$$
The general solution is
$$
u(x,t) = (A_0+B_0t)+\sum_{n=1}^{\infty}\left(A_n\cos(nc t)+B_n\sin(nc t)\right)\cos(n x).
$$
The constants $A_n,B_n$ are determined by the initial conditions:
$$
\cos(x) = u(x,0) = A_0+\sum_{n=1}^{\infty}A_n\cos(n x), \\
\cos^2(x) = u_{t}(x,0) = B_0+\sum_{n=1}^{\infty}nc B_n\cos(n x).
$$
The mutual orthogonality of the functions $\{ \cos(n\pi x) \}_{n=0}^{\infty}$ in $L^2[0,\pi]$ is used to determine the coefficients $A_n$ and $B_n$ in the usual manner of Fourier, which is simplified after applying the identity
$$
\cos^2(x) = \frac{1+\cos(2x)}{2}.
$$
It seems I was confused or made mistakes the first time trying to solve this, so I will post my solution now that it makes sense.
Assume $u(x,t)=F(x+2t)+G(x-2t)$. Then, the initial conditions give us:
$$
u(x,0)=F(x)+G(x)=e^{-x}\\
u_t(x,0)=2F'(x)-2G'(x)=2e^{-x}
$$
which hold for all $x>0$.
Hence, in the last equation, we may divide both sides by 2 and integrate with respect to x, then solve the resulting system:
$$
\begin{cases}
F(x)+G(x)=e^{-x}\\
F(x)-G(x)=-e^{-x}+C
\end{cases}
$$
where $C$ is some constant.
We thus obtain $F(x)=C/2$ and $G(x)=e^{-x}-C/2$. Since the only condition is that $x$ is positive, we may replace it by any positive quantity (I think this is where I was previously confused). Thus, we obtain $u(x,t)=F(x+2t)+G(x-2t)=C/2+e^{-(x-2t)}-C/2=e^{2t-x}$ which holds for all $x>2t$. It is clear, as I noted in my original post, that this corresponds to the same solution that we get from d'Alembert's formula.
Now we handle the case when the argument to $G$ is negative. For this, we need to use the boundary condition.
We have $u_x(0,t)=F'(2t)+G'(-2t)=-\cos t$ for all $t>0$. Make the substitution $z=-2t$ to obtain $G'(z)=-\cos(z/2)-F'(-z)=-\cos(z/2)$ by noting that $F'(-z)=0$ from our previous work. Integrating, we obtain $G(z)=-2\sin(z/2)+\tilde{C}$.
Applying the continuity condition, we must have $G(0)=\tilde{C}=1-C/2$. Thus, we have $u(x,t)=F(x+2t)+G(x-2t)=1-2\sin(x/2-t)$ for $0<x<2t$.
Hence, the complete solution is:
$$u(x,t)=\begin{cases}1-2\sin(x/2-t),&0<x\leq 2t\\e^{2t-x},&x>2t\end{cases}.$$
We can now verify that the initial conditions, boundary condition, and continuity are satisfied.
Best Answer
I admitted for the current stiff PDE education system, it is hard to find the examples of solving PDEs with sightly innovative types of conditions.
So it is the time to use the brains ourselves.
For your first example, it gives the message that the roles of $x$ and $t$ can be interchanged.
Please use the general solution of the form $u(x,t)=f\left(t+\dfrac{x}{2}\right)+g\left(t-\dfrac{x}{2}\right)+4t^2-x^2$ instead for convenience.
$u(0,t)=t$ :
$f(t)+g(t)+4t^2=t$
$f(t)+g(t)=t-4t^2~......(1)$
$u_x(x,t)=f_x\left(t+\dfrac{x}{2}\right)+g_x\left(t-\dfrac{x}{2}\right)-2x=\dfrac{1}{2}f_t\left(t+\dfrac{x}{2}\right)-\dfrac{1}{2}g_t\left(t-\dfrac{x}{2}\right)-2x$
$u_x(0,t)=0$ :
$\dfrac{1}{2}f_t(t)-\dfrac{1}{2}g_t(t)=0$
$f_t(t)-g_t(t)=0$
$f(t)-g(t)=c~......(2)$
$\therefore f(t)=\dfrac{t}{2}-2t^2+\dfrac{c}{2},g(t)=\dfrac{t}{2}-2t^2-\dfrac{c}{2}$
$\therefore u(x,t)=\dfrac{t}{2}+\dfrac{x}{4}-2\left(t+\dfrac{x}{2}\right)^2+\dfrac{c}{2}+\dfrac{t}{2}-\dfrac{x}{4}-2\left(t-\dfrac{x}{2}\right)^2-\dfrac{c}{2}+4t^2-x^2=t-2x^2$
For your second example,
Please use the general solution of the form $u(x,t)=f(2t+x)+g(2t-x)+\dfrac{t^2}{2}-\dfrac{x^2}{8}$ instead for convenience.
$u(x,x)=x^2$ :
$f(3x)+g(x)+\dfrac{x^2}{2}-\dfrac{x^2}{8}=x^2$
$f(3x)+g(x)=\dfrac{5x^2}{8}~......(1)$
$u_t(x,t)=f_t(2t+x)+g_t(2t-x)+t=2f_x(2t+x)+2g_x(2t-x)+t$
$u_t(x,x)=x$ :
$2f_x(3x)+2g_x(x)+x=x$
$3f_x(3x)+3g_x(x)=0$
$f(3x)+3g(x)=c~......(2)$
$\therefore f(x)=\dfrac{5x^2}{48}-\dfrac{c}{2},g(x)=\dfrac{c}{2}-\dfrac{5x^2}{16}$
$\therefore u(x,t)=\dfrac{5(2t+x)^2}{48}-\dfrac{c}{2}+\dfrac{c}{2}-\dfrac{5(2t-x)^2}{16}+\dfrac{t^2}{2}-\dfrac{x^2}{8}=-\dfrac{x^2-5xt+t^2}{3}$
Your two examples are having the conditions in same positions. Note that for the cases of having the conditions in different positions, their PDEs may still have infinitely many solutions.
For example $u_{tt}=u_{xx}$ with $u(x,0)=0$ and $u(0,t)=0$ ,
The general solution is $u(x,t)=f(x+t)+g(x-t)$
$u(x,0)=0$ :
$f(x)+g(x)=0~......(1)$
$u(0,t)=0$ :
$f(t)+g(-t)=0~......(2)$
$\therefore f(t)-f(-t)=0$
$f(t)=\Phi(t)$ , where $\Phi(t)$ is any even function of $t$
$\therefore g(x)=-\Phi(x)$ , where $\Phi(x)$ is any even function of $x$
$\therefore u(x,t)=\Phi(x+t)-\Phi(x-t)$ , where $\Phi(x)$ is any even function of $x$
Another good example is Does the wave equation require an initial function for one of its derivative?.