-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
102 lines (79 loc) · 1.71 KB
/
Test.cpp
File metadata and controls
102 lines (79 loc) · 1.71 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "Test.h"
void Test::EditQuestion(Questions& a)
{
str tmp;
cout << "Enter new question" << endl;
getline(cin, tmp);
a.question = tmp;
}
void Test::AddQuestion()
{
Questions tmp;
int tmpnum;
cout << "Enter your question" << endl;
getline(cin, tmp.question);
cout << "Enter number of answers " << endl;
cin >> tmpnum;
tmp.answers.resize(tmpnum);
for (auto& i : tmp.answers)
{
cout << "Enter answer (put '!' at the beginning of correct answer)" << endl;
getline(cin, i);
if (i[0] == '!')
tmp.correct_answer = i;
i.erase(0);
}
test.push_back(tmp);
}
void Test::DelQuestion()
{
string cinstr;
cout << "Here is your questions. With the help of them, you can enter a few key words to find neariest question you wanna delete" << endl;
for (auto& i : test)
cout << i.question << endl;
cout << "So, now it`s your turn to enter " << endl;
getline(cin, cinstr);
int max = 0;
for (int i = 0; i < test.size() - 1; i++)
{
if (test.begin()[i].question.find(cinstr) > test.begin()[i + 1].question.find(cinstr))
max = i;
else
max = i + 1;
}
test.erase(test.begin() + max);
}
void Test::load_data()
{
ofstream load("Tests.txt");
for (auto& i : test)
{
load << i.question << endl;
load << i.correct_answer << endl;
for (auto& k : i.answers)
{
load << k;
}
}
}
void Test::upload_data()
{
ifstream download("Tests.txt");
for (auto& i : test)
{
getline(download, i.question);
getline(download, i.correct_answer);
for (auto& k : i.answers)
{
getline(download, k);
i.answers.push_back(k);
}
}
}
void Test::print_question() const
{
for (auto& i : test) {
cout << " >>> " << i.question << " <<<\n";
for (auto& k : i.answers) cout << k << "\n";
}
}