(a) Here is my typed solution:
We have the Dirichlet problem \begin{equation}
\begin{cases}
u_t = ku_{xx} & x>0, t>0 \\
u|_{t=0} = g(x) \\
u|_{x=0} = 0
\end{cases}
\label{eq:problem}
\end{equation}
By method of continuation, we extend the initial function to the full line (recalling the odd extension for Dirichlet problems): \begin{equation}
g_{extended}(x) = \begin{cases} g(x) & x>0 \\
-g(-x) & x<0 \\
0 & x=0
\label{eq:gext}
\end{cases}
\end{equation}
So for the entire line (i.e. $-\infty<x<\infty$), we arrive at a solution with the formula as given in the textbook; call it w. The solution to the given problem \ref{eq:problem} will just be this solution in the region of x>0. \begin{equation}
w(x,t) = \int_{-\infty}^{\infty} G(x,y,t)g_{extended}(y)dy
\end{equation}
So using the definition of $g_{extended}$ as given in \ref{eq:gext}, we can rewrite this as: \begin{equation}
w(x,t) = \int_{0}^{\infty} G(x,y,t)g(y)dy - \int_{-\infty}^{0} G(x,y,t)g(-y)dy
\end{equation}
In the second equation above, let's make a change of variables from -y to y. Then this yields: \begin{equation}
w(x,t) = \int_0^{\infty}[G(x,y,t) - G(x, -y, t)]g(y)dy \end{equation}
This is our solution. Written in terms of the definition of G, we arrive at the final solution to \ref{eq:problem}: \begin{equation}
u(x,t) = \frac{1}{2\sqrt{\pi{}kt}}\int_0^{\infty}[e^{-(x-y)^2/(4kt)} - e^{-(x+y)^2/(4kt)}]g(y)dy \end{equation}
(b) Part (b) is very similar, only here we have a Neumann problem: \begin{equation}
\begin{cases}
u_t = ku_{xx} & x>0, t>0 \\
u|{t=0} = g(x) \\
u_x|{x=0} = 0
\end{cases}
\label{eq:neumann}
\end{equation}
Recall that for Neumann problems, the continuation is even. So we write the extension of the initial function to the entire line: \begin{equation}
g_{extended}(x) = \begin{cases} g(x) & x \geq 0 \\
g(-x) & x \leq 0 \end{cases}
\label{eq:geven}
\end{equation}
Proceeding similarly as in part (a), the solution for the whole line will be: \begin{equation}
w(x,t) = \int_{-\infty}^{\infty} G(x,y,t)g_{extended}(y)dy
\end{equation}
The solution to \ref{eq:neumann} will just be this solution in the region x>0.
So let's write this in terms of the definition in \ref{eq:geven}: \begin{equation}
w(x,t) = \int_{0}^{\infty} G(x,y,t)g(y)dy + \int_{-\infty}^{0} G(x,y,t)g(-y)dy
\end{equation}
Let's again make the change of variables, from -y to y. We arrive at: \begin{equation}
w(x,t) = \int_{0}^{\infty} [G(x,y,t) + G(x,-y,t)]g(y)dy
\end{equation}
Using the definition of G as before, we arrive at the final solution to \ref{eq:neumann}: \begin{equation}
u(x,t) = \frac{1}{2\sqrt{\pi{}kt}}\int_0^{\infty}[e^{-(x-y)^2/(4kt)} + e^{-(x+y)^2/(4kt)}]g(y)dy \end{equation}