I created the following class, which allows you to toggle showing the solutions:
% Assignment class for homework and exams.
%
% Gabriel Antonius
%
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myassignment}[2019/02/18 Assigment]
\LoadClass{article}
\RequirePackage{placeins}
\RequirePackage{environ}
\RequirePackage{xifthen}
% \solutiontrue and \solutionfalse control whether solutions are shown
\newif\ifsolution
\solutiontrue
%\solutionfalse
% Redefine these if you want to change the language
\newcommand{\problemlabel}{Problem}
\newcommand{\solutionlabel}{Solution}
% Set up counters for problems and subproblems
\newcounter{ProblemNum}
\newcounter{SubProblemNum}[ProblemNum]
\renewcommand{\theProblemNum}{\arabic{ProblemNum}}
\renewcommand{\theSubProblemNum}{\alph{SubProblemNum}}
% The problem environment is the base unit of content for this class.
\newcommand{\subsectiontitle}{}
\newenvironment{problem}[1]%
{
\stepcounter{ProblemNum}
\renewcommand{\subsectiontitle}{\problemlabel \ \theProblemNum \ifthenelse{\isempty{#1}}{}{\ : #1}}
\medskip \subsection*{\subsectiontitle}
\FloatBarrier
}
{
\FloatBarrier
}
% The subproblem command divides a problem into parts a), b), c), ...
\newcommand*{\subproblem}{%
\stepcounter{SubProblemNum}%
{\bf \theSubProblemNum)\hspace{2pt}}
}
% The solution environment should be used within the problem environment
\NewEnviron{solution}{
\setcounter{SubProblemNum}{0}
\ifsolution
\FloatBarrier
\subsubsection*{\solutionlabel}
\BODY
\fi}
Here is an example usage:
\documentclass[12pt]{myassignment}
\usepackage{amsmath}
\setlength{\parindent}{0pt}
\solutiontrue % <---- Toggle showing solutions or not
%\solutionfalse
\begin{document}
\begin{problem}{Hyperbolic functions}
Let $\cosh(x) = \cos(ix)$ and $\sinh(x) = -i\sin(ix)$.
\subproblem Show that $\cosh^2(x) - \sinh^2(x) = 1$
\subproblem Show that $e^{-x} = \cosh(x) - \sinh(x)$
\begin{solution}
\subproblem
Starting from
\begin{equation}
1 = \cos^2(x) + \sin^2(x) = \cos^2(x) - \Big( -i\sin(x) \Big)^2
\end{equation}
and using $x=iy$, we get
\begin{equation}
1 = \cosh^2(y) - \sinh^2(y)
\end{equation}
\subproblem
Starting from
\begin{equation}
e^{ix} = \cos(x) + i \sin(x)
\end{equation}
and using $x=iy$, we get
\begin{equation}
e^{-y} = \cosh(y) - \sinh(y)
\end{equation}
\end{solution}
\end{problem}
\end{document}
exam
class. You can also find examples in this site:{exam}