-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputN.cpp
More file actions
211 lines (199 loc) · 4.75 KB
/
inputN.cpp
File metadata and controls
211 lines (199 loc) · 4.75 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include "stdafx.h"
#include "headerA.h"
void NameWay_countSpaces::parcel(string line)
{
count_spaces = line.find_first_not_of(" ");
name_way = line.substr(line.find_first_not_of(" "));
}
bool Position_in_menu::parceling_line(string line) //0óñïåõ 1íå óñïåõ
{
regex tmpRegex("\\s*(.+?)[\\s=]+(\\d+)[,\\.](\\d{2})");
smatch match;
if (!regex_search(line, match, tmpRegex)) return 1;
// â ìàò÷å:
//ìàò÷(0) âñÿ ñòðîêà
//ìàò÷(1) íàçâàíèå
//ìàò÷(2) ðóáëè
//ìàò÷(3) êîïåéêè
name = match.str(1);
rubles = stoi(match.str(2));
kopecks = stoi(match.str(3));
cout << match.str(0) << endl;
cout << match.str(1) << endl;
cout << match.str(2) << endl;
cout << match.str(3) << endl;
return 0;
}
void Position_in_menu::clear()
{
name = "";
rubles = 0;
kopecks = 0;
way.clear();
}
bool Position_in_kc::parcelling_string(string line) //0 success 1 fail
{
regex tmpRegex("\\s*(.+?)[\\s=]+?(\\d+)\\s*");
smatch match;
if (!regex_search(line, match, tmpRegex)) return 1;
// â ìàò÷å:
//ìàò÷(0) âñÿ ñòðîêà
//ìàò÷(1) íàçâàíèå
//ìàò÷(2) êîëè÷åñòâî
name_dish = match.str(1);
count = stoi(match.str(2));
return 0;
}
vector<string> Menu::opredelenie_puti_po_strochke(string line)
{
int count_spaces = line.find_first_not_of(" ");
list<NameWay_countSpaces>::iterator iter;
vector<string> way;
way.clear();
iter = kategories_list.end();
--iter;
while (count_spaces <= iter->count_spaces)
{
iter--;
kategories_list.pop_back();
}
for (iter = kategories_list.begin(); iter != kategories_list.end(); ++iter)
{
way.push_back(iter->name_way);
}
return way;
}
int Menu::inputMenu()
{
NameWay_countSpaces tmpWay;
vector<string> way_now;
bool flag; //ïàðñåëüíóëàñü ëè ñòðî÷êà?
Position_in_menu positionTmp;
string name_dish;
int count;
double price;
cout << "Enter name of 'menu' file." << endl;
cin >> name_dish;
ifstream fin(name_dish);
if (!fin.is_open())
{
cout << "menu file is not found." << endl;
system("pause");
exit(-1);
}
while (!fin.eof())//÷òåíèå ìåíþøêè
{
getline(fin, name_dish);
positionTmp.clear();
flag = positionTmp.parceling_line(name_dish); //0óñïåõ 1íå óñïåõ
if (!flag)
{
positionTmp.way = opredelenie_puti_po_strochke(name_dish);
list_position.push_back(positionTmp);
continue;
}
//åñëè ñòðî÷êà íå âèäà íàçâàíèå öåíà...
regex tmpRegex("\\s*.+\\s*");
smatch match;
if (!regex_search(name_dish, match, tmpRegex)) return 10; //ÎØÈÁÊÀ ¹10:ÑÒÐÎÊÀ Â ÌÅÍÞ ÍÅ ÏÎÄÕÎÄÈÒ ÏÎÄ ÎÏÈÑÀÍÈÅ ÍÈ ÊÀÒÅÃÎÐÈÈ ÍÈ ÁËÞÄÎ ÖÅÍÀ
// åñëè ñòðîêà ïoäõîäèò ïîä îïèñàíèå êàòåãîðèè
tmpWay.parcel(name_dish);
list <NameWay_countSpaces>::iterator iter = kategories_list.end();
if (kategories_list.size() > 0)
{
iter--;
while ((kategories_list.size() > 0) && (tmpWay.count_spaces <= iter->count_spaces))
{
if (kategories_list.size() > 1)
{
iter--;
}
kategories_list.pop_back();
}
kategories_list.push_back(tmpWay);
}
else
{
kategories_list.push_back(tmpWay);
}
}
}
int Kitchen::inputKitchen()
{
string line;
ifstream fin;
Position_in_kc one_pos;
cout << "Enter name of 'kitchen' file." << endl;
cin >> line;
fin.open(line);
if (!fin.is_open())
{
cout << "Kitchen file is not found." << endl;
system("pause");
exit(-1);
}
while (!fin.eof())
{
getline(fin, line);
if (one_pos.parcelling_string(line))
{
cout << "error in line:" << line << endl;
exit(-1);
}
else //0success 1 fail
list_k.push_back(one_pos);
}
}
void OneCheck::clear()
{
number = 0;
list_position.clear();
sum_kopecks = 0;
sum_rubles = 0;
}
int Checks::inputCheck()
{
string line;
Position_in_kc positionTmp;
OneCheck tmpCheck;
cout << "Enter name of 'check' file." << endl;
cin >> line;
ifstream fin(line);
if (!fin.is_open())
{
cout << "Check file is not found." << endl;
system("pause");
exit(-1);
}
tmpCheck.clear();
while (!fin.eof())
{
getline(fin, line);
regex tmpRegex(".+¹\\s*([0-9]+)\\s*");
smatch match;
if (regex_search(line, match, tmpRegex))
{
tmpCheck.number = stoi(match.str(1));
continue;
}
tmpRegex = "èòîãî:\\s*([0-9]+)[.,]([0-9]+)";
if (regex_search(line, match, tmpRegex))
{
tmpCheck.sum_rubles = stoi(match.str(1));
tmpCheck.sum_kopecks = stoi(match.str(2));
continue;
}
if (!positionTmp.parcelling_string(line)) //0 success 1 fail
{
tmpCheck.list_position.push_back(positionTmp);
continue;
}
if (line.find("======") == -1)
{
cout << "error in line:" << endl << line << endl << "can't read" << endl;
exit(-1);
}
list_ch.push_back(tmpCheck);
tmpCheck.clear();
}
}