➕Create your first C++ assignment
Last updated
Last updated
In this tutorial, we will guide you through all the steps to create your very first C++ assignment in CodeGrade. For this tutorial, we will be considering the example below. The zip folder contains a completed solution and a template file. Please make sure to save this file somewhere accessible on your computer:
A quick note about this example In this assignment, students have been asked to create a C++ program that prints the first 'n' numbers of the Fibonacci sequence starting from 1, where 'n' is determined by user input.
First, we need an assignment to work with. Whether CodeGrade is integrated with your LMS or you are using CodeGrade Standalone, you can follow the steps in the guide below to get started:
➕Create assignmentThe first step in setting up an assignment is to ensure that students can submit their code correctly. Because this example is straightforward and only requires a single solution file, we will offer the students the option to code in the CodeGrade Editor alongside the default File Uploader option.
Navigate to the Assignment Management page by using the ⚙️ icon at the right-hand side of the page header on the submissions page.
Find the Submission settings in the corresponding container under the General tab.
Enable the File uploader and Editor submission methods by clicking the respective check boxes.
Enabling the Editor will reveal the Template files option. Unzip the Calculator.zip folder and upload Fibonacci/Template/Fibonacci.cpp
as the template.
Finalize your settings by clicking the "Submit" button.
It is good practice to provide a template file when enabling the Editor so that your students don't have to create their own file. This also avoids the risk of students submitting a file with the wrong name.
For more information about submission methods, see submission settings.
While you can always grade assignments directly by manually setting the Final grade, It's only possible to award points for your automatic tests with Rubrics. Rubrics also allow you to standardize the grading scheme for graders and to clarify the grading requirements to your students.
CodeGrade offers two types of rubric categories:
Discrete category - Specify points in discrete steps (eg. 0, 5, or 10 points)
Continuous category - Specify points as a continuous scale (eg. 0 - 10)
Navigate to the Rubric tab on the Assignment Management page.
Select Create New Rubric.
Create 3 new Continuous Categories. Set the parameters as follows:
Compile test
Check that your code compiles without errors.
0 - 20
Input/Output tests
Check that your program produces the correct output depending on the provided input.
0 - 40
Code structure tests
Check that you have used the expected code structures
0 - 40
Automatic tests are really what gives your students the opportunity to learn in a unique way. The immediate feedback they get from the automatic tests allows them to learn through trial and error by applying the instant feedback and resubmitting their work.
For this tutorial, we will be setting up two types of automatic tests: IO tests and Semgrep code structure tests.
Before actually creating the tests, we need to make sure we have the correct version of our compiler, GCC, installed.
Navigate to the Setup tab under the AutoTest settings.
Add an Install GCC block to your configuration.
Select the latest version of GCC using the drop-down menu.
As with any compiled language like C++, each student's program must be compiled before we can run any other tests on it. We will also grade this test using the "Compile test" rubric category :
Navigate to the Tests tab under the AutoTest settings.
Add a Connect rubric block to your AutoTest configuration and select the "Compile test" rubric category from the drop-down menu.
Add a Script block to your AutoTest configuration and nest it within the Connect rubric block.
In the editor provided, add the following bash commands:
Input/Output tests (or "IO tests" for short) are a great way of checking a program's functionality by providing various input cases that should result in a different outputs. You can create IO test cases in AutoTest v2 using the IO Test wrapper block and its corresponding Full match, Substring match, and Regex match blocks. For more information about these blocks, see Create an IO Test.
Navigate to the Tests tab of the AutoTest settings.
Add a Connect rubric block to your AutoTest configuration. Select the "IO tests" rubric category from the drop-down menu.
Add an IO test block to your AutoTest configuration and nest it inside the Connect Rubric block.
In the editor provided use the command ./Fibonacci
to run the program.
Add five Substring match blocks to your AutoTest configuration and nest them inside the IO test block. Make sure each match block is case insensitive and ignores whitespace.
Copy and paste the info from the table below into the Input and Expected output fields in their respective match block:
1
1
3
1 1 2
5
1 1 2 3 5
0
invalid
-1
invalid
Semgrep is a code structure testing framework that is excellent for checking if students have used a specific syntax to reach their solution. AutoTest v2 offers the Code structure test block and its corresponding Positive match and Negative match blocks for running semgrep tests. For more information about these test blocks, see Create a Code Structure Test. For more details on setting up Code Structure Tests, read our dedicated guide.
For this example, we want to check that the students have the add function in their program. Here are the Semgrep rules we will be using:
Add a Connect rubric block to your test configuration and select the "Code structure tests" rubric category.
Add a Code structure test block to your test configuration and nest it within the Connect rubric block.
In the Student file input field, write "Fibonacci.cpp".
Add two Positive match blocks to your test configuration and nest them within the Code structure test block
Copy and paste the semgrep rules in the code blocks above into the provided editor in each Positive match block. Make sure to delete the template provided.
The most recent version of Semgrep may not be available in AutoTest v2. For this reason, rules that work in the Semgrep playground may not always work in the Code Structure test block.
It's important to test your AutoTest configuration before running it on students' submissions to make sure that your tests are running as expected and to check for edge cases. This is easy to do with Snapshots. When you're ready to check your tests, simply press the Build snapshot button at the bottom of the test block sidebar. This will make a test run of your AutoTest configuration on your Test submission.
The first time you build a snapshot, CodeGrade will prompt you to upload a Test submission. Use the "Click here to upload files" option or drag-and-drop the Fibonacci/Solution/Fibonacci.cpp
file that you downloaded at the beginning of this tutorial and click "Submit".
If in the future you need to re-upload your test submission, you can do so by going to Upload Submission option in the General Settings tab. Just upload your file and check the "Test Submission" option before clicking "Submit".
Once you're happy with your tests, you need to publish them to your students for them to run on their submissions. Publish your tests by building a snapshot and at the bottom of the pop-up modal click the Publish to students button. Once it is published, AutoTest V2 is available for students through the editor and on the submission page.
You have just built your first automatically graded assignment, ready for your students to begin submitting work!
This guide is designed to get you started with a completed assignment but doesn't go into explicit detail about all of the features CodeGrade has to offer. For more in-depth information about the product and the various workflows that you can achieve, see Learn more or reach out to our support team at support@codegrade.com.