problem with "cpp_program"

problem with "cpp_program"

by Gulsum Yigit -
Number of replies: 3

Hello,

I am having trouble while creating a full C++ program question. It is unclear how to use the test cases and how to validate the entire program. For example, a simple:

Question type: cpp_program

#include <iostream>

int main()
{
   std::cout << "hi";
}

would fail when running tests. I am not sure if this is a compiling error or CodeRunner simply does not understand what I am trying to do.

Ultimately, I would like to have a program that reads a file, process its data, and then writes the results on a second file; so, ideally the test should run on the content of the file. However, even a simple console output does not seem to work.

Any suggestions?

In reply to Gulsum Yigit

Re: problem with "cpp_program"

by Richard Lobb -

You don't say what's going wrong, so I'm not sure where the problem lies. But I attach a couple of xml question exports that you should be able to import and run. The first one just outputs 'hi', the second reads a single supplied file 'blah.txt' and writes to stdout all the lines backwards. If those don't work, please provide a detailed description of what goes wrong, plus a screenshot.

Note that your intention to have students read a file and write a new one is a bit problematic: such a program wouldn't generate any output so is hard to test. It's possible to write your own question type that first compiles and runs the student answer then compiles and runs your test code but it's a huge step up in complexity and certainly not recommended until you're familiar with the standard question types.

The usual way to set and test write-a-program questions is as in program contests: get students to read from standard input and write the processed output to standard output. You specify both the input and expected output in each test case, so can test with multiple datasets.

In reply to Richard Lobb

Re: problem with "cpp_program"

by Gulsum Yigit -

Thanks for your reply and for attaching sample question exports.

I've imported the xml question exports, but when I try to run it and click the check button, I get the following error.


In reply to Gulsum Yigit

Re: problem with "cpp_program"

by Richard Lobb -
To run your code safely, the CodeRunner plugins submits the task to a sandbox server called Jobe using an HTTP request. That message tells you that the request failed.

There are quite a lot of possibilities but if this is a newly installed CodeRunner using the default Jobe server, jobe2.cosc.canterbury.ac.nz, the most likely explanation is that the Moodle server is preventing HTTP requests to that server. A firewall configuration, perhaps? You probably need to talk to a sysadmin, who should be asked to check the installation procedure for coderunner (https://github.com/trampgeek/moodle-qtype_coderunner#installation).

Please note that this default server is only for initial testing. The CodeRunner installation documentation explains how to set up your own Jobe server for production use. Further documentation is at https://github.com/trampgeek/jobe#jobe