CodeRunner Documentation (V3.1.0)

5.3 Customising templates

As mentioned above, if a question author clicks in the customise checkbox, the question template is made visible and can be edited by the question author to modify the behaviour for that question.

As a simple example, consider the following question:

"What is the missing line in the sqr function shown below, which returns the square of its parameter n?"

int sqr(int n) {
    // What code replaces this line?
}

Suppose further that you wished the test column of the result table to display just, say, sqr(-11) rather than printf("%d, sqr(-11));

You could set such a question using a template like:

    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>

    int sqr(int n) {
       {{ STUDENT_ANSWER }}
    }

    int main() {
        printf("%d\n", {{ TEST.testcode }});
        return 0;
    }

The authoring interface allows the author to set the size of the student's answer box, and in a case like the above you'd typically set it to just one or two lines in height and perhaps 30 columns in width.

The above example was chosen to illustrate how template editing works, but it's not a very compelling practical example. It would generally be easier for the author and less confusing for the student if the question were posed as a standard built-in write-a-function question, but using the Preload capability in the question authoring form to pre-load the student answer box with something like

// A function to return the square of its parameter n
int sqr(int n) {
    // *** Replace this line with your code

If you're customising templates, or developing your own question type (see later), the combinator template doesn't normally offer sufficient additional benefit to warrant the complexity increase unless you have a large number of testcases or are using a slow-to-launch language like Matlab. It is recommended that you always start with a per-test template, and move to a combinator template only if you have an obvious performance issue.