%%% grade distribution macros for course reports  1997 Jan 16, 2002 Dec 09 WH
\message{ Loading macros for computing percentages and GPA - 1997 Jan 16, 2002 Dec 09  WH }
\newcount\numAp
\newcount\numA
\newcount\numAm
\newcount\numBp
\newcount\numB
\newcount\numBm
\newcount\numCp
\newcount\numC
\newcount\numCm
\newcount\numDp
\newcount\numD
%\newcount\numDm
\newcount\numF
\newcount\numFs
\newcount\numW
\newcount\numI
\newcount\tmp
\newcount\tmpround
\newcount\tmppercent
\newcount\tmpintenths
\newcount\total
\newcount\gpa
\newcount\tmpa
\newcount\tmpb

\def\gpaadd#1#2{\tmp=#1\multiply\tmp by #2 \global\advance\gpa by\tmp}

\def\gradesum{
\gpa=0
\total=0
\global\advance\total by\numAp
\gpaadd\numAp{40}
\global\advance\total by\numA
\gpaadd\numA{40}
\global\advance\total by\numAm
\gpaadd\numAm{37}
\global\advance\total by\numBp
\gpaadd\numBp{33}
\global\advance\total by\numB
\gpaadd\numB{30}
\global\advance\total by\numBm
\gpaadd\numBm{27}
\global\advance\total by\numCp
\gpaadd\numCp{23}
\global\advance\total by\numC
\gpaadd\numC{20}
\global\advance\total by\numCm
\gpaadd\numCm{17}
\global\advance\total by\numDp
\gpaadd\numDp{13}
\global\advance\total by\numD
\gpaadd\numD{10}
%\global\advance\total by\numDm
%\gpaadd\numDm{7}
\global\advance\total by\numF
\global\advance\total by\numFs
\newcount\totalnoWI\totalnoWI=\total
\global\advance\total by\numI
\newcount\totalnoW\totalnoW=\total
\global\advance\total by\numW
}

%%  ((#1 * 1000) + (#2/2)) / #2  gives  P = #1/#2  in tenth's of a % rounded. 

\def\printpercent#1#2{\tmp=#1\multiply\tmp by1000
\tmpround=#2\divide\tmpround by2
\advance\tmp by \tmpround
\divide\tmp by #2
% \tmp = P say as 123 representing 12.3%
% Then \tmppercent = 12, \tmpintenths = 120, \tmp = 3
\tmppercent=\tmp\divide\tmppercent by 10
\tmpintenths=\tmppercent\multiply\tmpintenths by -10
\advance\tmp by\tmpintenths
\the\tmppercent.\the\tmp
}
%
\def\digitof#1{\tmpa=#1\divide\tmpa by 100
\the\tmpa
\tmpb=\tmpa\multiply\tmpb by -100\global\advance#1 by\tmpb
\global\multiply#1 by 10
}
%
\def\gpaprint#1#2{\tmp=#1\multiply\tmp by10
\tmpround=#2\divide\tmpround by2
\advance\tmp by \tmpround
\divide\tmp by #2
% \tmp = P say as 321 which must be printed out as 3.21  
% Then \tmpa = 3, \tmpb = 120, \tmp = 3
\digitof\tmp.\digitof\tmp\digitof\tmp
}

