-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
81 lines (71 loc) · 1.87 KB
/
main.cpp
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
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdlib>
using namespace std;
vector<string> dataBase;
void filling();
void printVectorContent();
int getSelectionKey();
string getOneElementRandomly();
int main()
{
cout << " Hi!" << endl;
while (true) {
cout << " Please enter some data into dataBase (by one word in string)." << endl;
cout << " Write \".\" to finish entering." << endl << endl;
filling();
printVectorContent();
string myElement = getOneElementRandomly();
cout << endl << " Your element is: ";
cout << myElement << endl;
cout << endl << " Would you like to continue? (y/n)" << endl;
char a = '0';
cout << "> ";
cin >> a;
while (( a != 'n' ) && (a != 'y')) {
cout << " Please use '";
cout << "y";
cout << "' or '";
cout << "n";
cout << "' to select the action." << endl;
cout << "> ";
cin >> a;
}
if ( (a == 'N') || (a == 'n') ) {
cout << " Okay! Nice to meet you." << endl;
break;
} else {
system("cls");
dataBase.clear();
}
}
system("pause");
return 0;
}
void filling() {
{
string myStr;
cout << "> ";
cin >> myStr;
while (true) {
dataBase.insert(dataBase.end(), myStr);
cout << "> ";
cin >> myStr;
if (myStr[0] == '.') {
break;
}
}
}
}
void printVectorContent() {
cout << endl << " Data base content:" << endl;
for (int i = 0; i < (int) dataBase.size(); i++) {
cout << " Element " << i << ": ";
cout << dataBase.at(i) << endl;
}
}
string getOneElementRandomly() {
int k = rand() % dataBase.size() + 0;
return dataBase.at(k);
}