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
| #include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <Windows.h>
using namespace std;
ofstream ofmed;
ifstream ifmed;
class MedBook
{
private:
int index;
string name;
string position;
string address;
string telephone;
string indications;
string сontraindications;
string releaseForm;
vector<MedBook> medbook;
public:
MedBook() {};
MedBook(int index, string name, string cost, string description, string composition, string indications, string сontraindications, string releaseForm) :
index(index), name(name), cost(cost), description(description), composition(composition), indications(indications), сontraindications(сontraindications), releaseForm(releaseForm) {}
void Numbering(vector<MedBook>& book) {
unsigned short count = 0;
for (vector<MedBook>::iterator i = book.begin(); i != book.end(); i++)
{
(*i).index = count + 1;
count++;
}
};
void AddMedPrep(vector<MedBook>& book) {
system("cls");
cout << "Добавить сотрудника в базу данных" << endl;
cout << "Введите навзание препарата: " << endl;
getline(cin, name);
cout << "Введите цену препарата:" << endl;
getline(cin, cost);
cout << "Введите описание препарата:" << endl;
getline(cin, description);
cout << "Введите состав препарата:" << endl;
getline(cin, composition);
cout << "Введите показания к применению:" << endl;
getline(cin, indications);
cout << "Введите противопоказания:" << endl;
getline(cin, сontraindications);
cout << "Введите формы выпуска препарата:" << endl;
getline(cin, releaseForm);
index = book.size() + 1;
book.push_back(MedBook(index, name, cost, description, composition, indications, сontraindications, releaseForm));
system("cls");
cout << "Препарат добавлен!" << endl;
system("pause");
};
void ShowMedPreps(vector<MedBook>& book) {
vector<MedBook>::iterator it;
Numbering(book);
cout << left << setw(3) << "№"
<< setw(40) << "Название препарата"
<< setw(10) << "Цена(руб.)" << endl;
for (it = book.begin(); it != book.end(); it++) {
cout << left << setw(3) << (*it).index
<< setw(40) << (*it).name
<< setw(10) << (*it).cost << endl;
}
};
void ShowMedPrepsDetail(vector<MedBook>& book) {
system("cls");
if (book.size() == 0) cout << "Список с препаратами пуст!" << endl;
else {
ShowMedPreps(book);
cout << "Введите номер препарата для отображения подробного описания." << endl;
string sChoose;
getline(cin, sChoose);
int choose = atoi(sChoose.c_str());
if (choose <= book.size() && choose > 0) {
for (vector<MedBook>::iterator i = book.begin(); i != book.end(); i++) {
if ((*i).index == choose) {
system("cls");
cout << setw(20) << "Название:" << (*i).name << "\n" << endl
<< setw(20) << "Цена(руб.):" << (*i).cost << endl
<< "\nОписание:\n" << (*i).description << endl
<< "\nСостав:\n" << (*i).composition << endl
<< "\nПоказания к применению:\n" << (*i).indications << endl
<< "\nПротивопоказания:\n" << (*i).сontraindications << "\n" << endl
<< setw(20) << "Формы выпуска:" << (*i).releaseForm << "\n" << endl;
}
}
}
else cout << "Неверный номер препарата!" << endl;
}
system("pause");
};
void SortMedPreps(vector<MedBook>& book) {
system("cls");
if (book.size() == 0) cout << "Список с препаратами пуст!" << endl;
else {
sort(book.begin(), book.end(), []
(MedBook const& a, MedBook const& b)->
bool {return a.name < b.name; });
Numbering(book);
cout << "Сортировка выполнена!" << endl;
}
system("pause");
}
void SearchMedPrep(vector<MedBook>& book) {
system("cls");
if (book.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<MedBook>::iterator i = book.begin(); i != book.end(); i++) {
if ((search = (*i).name.find(sSearch)) != -1 ||
(search = (*i).description.find(sSearch)) != -1 ||
(search = (*i).indications.find(sSearch)) != -1 ||
(search = (*i).сontraindications.find(sSearch)) != -1 ||
(search = (*i).composition.find(sSearch)) != -1) {
cout << setw(20) << "Название:" << (*i).name << "\n" << endl
<< setw(20) << "Цена(руб.):" << (*i).cost << endl
<< "\nОписание:" << (*i).description << endl
<< "\nСостав:\n" << (*i).composition << endl
<< "\nПоказания к применению:\n" << (*i).indications << endl
<< "\nПротивопоказания:\n" << (*i).сontraindications << "\n" << endl
<< setw(20) << "Формы выпуска:" << (*i).releaseForm << "\n" << endl;
cout << "=========================================================================" << endl;
count++;
}
}
if (count == 0) {
cout << "Совпадений не найдено." << endl;
system("cls");
}
}
}
system("pause");
};
void DeleteMedPrep(vector<MedBook>& book) {
system("cls");
if (book.size() == 0) cout << "Список с препаратами пуст!" << endl;
else {
ShowMedPreps(book);
string sDel;
cout << "Введите номер препарата, который нужно удалить." << endl;
getline(cin, sDel);
int delIndex = atoi(sDel.c_str());
if (delIndex > 0 && delIndex <= book.size()) {
system("cls");
book.erase(book.begin() + (delIndex - 1));
vector<MedBook>(book).swap(book);
cout << "Препарат удалён из списка!" << endl;
}
else {
cout << "Неверный номер препарата!" << endl;
}
}
system("pause");
};
void WriteInTxtFile(vector<MedBook>& book) {
system("cls");
if (book.size() == 0) cout << "Список " << endl;
else {
ofmed.open("med.txt");
for (vector<MedBook>::iterator i = book.begin(); i != book.end(); ++i) {
if ((i + 1) == book.end()) {
ofmed << (*i).index << endl;
ofmed << (*i).name << endl;
ofmed << (*i).cost << endl;
ofmed << (*i).description << endl;
ofmed << (*i).composition << endl;
ofmed << (*i).indications << endl;
ofmed << (*i).сontraindications << endl;
ofmed << (*i).releaseForm;
}
else {
ofmed << (*i).index << endl;
ofmed << (*i).name << endl;
ofmed << (*i).cost << endl;
ofmed << (*i).description << endl;
ofmed << (*i).composition << endl;
ofmed << (*i).indications << endl;
ofmed << (*i).сontraindications << endl;
ofmed << (*i).releaseForm << endl;
}
}
ofmed.close();
cout << "Данные записаны в текстовый файл." << endl;
system("pause");
}
};
void ReadTxtAndWriteInVector(vector<MedBook>& book) {
system("cls");
ifmed.open("med.txt", ios_base::in);
if (ifmed.peek() == ifstream::traits_type::eof())
{
cout << "Данные в текстовом файле отсутствуют." << endl;
system("pause");
}
else
{
string forIndex;
int Index;
while (!ifmed.eof())
{
getline(ifmed, forIndex);
getline(ifmed, name);
getline(ifmed, cost);
getline(ifmed, description);
getline(ifmed, composition);
getline(ifmed, indications);
getline(ifmed, сontraindications);
getline(ifmed, releaseForm);
Index = atoi(forIndex.c_str());
book.push_back(MedBook(Index, name, cost, description, composition, indications, сontraindications, releaseForm));
}
cout << "Данные из текстового файла считаны!" << endl;
system("pause");
}
ifmed.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:
AddMedPrep(medbook);
break;
case 2:
ShowMedPrepsDetail(medbook);
break;
case 3:
SearchMedPrep(medbook);
break;
case 4:
SortMedPreps(medbook);
break;
case 5:
DeleteMedPrep(medbook);
break;
case 6:
WriteInTxtFile(medbook);
break;
case 7:
ReadTxtAndWriteInVector(medbook);
default:
break;
}
}
};
~MedBook() {};
};
int main() {
MedBook A;
A.Menu();
return 0;
} |