title: An automatic grader in c++
body: <p>I am trying to write an automatic grading program for a C++ course I am teaching. Usually, automatic graders use (input,output) pairs: the submitted program reads from standard input and writes to standart output, and the grader compares it with the expected output. But I want my students to practice specific C++ constructs (and not e.g. write a program in C), so the tests are written in C++. In a simple example, I give them a main program such as:</p>
  <pre><code>#include &quot;func.hpp&quot;
  ...
  
  int main() {
      test(func(1)==2);
      test(func(2)==33);
      ...  
      /* some 100 tests, including some randomized tests */
      ...
      cout &lt;&lt; &quot;Grade: &quot; &lt;&lt; grade &lt;&lt; endl;
  }
  </code></pre>
  <p>The students have to submit the files <code>func.hpp</code> and <code>func.cpp</code> (for more complex assignments, some more files are required).</p>
  <p>There  is a <code>bash</code> script that compiles <code>main.cpp</code> with <code>func.cpp</code>, runs the program and reads the grade from the last line (It is run within a <code>docker</code> container, to prevent inadvertent damage to the host computer).</p>
  <p>The problem is that a student can, from within <code>func</code>, print &quot;Grade: 100&quot; and exit.</p>
  <p>Is there a simple way to make the grader more reliable?</p>