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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
| #include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <Windows.h>
using namespace std;
ofstream ofhot;
ifstream ifhot;
class Hotel
{
private:
int index;
string name;
string telNumber;
string pasport;
string roomNumber;
string entryDate;
string departDate;
string releaseForm;
vector<Hotel> hotel;
public:
Hotel() {};
Hotel(int index, string name, string telNumber, string pasport, string roomNumber, string entryDate, string departDate, string releaseForm) :
index(index), name(name), telNumber(telNumber), pasport(pasport), roomNumber(roomNumber), entryDate(entryDate), departDate(departDate), releaseForm(releaseForm) {}
void Numbering(vector<Hotel>& hotel) {
unsigned short count = 0;
for (vector<Hotel>::iterator i = hotel.begin(); i != hotel.end(); i++)
{
(*i).index = count + 1;
count++;
}
};
void AddHotelClient(vector<Hotel>& hotel) {
system("cls");
cout << "Добавить клиента" << endl;
cout << "Введите ФИО клиента: " << endl;
getline(cin, name);
cout << "Введите номер телефона клиента:" << endl;
getline(cin, telNumber);
cout << "Введите паспортные данные клиента:" << endl;
getline(cin, pasport);
cout << "Введите введите номер комнаты:" << endl;
getline(cin, roomNumber);
cout << "Введите дату въезда:" << endl;
getline(cin, entryDate);
cout << "Введите дату выезда:" << endl;
getline(cin, departDate);
cout << "Введите способ оплаты:" << endl;
getline(cin, releaseForm);
index = hotel.size() + 1;
hotel.push_back(Hotel(index, name, telNumber, pasport, roomNumber, entryDate, departDate, releaseForm));
system("cls");
cout << "Клиент добавлен!" << endl;
system("pause");
};
void ShowHotel(vector<Hotel>& hotel) {
vector<Hotel>::iterator it;
Numbering(hotel);
cout << left << setw(3) << "№"
<< setw(40) << "ФИО клиента"
<< setw(10) << "Номер телефона" << endl;
for (it = hotel.begin(); it != hotel.end(); it++) {
cout << left << setw(3) << (*it).index
<< setw(40) << (*it).name
<< setw(10) << (*it).telNumber << endl;
}
};
void ShowHotelDetail(vector<Hotel>& hotel) {
system("cls");
if (hotel.size() == 0) cout << "Список клиентов пуст!" << endl;
else {
ShowHotel(hotel);
cout << "Введите номер клиента для отображения подробного описания." << endl;
string sChoose;
getline(cin, sChoose);
int choose = atoi(sChoose.c_str());
if (choose <= hotel.size() && choose > 0) {
for (vector<Hotel>::iterator i = hotel.begin(); i != hotel.end(); i++) {
if ((*i).index == choose) {
system("cls");
cout << setw(20) << "ФИО:" << (*i).name << "\n" << endl
<< setw(20) << "Номер телефона:" << (*i).telNumber << endl
<< "\nПаспортные данные:\n" << (*i).pasport << endl
<< "\nНомер комнаты:\n" << (*i).roomNumber << endl
<< "\nДата въезда:\n" << (*i).entryDate << endl
<< "\nДата выезда:\n" << (*i).departDate << "\n" << endl
<< setw(20) << "Способ оплаты:" << (*i).releaseForm << "\n" << endl;
}
}
}
else cout << "Неверный номер клиента!" << endl;
}
system("pause");
};
void SortHotel(vector<Hotel>& hotel) {
system("cls");
if (hotel.size() == 0) cout << "Список клиентов пуст!" << endl;
else {
sort(hotel.begin(), hotel.end(), []
(Hotel const& a, Hotel const& b)->
bool {return a.name < b.name; });
Numbering(hotel);
cout << "Сортировка выполнена!" << endl;
}
system("pause");
}
void SearchHotel(vector<Hotel>& hotel) {
system("cls");
if (hotel.size() == 0) cout << "Список клиентов пуст!" << endl;
else {
int search, count = 0;
string sSearch;
cout << "Введите слово для поиска, состоящее минимум из 4 букв." << endl;
getline(cin, sSearch);
if (sSearch.size() > 3) {
system("cls");
for (vector<Hotel>::iterator i = hotel.begin(); i != hotel.end(); i++) {
if ((search = (*i).name.find(sSearch)) != -1 ||
(search = (*i).pasport.find(sSearch)) != -1 ||
(search = (*i).entryDate.find(sSearch)) != -1 ||
(search = (*i).departDate.find(sSearch)) != -1 ||
(search = (*i).roomNumber.find(sSearch)) != -1) {
cout << setw(20) << "ФИО:" << (*i).name << "\n" << endl
<< setw(20) << "Номер телефона:" << (*i).telNumber << endl
<< "\nПаспортные данные:" << (*i).pasport << endl
<< "\nНомер комнаты:\n" << (*i).roomNumber << endl
<< "\nДата въезда:\n" << (*i).entryDate << endl
<< "\nДата выезда:\n" << (*i).departDate << "\n" << endl
<< setw(20) << "Способ оплаты:" << (*i).releaseForm << "\n" << endl;
cout << "=========================================================================" << endl;
count++;
}
}
if (count == 0) {
cout << "Совпадений не найдено." << endl;
system("cls");
}
}
}
system("pause");
};
void DeleteHotelClient(vector<Hotel>& hotel) {
system("cls");
if (hotel.size() == 0) cout << "Список клиентов пуст!" << endl;
else {
ShowHotel(hotel);
string sDel;
cout << "Введите номер клиента, которого нужно удалить." << endl;
getline(cin, sDel);
int delIndex = atoi(sDel.c_str());
if (delIndex > 0 && delIndex <= hotel.size()) {
system("cls");
hotel.erase(hotel.begin() + (delIndex - 1));
vector<Hotel>(hotel).swap(hotel);
cout << "Клиент удалён из списка!" << endl;
}
else {
cout << "Неверный номер клиента!" << endl;
}
}
system("pause");
};
void WriteInTxtFile(vector<Hotel>& hotel) {
system("cls");
if (hotel.size() == 0) cout << "Список " << endl;
else {
ofhot.open("hot.txt");
for (vector<Hotel>::iterator i = hotel.begin(); i != hotel.end(); ++i) {
if ((i + 1) == hotel.end()) {
ofhot << (*i).index << endl;
ofhot << (*i).name << endl;
ofhot << (*i).telNumber << endl;
ofhot << (*i).pasport << endl;
ofhot << (*i).roomNumber << endl;
ofhot << (*i).entryDate << endl;
ofhot << (*i).departDate << endl;
ofhot << (*i).releaseForm;
}
else {
ofhot << (*i).index << endl;
ofhot << (*i).name << endl;
ofhot << (*i).telNumber << endl;
ofhot << (*i).pasport << endl;
ofhot << (*i).roomNumber << endl;
ofhot << (*i).entryDate << endl;
ofhot << (*i).departDate << endl;
ofhot << (*i).releaseForm << endl;
}
}
ofhot.close();
cout << "Данные записаны в текстовый файл." << endl;
system("pause");
}
};
void ReadTxtAndWriteInVector(vector<Hotel>& hotel) {
system("cls");
ifhot.open("hot.txt", ios_base::in);
if (ifhot.peek() == ifstream::traits_type::eof())
{
cout << "Данные в текстовом файле отсутствуют." << endl;
system("pause");
}
else
{
string forIndex;
int Index;
while (!ifhot.eof())
{
getline(ifhot, forIndex);
getline(ifhot, name);
getline(ifhot, telNumber);
getline(ifhot, pasport);
getline(ifhot, roomNumber);
getline(ifhot, entryDate);
getline(ifhot, departDate);
getline(ifhot, releaseForm);
Index = atoi(forIndex.c_str());
hotel.push_back(Hotel(Index, name, telNumber, pasport, roomNumber, entryDate, departDate, releaseForm));
}
cout << "Данные из текстового файла считаны!" << endl;
system("pause");
}
ifhot.close();
};
void Menu() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
string sChoose = "";
int choose;
while (1) {
system("cls");
cout << "Справочник клиентов\n" << endl;
cout << "1.Добавить клиента." << endl;
cout << "2.Вывести список лклиентов на экран." << endl;
cout << "3.Поиск." << endl;
cout << "4.Выполнить сортировку ФИО по алфавиту." << endl;
cout << "5.Удалить клиента из списка." << endl;
cout << "6.Записать список клллиентов в текстовый файл." << endl;
cout << "7.Считать список клиентов из текстового файла(текущие данные будут удалены)." << endl;
cout << "\nexit - Выход.\n" << endl;
getline(cin, sChoose);
choose = atoi(sChoose.c_str());
if (sChoose == "exit") {
exit(EXIT_FAILURE);
}
switch (choose) {
case 1:
AddHotelClient(hotel);
break;
case 2:
ShowHotelDetail(hotel);
break;
case 3:
SearchHotel(hotel);
break;
case 4:
SortHotel(hotel);
break;
case 5:
DeleteHotelClient(hotel);
break;
case 6:
WriteInTxtFile(hotel);
break;
case 7:
ReadTxtAndWriteInVector(hotel);
default:
break;
}
}
};
~Hotel() {};
};
int main() {
Hotel A;
A.Menu();
return 0;
} |