Print this chapterPrint this chapter

CodeRunner Documentation (V3.2.1)

4.1 An example question type

The C-function question type expects students to submit a C function, plus possible additional support functions, to some specification. As a trivial example, the question might ask "Write a C function with signature int sqr(int n) that returns the square of its parameter n". The author will then provide some test cases of the form

printf("%d\n", sqr(-11));

and give the expected output from this test.

A per-test template for such a question type would then wrap the submission and the test code into a single program like:

#include <stdio.h>

// --- Student's answer is inserted here ----

int main()
{
    printf("%d\n", sqr(-11));
    return 0;
}

which would be compiled and run for each test case. The output from the run would then be compared with the specified expected output (121) and the test case would be marked right or wrong accordingly.

That example assumes the use of a per-test template rather than the more complicated combinator template that is actually used by the built-in C function question type. See the section on templates for more.