-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionSort.cpp
More file actions
61 lines (46 loc) · 1.73 KB
/
QuestionSort.cpp
File metadata and controls
61 lines (46 loc) · 1.73 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
#include "main.h"
#include "utilities.h"
using namespace std;
int main(void) {
srand(time(NULL));
string fileNameTest = "Test";
string firstLine, secondLine, header = "", dummystr;
int numberOfTestsToWrite = 0;
vector<pair<string, vector<string>>> singleQuestions; //first element is the question, second element is an array containing the answers.
fstream MasterKey("MasterKey.qsrt", ios::in); //file with form
fstream Answers("ForTeachers.qsrt", ios::out); //file with answers,for teacher to correct.
fstream Tests;
FileManager myManager;
if (!MasterKey.bad() && !Answers.bad() && !myManager.getHeaderHTML(header)) {
//filling vector
while (getline(MasterKey, firstLine) && getline(MasterKey, secondLine) && !MasterKey.fail()) { //read two lines from file
singleQuestions.push_back(make_pair(firstLine, myManager.parser(secondLine))); //filling singleQuestions with couple of question - answer(s)
}
do {
cin.clear();
cout << "How many tests do you want to prepare? ";
cin >> numberOfTestsToWrite;
} while (cin.fail());
for (int i = 1; i <= numberOfTestsToWrite; i++) {
//open file
Tests.open((fileNameTest + to_string(i) + ".html"), ios::out);
if (!Tests.bad()) {
Tests << header; //inserting header in each test
myManager.shuffler(singleQuestions); //shuffles both quetions and multiple choice answers
if (!myManager.WriteQuestionsOnFile(singleQuestions, Answers, Tests,i==1)) {
Tests.close();
}
else {
cout << "An Error occurred while writing tests...";
exit(EXIT_FAILURE);
}
}
}
MasterKey.close();
Answers.close();
}
else {
cout << "An Error occurred while opening the files...";
}
return 0;
}