-
Notifications
You must be signed in to change notification settings - Fork 0
/
Books.cpp
422 lines (378 loc) · 10.3 KB
/
Books.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
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#include "Books.h"
#include "fstream"
#include "Animation.h"
#include "Controller.h"
#include <string>
#include <fstream>
using namespace std;
//books
string Book::get_title()
{
return title;
}
void Book::set_id(int i)
{
id = i;
}
float Book::get_price()
{
return price;
}
//gives id whit incrementing
int Book::get_id()
{
string file = "Update ID.txt";
ifstream last_id;
last_id.open(file);
last_id >> id;
last_id.close();
ofstream update_id;
update_id.open(file);
update_id << (id + 1);
update_id.close();
return id;
}
//gives id whithout incrementing
int Book::get_id_no_update()
{
return id;
}
float Book::get_rating()
{
return rating;
}
string Book::get_release_date()
{
return release_date;
}
string Book::get_language()
{
return language;
}
string Book::get_edition()
{
return edition;
}
string Book::get_janres()
{
return janres;
}
string Book::get_writer()
{
return writer;
}
//paper_book get func
string Paper_book::get_publisher()
{
return publisher;
}
int Paper_book::get_pages()
{
return pages;
}
//audio_books get func
string Audio_cd::get_listening_length()
{
return listening_length;
}
string Audio_cd::get_voice()
{
return voice;
}
void Paper_book::add_book()
{
system("cls");
Paper_book pb;
char c;
int color_yellow = 14;
int color_cyan = 17;
cout << endl;
Animation::draw_border(61, color_cyan);
Animation::colorize_text("\t\t Fill the form to add book \n", 07);
Animation::draw_border(61, color_cyan);
cout << endl;
Animation::colorize_text("\n\t\t Title: ", color_yellow);
pb.set_title();
Animation::colorize_text("\t\t Release date: ", color_yellow);
pb.set_release_date();
Animation::colorize_text("\t\t Author: ", color_yellow);
pb.set_writer();
Animation::colorize_text("\t\t Janres: ", color_yellow);
pb.set_janres();
Animation::colorize_text("\t\t Edition: ", color_yellow);
pb.set_edition();
pb.set_language();
pb.set_rating();
pb.set_price();
pb.set_publisher();
pb.set_pages();
Animation::colorize_text("\t\t ID of this book in the system: ", 3);
cout << pb.get_id();
cout << endl;
cout << endl;
ofstream pb_write;
pb_write.open("DataBase/Paper Books/book - " + to_string(pb.get_id_no_update()) + ".info");
pb_write << pb.get_id_no_update() << endl;
pb_write << pb.get_title() << endl;
pb_write << pb.get_release_date() << endl;
pb_write << pb.get_writer() << endl;
pb_write << pb.get_janres() << endl;
pb_write << pb.get_edition() << endl;
pb_write << pb.get_language() << endl;
pb_write << pb.get_rating() << endl;
pb_write << pb.get_price() << endl;
pb_write << pb.get_publisher() << endl;
pb_write << pb.get_pages() << endl;
pb_write.close();
Animation::draw_border(61, color_cyan);
Animation::frame_phrase(" ", color_cyan);
Animation::frame_phrase(" New paper book has been successfully added to database ", color_cyan);
Animation::frame_phrase(" ", color_cyan);
Animation::frame_phrase(" -> Press any key to go back <- ", color_cyan);
Animation::frame_phrase(" ", color_cyan);
Animation::draw_border(61, color_cyan);
cout << endl;
while (true)
{
if (_kbhit())
{
char ch = _getch();
switch (ch)
{
default:
system("cls");
Controller c;
c.admin_panel();
}
}
}
};
void Audio_cd::add_book()
{
system("cls");
Audio_cd pb;
fstream books;
books.open("Audio.dat", ios::binary | ios::in | ios::app);
char c;
int color_yellow = 14;
int color_cyan = 17;
cout << endl;
Animation::draw_border(61, color_cyan);
Animation::colorize_text("\t\t Fill the form to add book \n", 07);
Animation::draw_border(61, color_cyan);
cout << endl;
Animation::colorize_text("\t\t Title: ", color_yellow);
pb.set_title();
Animation::colorize_text("\t\t Release date: ", color_yellow);
pb.set_release_date();
Animation::colorize_text("\t\t Author: ", color_yellow);
pb.set_writer();
Animation::colorize_text("\t\t Janres: ", color_yellow);
pb.set_janres();
Animation::colorize_text("\t\t Edition: ", color_yellow);
pb.set_edition();
pb.set_language();
pb.set_rating();
pb.set_price();
Animation::colorize_text("\t\t Voice: ", color_yellow);
pb.set_voice();
Animation::colorize_text("\t\t Listening length (hours): ", color_yellow);
pb.set_listening_length();
Animation::colorize_text("\t\t ID of this book in the system: ", 3);
cout << pb.get_id();
cout << endl;
cout << endl;
Animation::draw_border(61, color_cyan);
Animation::frame_phrase(" ", color_cyan);
Animation::frame_phrase(" New audio book has been successfully added to database ", color_cyan);
Animation::frame_phrase(" ", color_cyan);
Animation::frame_phrase(" -> Press any key to go back <- ", color_cyan);
Animation::frame_phrase(" ", color_cyan);
Animation::draw_border(61, color_cyan);
cout << endl;
ofstream pb_write;
pb_write.open("DataBase/Audio CD/book - " + to_string(pb.get_id_no_update()) + ".info");
pb_write << pb.get_id_no_update() << endl;
pb_write << pb.get_title() << endl;
pb_write << pb.get_release_date() << endl;
pb_write << pb.get_writer() << endl;
pb_write << pb.get_janres() << endl;
pb_write << pb.get_edition() << endl;
pb_write << pb.get_language() << endl;
pb_write << pb.get_rating() << endl;
pb_write << pb.get_price() << endl;
pb_write << pb.get_voice() << endl;
pb_write << pb.get_listening_length() << endl;
pb_write.close();
books.write((char*)&pb, sizeof(pb));
books.close();
while (true)
{
if (_kbhit())
{
char ch = _getch();
switch (ch)
{
default:
system("cls");
Controller c;
c.admin_panel();
}
}
}
};
void Digital_book::add_book()
{
system("cls");
Digital_book pb;
fstream books;
books.open("Digital.dat", ios::binary | ios::in | ios::app);
char c;
int color_yellow = 14;
int color_cyan = 17;
cout << endl;
Animation::draw_border(61, color_cyan);
Animation::colorize_text("\t\t Fill the form to add book \n", 07);
Animation::draw_border(61, color_cyan);
cout << endl;
Animation::colorize_text("\t\t Title: ", color_yellow);
pb.set_title();
Animation::colorize_text("\t\t Release date: ", color_yellow);
pb.set_release_date();
Animation::colorize_text("\t\t Author: ", color_yellow);
pb.set_writer();
Animation::colorize_text("\t\t Janres: ", color_yellow);
pb.set_janres();
Animation::colorize_text("\t\t Edition: ", color_yellow);
pb.set_edition();
pb.set_language();
pb.set_rating();
pb.set_price();
Animation::colorize_text("\t\t ID of this book in the system: ", 3);
cout << pb.get_id();
cout << endl;
cout << endl;
Animation::draw_border(61, color_cyan);
Animation::frame_phrase(" ", color_cyan);
Animation::frame_phrase(" New digit-book has been successfully added to database ", color_cyan);
Animation::frame_phrase(" ", color_cyan);
Animation::frame_phrase(" -> Press any key to go back <- ", color_cyan);
Animation::frame_phrase(" ", color_cyan);
Animation::draw_border(61, color_cyan);
cout << endl;
ofstream pb_write;
pb_write.open("DataBase/Digital Books/book - " + to_string(pb.get_id_no_update()) + ".info");
pb_write << pb.get_id_no_update() << endl;
pb_write << pb.get_title() << endl;
pb_write << pb.get_release_date() << endl;
pb_write << pb.get_writer() << endl;
pb_write << pb.get_janres() << endl;
pb_write << pb.get_edition() << endl;
pb_write << pb.get_language() << endl;
pb_write << pb.get_rating() << endl;
pb_write << pb.get_price() << endl;
pb_write.close();
books.write((char*)&pb, sizeof(pb));
books.close();
while (true)
{
if (_kbhit())
{
char ch = _getch();
switch (ch)
{
default:
system("cls");
Controller c;
c.admin_panel();
}
}
}
};
void Book::set_title()
{
string t;
getline(cin, t);
title = t;
}
void Book::set_price()
{
float t = -1;
while (t < 0 || !(cin.good()) || t > 10000000)
{
cin.clear();
cin.ignore(100, '\n');
Animation::colorize_text("\t\t Price in sums: ", 14);
cin >> t;
price = t;
}
}
void Book::set_release_date()
{
string t;
getline(cin, t);
release_date = t;
}
void Book::set_language()
{
string t;
Animation::colorize_text("\t\t Language: ", 14);
cin >> t;
language = t;
}
void Book::set_edition()
{
string t;
getline(cin, t);
edition = t;
}
void Book::set_writer()
{
string t;
getline(cin, t);
writer = t;
}
void Book::set_rating()
{
float t = - 1;
while (t < 1 || t > 10 || !(cin.good()))
{
cin.clear();
cin.ignore(100, '\n');
Animation::colorize_text("\t\t Rating (1 -> 10): ", 14);
cin >> t;
rating = t;
}
}
void Paper_book::set_publisher()
{
Animation::colorize_text("\t\t Publisher: ", 14);
cin >> publisher;
}
void Paper_book::set_pages()
{
int t = -1;
while (t < 0 || !(cin.good()))
{
cin.clear();
cin.ignore(100, '\n');
Animation::colorize_text("\t\t Volume in pages: ", 14);
cin >> t;
pages = t;
}
}
void Audio_cd::set_voice()
{
getline(cin, voice);
}
void Audio_cd::set_listening_length()
{
getline(cin, listening_length);
getline(cin, listening_length);
}
void Book::set_janres()
{
string t;
getline(cin, t);
janres = t;
}