
\documentclass[12pt]{article}
\usepackage{ifthen}

% TO LEAVE SPACE FOR CROWDMARK'S QR CODE AT THE TOP:
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{8.8in}
\setlength{\oddsidemargin}{0in}
\setlength{\topmargin}{0in}

\begin{document}

% COMMANDS FOR HEADERS AND EMPHASIS:
\def\cb#1{\centerline{\bf #1}}
\def\cbf#1{\centerline{\bf #1}}
\def\cbfu#1{\centerline{\underbar{\bf #1}}}
\def\un{\underbar}
\pagestyle{empty}  % Since Crowdmark adds page numbers anyway.

% COMMANDS TO AUTOMATICALLY DISPLAY QUESTIONS AND TOTAL POINTS:
\newcounter{quesnum}
\setcounter{quesnum}{0}
\newcounter{piecenum}
\setcounter{piecenum}{0}
\newcounter{totpoints}
\newcommand{\ques}[2][0]{%
  \setcounter{piecenum}{0}%
  \refstepcounter{quesnum}%
  \par
  \bigskip
  \bf \noindent \thequesnum.%
  \showpoints{#1}
  \rm #2
}
\newcommand{\piece}[2][0]{
  \refstepcounter{piecenum}
  \par\medbreak
  \bf \noindent (\alph{piecenum})
  \showpoints{#1}
  \rm #2
}
\def\showpoints#1{
  \ifnum#1>0
    [#1]
    \addtocounter{totpoints}{#1}%
  \fi
}
\def\sp{\par\vfil}
\def\nextpage{\eject}

% COMMANDS TO WRITE THE TOTAL POINTS FROM THE PREVIOUS COMPILE:
\makeatletter
\def\writeval#1#2{
  \protected@write\@auxout{}%
         {\string\newlabel{#1}{{#2}{\thepage}}}%
  }
\makeatother
\def\examinfo{%
  \ref{prevnumques}~questions; \pageref{endpage}~pages;
        total points = \ref{prevtotpoints}%
}

% ***** THE COVER PAGE: *****

\cb{\Large STA257 Midterm~\#1 (PRETEND), Oct.~12, 2022}

\bigskip
\cb{(100~minutes; \examinfo)}

\bigskip\noindent
$\bullet$\ {\bf Do \un{not} open this test until told to do so.
					Answer \un{all} questions.}
Aids allowed: a single non-programmable \un{calculator}, only.
Please write your answers \un{in the space provided}, only.
You should {\bf \un{explain}} all of your solutions clearly.
You \un{may} use results from class, with explanation.
\un{Point values} for each question are indicated
				in [square brackets].

% LEAVE SPACE FOR CROWDMARK NAME/ID MATCHING BOX:
\vskip 10cm

\cbfu{Academic Integrity Acknowledgement Form}

\medskip\noindent
The University of Toronto's Code of Behaviour on Academic Matters outlines
the behaviours that constitute academic \un{misconduct}, the processes for
addressing academic offences, and the \un{penalties} that may be imposed.
Potential \un{offences} include (but are not limited to):
\par$\bullet$ Looking at someone else's answers during the exam.
\par$\bullet$ Letting someone else look at your answers during the exam.
\par$\bullet$ Misrepresenting your identity or having someone else
				complete your exam.
\par$\bullet$ Sharing or posting the exam questions during
			\un{or for 24 hours after} the exam.

\medskip\noindent
Prior to beginning this exam, you must \un{affirm} that you will follow the
Code of Behaviour on Academic Matters in the completion of this exam,
by \un{completing the following statement}:

\bigskip\medskip\noindent
I, \underbar{\hskip 8cm} (print your full name), agree to fully abide by
the Code of Behaviour on Academic Matters. I promise not to commit academic
misconduct, and am aware that significant penalties may be imposed
if I do.

\bigskip\medskip
Signature:
\quad \underbar{\hskip8cm}

\vfil\eject

% ***** THE ACTUAL EXAM: *****

\ques[10]{What is the probability that you will enjoy this course?}
\sp

\ques[10]{What is the probability that you will pass this test?}
\sp
\nextpage

\ques{Comment on how much you adore each of the following:}
\piece[5]{The professor.}
\sp
\piece[5]{The classroom.}
\sp
\piece[5]{The other students.}
\sp


% ***** END OF THE EXAM: *****

\bigskip
\noindent\bf [END OF EXAMINATION; total points = \thetotpoints]
\writeval{prevtotpoints}{\thetotpoints}
\writeval{prevnumques}{\thequesnum}
\label{endpage}
\eject

% **** COMMANDS TO ADD AN EXTRA CROWDMARK PAGE FOR OVERFLOW ANSWERS ****
% Define \newtextline to get the spacing right for double-sided printing:
\def\newtextline#1{\par\noindent\ifodd\value{page}\relax\else{\hskip9cm}\fi
					{\bf #1}}
\long\def\extracrowdmarkpage{
  \newpage
  $\big.$
  \vskip -3cm
\newtextline{OPTIONAL EXTRA PAGE.}
\newtextline{If necessary, continue answer(s) here.}
\newtextline{If you do, write ``SEE LAST PAGE''}
\newtextline{\qquad on the question page itself.}
}

% ADD ACTUAL EXTRA CROWDMARK PAGES:
\extracrowdmarkpage
%(Can be repeated as many times as desired, or not at all.)

\end{document}

