Skip to content

Commit

Permalink
Added defaul file read code for all languages
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanAziz authored and RehanAziz committed Apr 13, 2022
1 parent 4f056dd commit 081da41
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions openassessment/xblock/static/js/src/lms/oa_response.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,62 @@ OpenAssessment.ResponseView.prototype = {
this.updateEditorMode(language);
this.handleResponseChanged();
let defaulCodes = {
"Python":"Default code of Python",
"NodeJS":"Default code of NodeJs",
"Java":"Default code of Java",
"C++":"Default code of C++"
"Python":"import sys\n" +
"\n" +
"lines = open(sys.argv[1], 'r').readlines()\n" +
"\n" +
"# Write your code here.",
"NodeJS":"const fs = require('fs');\n" +
"\n" +
"const args = process.argv.slice(2);\n" +
"const fileName = args[0];\n" +
"\n" +
"const content = fs.readFileSync(fileName).toString();\n" +
"const lines = content.split('\\n');\n" +
"\n" +
"// Write your code here.",
"Java":"import java.io.File;\n" +
"import java.io.FileNotFoundException;\n" +
"import java.util.Scanner;\n" +
"\n" +
"\n" +
"public class Main {\n" +
" public static void main(String[] args) {\n" +
" try {\n" +
" File inputFile = new File(args[0]);\n" +
" Scanner inputReader = new Scanner(inputFile);\n" +
" while (inputReader.hasNextLine()) {\n" +
" String line = inputReader.nextLine();\n" +
"\n" +
" // Write your code here.\n" +
"\n" +
" }\n" +
" inputReader.close();\n" +
" } catch (FileNotFoundException e) {\n" +
" System.out.println(\"An error occurred.\");\n" +
" e.printStackTrace();\n" +
" }\n" +
" }\n" +
"}",
"C++":"#include <iostream>\n" +
"#include <fstream>\n" +
"\n" +
"using namespace std;\n" +
"\n" +
"\n" +
"int main(int argc, char *argv[]) {\n" +
" ifstream inputFile(argv[1]);\n" +
"\n" +
" string line = \"\";\n" +
" do {\n" +
" getline(inputFile, line);\n" +
"\n" +
" // Write your code here.\n" +
"\n" +
" } while(inputFile.good());\n" +
"\n" +
" return 0;\n" +
"}"
}

if(this.showFileUplaodCode === 'True' && (this.codeEditor.getValue() === '' || Object.values(defaulCodes).includes(this.codeEditor.getValue()))){
Expand Down

0 comments on commit 081da41

Please sign in to comment.