-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathparagraph.cpp
More file actions
70 lines (59 loc) · 1.49 KB
/
Copy pathparagraph.cpp
File metadata and controls
70 lines (59 loc) · 1.49 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
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
vector<string> split(string s, char c);
class Paragraph
{
private:
string difficulty;
string toType;
public:
Paragraph(string difficulty)
{
this->difficulty = difficulty;
string filename;
if (this->difficulty == "easy")
{
filename = "./Database/WordLists/easy.txt";
}
else if (this->difficulty == "medium")
{
filename = "./Database/WordLists/medium.txt";
}
else if (this->difficulty == "hard")
{
filename = "./Database/WordLists/hard.txt";
}
else if (this->difficulty == "timeAttack")
{
filename = "./Database/WordLists/timeAttack.txt";
}
fstream file;
file.open(filename.c_str());
string output;
vector<string> paragraphs;
while (getline(file, output))
{
paragraphs.push_back(output);
}
file.close();
srand((int)time(NULL));
int select = rand()%paragraphs.size();
this->toType = paragraphs[select];
}
vector<string> getParagraph()
{
vector<string> lines = split(toType, '.');
return lines;
}
};
vector<string> split(string s, char c) {
vector <string> tokens;
stringstream check1(s);
string intermediate;
while(getline(check1, intermediate, c))
{
tokens.push_back(intermediate);
}
return tokens;
}