-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQuestion_ShortAnswer.cpp
More file actions
86 lines (71 loc) · 2.63 KB
/
Question_ShortAnswer.cpp
File metadata and controls
86 lines (71 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Question_ShortAnswer.hpp"
using emp::MakeCount;
void Question_ShortAnswer::Print(std::ostream& os) const {
os << "%- QUESTION " << id << "\n" << question << "\n";
for (const String & option : answers) {
os << option << '\n';
}
os << std::endl;
}
void Question_ShortAnswer::PrintD2L(std::ostream& os) const {
os << "NewQuestion,SA,,,\n"
<< "ID,QBL-" << id << ",,,\n"
<< "Title,,,,\n"
<< "QuestionText," << TextToD2L(question) << ",HTML,,\n"
<< "Points," << points << ",,,\n"
<< "Difficulty,1,,,\n"
<< "Image,,,,\n";
for (const String & option : answers) {
os << "Answer,100," << TextToD2L(option) << ",HTML,\n";
}
os << "Hint," << hint << ",,,\n"
<< "Feedback," << explanation << ",HTML,,\n"
<< ",,,,\n"
<< ",,,,\n";
}
void Question_ShortAnswer::PrintGradeScope(std::ostream& os, size_t q_num, bool compressed) const {
os << "% QUESTION ID " << id << "\n"
<< "\\noindent\\begin{minipage}{\\linewidth}\n"
<< "\\vspace{20pt}\\hangpara{1.8em}{1}\n"
<< q_num << ". " << TextToLatex(question) << "\n";
os << "\\framebox(100,30){}\n"; // Blank answer box.
for (const String & option : answers) {
os << "% Answer:" << option << '\n';
}
os << "\\end{minipage}\n"
<< std::endl;
}
void Question_ShortAnswer::PrintHTML(std::ostream & os, size_t q_num) const {
os << " <!-- Question " << id << " -->\n"
<< " <div class=\"question\">\n"
<< " <p><b>";
if (q_num) os << q_num << ".</b> "; // If we were given a number > 0, print it.
os << TextToHTML(question) << "</p>\n";
os << "<input type=\"text\" id=\"q" << id << "\">\n";
// Leave a div to place the answer.
os << " <div class=\"answer\" data-question=\"q" << id << "\"></div> <!-- Placeholder for answer -->"
<< "</div>\n"
<< std::endl; // Skip a line.
}
void Question_ShortAnswer::PrintJS(std::ostream & os) const {
_TestError(answers.size() == 0,
"Web mode a correct answer for each question, but none found.");
_TestWarning(answers.size() > 1,
"Web mode expects only one correct answer per question; ", answers.size(), " found.");
os << " q" << id << ": \"" << answers[0] << "\",\n";
}
void Question_ShortAnswer::PrintLatex(std::ostream& os) const {
os << "% QUESTION " << id << "\n"
<< "\\question " << TextToLatex(question) << "\n"
<< std::endl
<< "\\begin{saanswer}";
os << std::endl;
for (const String & option : answers) {
os << option << '\n';
}
os << "\\end{saanswer}\n" << std::endl;
}
void Question_ShortAnswer::Validate() {
// Is there at least one valid answer?
_TestError(answers.size() == 0, "At least one answer required.");
}