计算分数考试类

计算分数考试类

我想通过将百分比乘以总分数(例如 0.5 * \numpoints{})来计算考试的评分分数,以制作评分表。问题是,在运行编译之前,我无法将 \numpoints 作为数字访问,并且会出现错误。我一直试图使用某种 if 语句来解决这个问题,但没有任何用处。下面是一个可行的示例,我当前的解决方案是注释这些行,编译文件,然后取消注释并再次编译。有没有一种简单的方法可以使用 if 语句来解决这个问题?

\documentclass[addpoints, 12pt]{exam}
\printanswers
\usepackage[utf8]{inputenc}
\usepackage{fp}

\begin{document}
\Large{Exam}\\

% Marking points COMMENT line 1-3 below to run first time
\FPeval{\gradethree}{clip(\numpoints{} * 0.5)}
\FPeval{\gradefour}{clip(\numpoints{} * 0.67)}
\FPeval{\gradefive}{clip(\numpoints{} * 0.83)}

% Marking table COMMENT lines 2-4 below to run first time
\noindent{}Total points: \numpoints{} \\
Grade 3:  \gradethree \space points \\
Grade 4:  \gradefour  \space points \\
Grade 5:  \gradefive  \space points \\

\begin{questions}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\end{questions}


\end{document}

我的评论解决方法之后的输出如下所示(这正是我想要实现的): 考试及评分表和答案

答案1

ifthenx提供此功能的包\ispositiveinteger可以达到这个目的:

\documentclass[addpoints, 12pt]{exam}
\printanswers
\usepackage[utf8]{inputenc}
\usepackage{fp}
\usepackage{ifthenx}

\begin{document}
\noindent\Large{Exam}\\

% calculates marking points for exam grades
\ifthenelse{\ispositiveinteger{\numpoints}}
    {   \FPeval{\gradethree}{clip(\numpoints{} * 0.5)}
        \FPeval{\gradefour}{clip(\numpoints{} * 0.67)}
        \FPeval{\gradefive}{clip(\numpoints{} * 0.83)}  }

% grading table:
\noindent{}Total points: \numpoints{} \\
\ifthenelse{\ispositiveinteger{\numpoints}}
    {   Grade 3:  \gradethree \space points \\
        Grade 4:  \gradefour  \space points \\
        Grade 5:  \gradefive  \space points \\  }
    % Printed if \numpoints is not available.
    {Sorry no grading table \textbf{yet}.}
    
\normalsize
\begin{questions}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\end{questions}


\end{document}

当存在时,当然会给出与上面相同的输出numpoints,否则会打印标记表不可用。

相关内容