-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask7.cpp
More file actions
259 lines (223 loc) · 6.28 KB
/
task7.cpp
File metadata and controls
259 lines (223 loc) · 6.28 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
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
#include <iostream>
#include <cstring>
#include <fstream>
#include <vector>
#include <iterator>
#include <algorithm>
#define SIZE 80
using namespace std;
ofstream file1("first.txt", ios::app);
class Books {
public:
virtual void print() = 0;
};
class Name {
public:
void name (char mas[SIZE]) {
file1 << "Volume Name: " << mas << "\t";
}
void name1 () {
cout << "Класс имя"<< endl;
}
};
class Type {
public:
void type (char mas1[SIZE]) {
file1 << "Book type: " << mas1 << "\t";
}
void type1 () {
cout << "Класс тип"<< endl;
}
};
class Print {
public:
void print (char mas2[SIZE]) {
file1 << "Release frequency: " << mas2 << "\t";
}
void print1 () {
cout << "Класс частота выпуска"<< endl;
}
};
class Pages {
public:
void pages (char mas3[SIZE]) {
file1 << "Number of pages: " << *mas3 << "\t";
}
void pages1 () {
cout << "Класс кол-во страниц"<< endl;
}
};
class Edition {
public:
void edition (int mas4[SIZE]) {
file1 << "Edition: " << *mas4 << "\t";
}
void edition1 () {
cout << "Класс тираж"<< endl;
}
};
class Year {
public:
void year (int mas5[SIZE]) {
file1 << "The year of publishing: " << *mas5 << ";" << endl << endl;
}
void year1() {
cout << "Класс год выпуска" << endl;
}
};
class Run : public Name, public Year, public Edition, public Print, public Pages, public Type {
public:
void run() {
char k = 0;
for (;;) {
try {
cout << "Вы хотите отчистить файл?" << endl;
cin >> k;
if ((k > '1') || (k < '0')) {
throw k;
}
if (k == '1') {
ofstream file1;
file1.open("first.txt", ofstream::out | ofstream::trunc);
cout << "Файл был отчищен." << endl;
file1.close();
break;
} else {
cout << "Файл не был тронут." << endl;
file1.close();
break;
}
} catch (char) {
cout << "Введите 0 или 1 " << endl;
}
}
}
};
class Search {
public:
void search (char mas[SIZE]) {
ifstream file1("first.txt", ios::in);
vector<char> mas9;
vector<char> mas10(SIZE);
istream_iterator<char> begin(file1);
istream_iterator<char> end;
copy (begin, end, back_inserter(mas9));
for (int i = 1; i < mas9.size(); i++) {
if (mas[SIZE] == mas9[i]) {
cout << "Такая книга есть в списке" << endl;
} else {
cout << "данных нет" << endl;
}
}
}
};
class Prints: public Books {
public:
void print () {
ifstream file1("first.txt", ios::in);
vector<char> mas9;
vector<char> mas10(SIZE);
istream_iterator<char> begin(file1);
istream_iterator<char> end;
copy (begin, end, back_inserter(mas9));
cout << "Содержимое файла" << endl;
for (int i = 1; i < mas9.size(); i++) {
if (mas9[i] == ';') {
mas9[i] = 0x0A;
}
}
copy(mas9.begin(), mas9.end(), ostream_iterator<char>(cout, ""));
file1.close();
}
};
int main(int argc, const char * argv[]) {
setlocale(0,"");
cout << "Вводите данные на латинице" << endl;
int z = 1;
for(;;) {
if (z == 1) {
char *mas = new char[SIZE];
cout << "Введи название книги" << endl;
gets(mas);
Name a;
a.name(mas);
delete [] mas;
char *mas1 = new char [SIZE];
cout << "Введи тип книги" << endl;
gets(mas1);
Type b;
b.type(mas1);
delete [] mas1;
char *mas2 = new char [SIZE];
cout << "Частота выпуска" << endl;
gets(mas2);
Print d;
d.print(mas2);
delete [] mas2;
char *mas3 = new char [0];
for (;;) {
cout << "Введи кол-во страниц" << endl;
cin >> mas3[0];
try {
if ((mas3[0] > 57) || (mas3[0] < 48)) throw mas3[0];
Pages c;
c.pages(mas3);
delete [] mas3;
break;
} catch (char) {
cout << "Введите число, а не букву" << endl;
}
}
int *mas4 = new int [SIZE];
cout << "Введи тираж" << endl;
cin >> mas4[0];
Edition e;
e.edition(mas4);
delete [] mas4;
int *mas5 = new int [SIZE];
cout << "Введи год издания" << endl;
cin >> mas5[0];
Year f;
f.year(mas5);
delete [] mas5;
for (;;) {
try {
cout << "Хотите добавить новую запись?" << " ";
cin >> z;
if ((z < 0) || (z > 1)) throw z;
break;
} catch (int) {
cout << "Введите либо 0 либо 1" << endl;
}
}
char * mas6 = new char[0];
gets(mas6);
}
else {
file1.close();
break;
}
}
Search k;
char *mas10 = new char [SIZE];
gets(mas10);
k.search(mas10);
Prints p;
p.print();
Run r;
r.run();
r.name1();
r.type1();
r.print1();
r.pages1();
r.edition1();
r.year1();
return 0;
}
/*
Volume[__] = { 1, 2, 3, 4, 5}
Volume[i] = 4
Volume[__] = { 1, 2, 3, \0 ,5}
[1033024023]
[a] [b] [b]
*/