-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
1712 lines (1558 loc) · 54 KB
/
Copy pathmain.cpp
File metadata and controls
1712 lines (1558 loc) · 54 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
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include<fstream>
#include <cstring>
#include <ctime>
#include <vector>
#include <memory>
#include <string>
#include <stdexcept>
#include <cstdlib>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include "Menu.h"
using namespace std;
ifstream serviceIn("streaming_services.txt");
ifstream abonamentIn("abonament.txt");
const unsigned int MAX_LENGTH = 256;
class Service{
const int ServiceId;
static list<Service> listOfServices;
static int generator;
string serviceName;
int abonament;
public:
Service(): ServiceId(++generator){
this->abonament = -1;
this->serviceName="Inactiv";
}
Service(const string& serviceName, int abonament): ServiceId(++generator), abonament(abonament){
this->serviceName=serviceName;
}
Service(const Service& other): ServiceId(other.ServiceId), abonament(other.abonament){
this->serviceName = other.serviceName;
}
~Service()=default;
friend istream& operator>>(istream& in, Service& service){
cout<<"Numele serviciului selectat este:"<<'\n';
getline(in, service.serviceName);
cout<<"Pentru a accesa serviciul, selecteaza un abonament dintre cele disponibile:"<<'\n';
abonamentIn.clear();
abonamentIn.seekg(0, ios::beg);
char ab[MAX_LENGTH];
int index = 1;
while(abonamentIn.getline(ab, MAX_LENGTH)){
cout<<index<<" -> "<<ab<<'\n';
index++;
}
int tempAbonament;
bool validInput = false;
while (!validInput) {
cout << "Pretul abonamentului selectat este(0$,10$,50$,100$): "<<'\n';
in >> tempAbonament;
in.get();
try {
service.setAbonament(tempAbonament);
validInput = true;
} catch (const std::invalid_argument& e) {
cout << e.what() << " Reselecteaza pretul corect." << std::endl;
}
}
return in;
}
friend ostream& operator<<(ostream& out, const Service &service){
cout<<"Serviciul selectat este: ";
out<<service.serviceName<<'\n';
cout<<"Pretul abonamentului selectat este de: ";
out<<service.abonament<<"$"<<'\n';
return out;
}
bool operator==(const Service &service) const{
return (this->abonament==service.abonament && this->serviceName==service.serviceName);
}
int operator-(const Service &service)const{
return (this->abonament - service.abonament);
}
bool operator>=(Service &service)const{
return(this->abonament>=service.abonament);
}
int operator--(){
return (this->abonament - 1);
}
bool operator<=(Service &service)const{
return (this->abonament<=service.abonament);
}
Service &operator[](int index){
if (index<0 || index>=static_cast<int>(listOfServices.size()))
throw out_of_range("Ai introdus un serviciu care nu este activ!");
else{
auto it = listOfServices.begin();
advance(it,index);
return *it;
}
}
Service &operator=(const Service &service){
if (this != &service){
this->abonament = service.abonament;
this->serviceName=service.serviceName;
}
return *this;
}
static void addServiceToList(const Service& service){
listOfServices.push_back(service);
}
static bool ServiceExists(const Service& service){
auto it = find_if(listOfServices.begin(), listOfServices.end(), [&](const Service &service1){
return service.serviceName==service1.serviceName;
});
return it!=listOfServices.end();
}
static void SchimbaAbonamentul(const Service &service){
for (Service& service1: listOfServices) {
if (service>=service1){
int dif = service - service1;
cout<<"Pentru schimbarea abonamentului trebuie achitata, in plus, suma de: "<<dif<<"$"<<" dupa finalizarea abonamentului activ."<<'\n';
service1.setAbonament(service1.abonament);
}
else if (service<=service1){
int dif=service1 - service;
cout<<"Pentru schimbarea abonamentului, se va plati cu: "<<dif<<"$ mai putin decat abonamentul activ, dupa finalizarea acestuia."<<'\n';
service1.setAbonament(service1.abonament);
}
}
}
static void showAllServices(){
if (listOfServices.empty()){
throw underflow_error("Nu exista servicii active la momentul actual.");
}else {
int index = 1;
for (const Service& service: listOfServices)
{
cout<<index<<" -> "<<service<<'\n';
index++;
}
}
}
static void showServicesById(){
if (listOfServices.empty())
throw invalid_argument("Nu exista servicii active la momentul actual.");
else{
for(const Service& service:listOfServices)
cout<<service.serviceName<<" are ID-ul "<<service.ServiceId<<'\n';
}
}
static void deleteServiceById(int ServiceID){
auto it = listOfServices.begin();
bool found = false;
while(it != listOfServices.end()){
if(it->ServiceId == ServiceID){
it = listOfServices.erase(it);
found = true;
cout<<"Serviciul cu ID-ul " << ServiceID << " a fost sters."<<endl;
}else {++it;}
}
if (!found)
throw out_of_range("Serviciul cu ID-ul introdus nu exista.");
}
void setAbonament(int newAb){
if (newAb==10 || newAb==50 || newAb==100)
abonament=newAb;
else throw invalid_argument("Pretul este invalid. Introduceti un pret din lista de preturi!");
}
void setServiceName(string name){
serviceName=name;
}
int getAbonament()const {
return this->abonament;
}
string getServiceName() const{
return this->serviceName;
}
int getServiceId() const{
return this->ServiceId;
}
};
class Account{
static set<Account> listOfAcc;
const int AccId;
static int nrOfAcc;
string accountName;
string parola;
time_t creationTime;
public:
Account():AccId(++nrOfAcc){
this->accountName="Username";
this->parola="parola1234";
this->creationTime = time(0);
}
Account(const string& accountName, const string& parola):AccId(++nrOfAcc){
this->accountName=accountName;
this->parola=parola;
this->creationTime = time(0);
}
Account(const Account& acc):AccId(++nrOfAcc),creationTime(acc.creationTime){
this->accountName = acc.accountName;
this->parola = acc.parola;
}
~Account()=default;
friend istream& operator>>(istream& in, Account &account){
cout<<"Numele contului este:"<<'\n';
in>>ws;
getline(in,account.accountName);
cout<<"Introdu parola:"<<'\n';
getline(in,account.parola);
return in;
}
friend ostream& operator<<(ostream& out, const Account &acc){
out<<"Numele contului activ este: "<<acc.accountName<<'\n';
out<<"ID-ul contului activ este: "<<acc.AccId<<'\n';
out<<"Data la care contul a fost creat este: "<<ctime(&acc.creationTime)<<'\n';
return out;
}
bool operator==(const Account &acc) const{
return (acc.accountName==this->accountName && acc.parola==this->parola);
}
bool operator>=(Account &acc)const{//In sensul de comparatie al datei de creare al unui cont
return(this->creationTime>=acc.creationTime);
}
bool operator<=(Account &acc)const{
return (this->creationTime<=acc.creationTime);
}
Account &operator=(const Account &acc){
if (this != &acc){
this->accountName=acc.accountName;
this->parola=acc.parola;
creationTime=acc.creationTime;
}
return *this;
}
bool operator<(const Account& other) const {
return (this->creationTime<other.creationTime);
}
Account &operator[](int index){
if (index<0 || index>=static_cast<int>(listOfAcc.size()))
throw out_of_range("Ai introdus un cont care nu exista!");
else{
auto it = listOfAcc.begin();
advance(it,index);
return const_cast<Account&>(*it);
}
}
static void showAllAcc(){
for(auto const& acc : listOfAcc)
cout<<acc<<'\n';
}
static void addAccToList(const Account &acc){
listOfAcc.insert(acc);
}
static bool AccountExists(const Account &acc){
auto it = find_if(listOfAcc.begin(),listOfAcc.end(),[&](auto const& a){
return a.accountName==acc.accountName && a.parola==acc.parola;
}
);
return it != listOfAcc.end();
}
static bool parolaCorecta(const string& parola){
if (parola.empty())
throw invalid_argument("Parola nu poate fi vida!");
auto it = find_if(listOfAcc.begin(), listOfAcc.end(), [&](auto const& a){
return a.parola == parola;
});
return it!=listOfAcc.end();
}
static void showAllAccById(){
for(auto const& acc:listOfAcc){
cout<<acc.accountName<<" are ID-ul "<<acc.AccId<<endl;
}
}
static void deleteAcc(int accId){
auto it = find_if(listOfAcc.begin(), listOfAcc.end(),[&](auto const& a){
return a.AccId == accId; }
);
if (it != listOfAcc.end())
listOfAcc.erase(it);
else
throw out_of_range("ID-ul selectat este unul invalid. Incearca din nou!");
}
int getAccId()const {
return this->AccId;
}
string getAccName()const{
return this->accountName;
}
string getAccPass()const{
return this->parola;
}
time_t getAccDate() const{
return this->creationTime;
}
};
class Previewable {
public:
virtual void playPreview() const = 0;
virtual ~Previewable() {}
};
class Film;
class Serial;
class Documentar;
class Miniseries;
class Program {
protected:
const int ProgrId;
static int generator;
char *title;
char *type;
char *genre;
float rating;
static vector<Program> programsList;
static vector<Film> filmsList;
static vector<Serial> serialsList;
static vector<Documentar> documentarsList;
static vector<Miniseries> miniseriesList;
public:
Program() : ProgrId(++generator), title(nullptr), type(nullptr), genre(nullptr), rating(0.0) {
}
Program(char *title, char *type, char *genre, float rate) : ProgrId(++generator), rating(rate) {
this->title = new char[strlen(title)+1];
strcpy(this->title, title);
this->genre = new char[strlen(genre)+1];
strcpy(this->genre, genre);
this->type = new char[strlen(type)+1];
strcpy(this->type, type);
}
Program(const Program &progr) : ProgrId(++generator), rating(progr.rating) {
this->title = new char[strlen(progr.title)+1];
strcpy(this->title, progr.title);
this->genre = new char[strlen(progr.genre)+1];
strcpy(this->genre, progr.genre);
this->type = new char[strlen(progr.type)+1];
strcpy(this->type, progr.type);
}
virtual ~Program() {
delete[] title;
delete[] type;
delete[] genre;
}
friend istream& operator>>(istream &in, Program &program) {
char dummy[MAX_LENGTH];
cout << "Introdu numele filmului/serialului/documentarului/miniseriei pe care vrei sa-o adaugi:" << '\n';
in.getline(dummy, MAX_LENGTH);
program.setTitle(dummy);
cout << "Introdu tipul acestuia (Serial/Film/Documentar/Miniseries):" << '\n';
in.getline(dummy, MAX_LENGTH);
program.setType(dummy);
cout << "Introdu genul acestuia:" << '\n';
in.getline(dummy, MAX_LENGTH);
program.setGenre(dummy);
cout << "Introdu rating-ul acestuia (0.0-10.0):" << '\n';
in >> program.rating;
in.get();
return in;
}
friend ostream& operator<<(ostream &out, const Program &program) {
out << "Numele " << program.type << "ului este: " << program.title << '\n';
out << "Tipul programului este: " << program.type << '\n';
out << "Genul programului este: " << program.genre << '\n';
out << "Rating-ul programului este: " << program.rating << '\n';
return out;
}
Program& operator=(const Program &p) {
if (this != &p) {
if (this->title != nullptr) {
delete[] title;
}
if (this->genre != nullptr) {
delete[] genre;
}
if (this->type != nullptr) {
delete[] type;
}
this->title = new char[strlen(p.title)+1];
this->genre = new char[strlen(p.genre)+1];
this->type = new char[strlen(p.type)+1];
strcpy(this->title, p.title);
strcpy(this->genre, p.genre);
strcpy(this->type, p.type);
this->rating = p.rating;
}
return *this;
}
bool operator==(const Program &p) const {
return (!strcmp(this->title, p.title) && !strcmp(this->genre, p.genre) && !strcmp(this->type, p.type) && this->rating == p.rating);
}
bool operator>=(const Program &p) const {
return(this->rating >= p.rating);
}
bool operator<=(const Program &p) const {
return (this->rating <= p.rating);
}
friend Program operator+(Program& p, float x) {
if (p.rating+x <= 10.0)
p.rating += x;
return p;
}
Program operator+(float x) {
if (rating+x <= 10.0)
this->rating += x;
return *this;
}
friend Program operator+(float x, Program& p) {
if (p.rating+x <= 10.0)
p.rating += x;
return p;
}
Program& operator+=(float x) {
if (rating+x <= 10.0)
this->rating += x;
return *this;
}
Program& operator-=(float x) {
rating -= x;
if(rating < 0.0)
rating = 0.0;
return *this;
}
Program operator-(Program &p) {
this->rating = this->rating - p.rating;
if (this->rating >= 0.0)
return *this;
else {
this->rating = 0.0;
return *this;
}
}
const int getProgramId() const {
return this->ProgrId;
}
char* getTitle() const {
return this->title;
}
char* getGenre() const {
return this->genre;
}
char* getType() const {
return this->type;
}
float getRating() const {
return this->rating;
}
static int getSizeOfList() {
return programsList.size() + filmsList.size() + serialsList.size() + documentarsList.size()+miniseriesList.size();
}
void setTitle(const char* newTitle) {
if (title) delete[] title;
title = new char[strlen(newTitle)+1];
strcpy(title, newTitle);
}
void setType(const char* newType) {
if (type) delete[] type;
type = new char[strlen(newType)+1];
strcpy(type, newType);
}
void setGenre(const char* newGenre) {
if (genre) delete[] genre;
genre = new char[strlen(newGenre)+1];
strcpy(genre, newGenre);
}
void setRating(float newRating) {
rating = newRating;
}
static void addProgram(const Program& p) {
programsList.push_back(p);
}
static void addFilm(const Film& f);
static void addSerial(const Serial& s);
static void addDocumentar(const Documentar& d);
static void addMiniseries(const Miniseries& m);
static void showAllPrograms();
static void showAllProgramsById();
static bool ProgramExists(const char* name);
static void afiseazaRatingMaiMare(float rate);
static void load(const char* filename);
static void previewAllPrograms();
static Program* findProgramById(int id);
static void showallMiniseries();
};
class Film : public virtual Program, public Previewable {
protected:
float duration;
char* director;
public:
Film(char* title, char* genre, float rating=0.0, char* director="Anonim", float durat=0.0)
: Program(title, "Film", genre, rating), duration(durat) {
this->director = new char[strlen(director)+1];
strcpy(this->director, director);
}
Film() : Program() {
duration = 0.0;
director = new char[strlen("Anonim")+1];
strcpy(director, "Anonim");
if(!getType()) {
setType("Film");
}
}
Film(const Film &other) : Program(other), duration(other.duration) {
this->director = new char[strlen(other.director)+1];
strcpy(this->director, other.director);
}
Film& operator=(const Film &other) {
if (this != &other) {
Program::operator=(other);
duration = other.duration;
if (director) {
delete[] director;
}
director = new char[strlen(other.director)+1];
strcpy(director, other.director);
}
return *this;
}
virtual ~Film() {
delete[] director;
}
friend istream &operator>>(istream &in, Film &f) {
char dummy[MAX_LENGTH];
float rating, dur;
cout << "Numele filmului este: " << endl;
in.getline(dummy, MAX_LENGTH);
if (f.title) delete[] f.title;
f.title = new char[strlen(dummy) + 1];
strcpy(f.title, dummy);
cout << "Genul filmului este: " << endl;
in.getline(dummy, MAX_LENGTH);
if (f.genre) delete[] f.genre;
f.genre = new char[strlen(dummy)+1];
strcpy(f.genre, dummy);
if (f.type) delete[] f.type;
f.type = new char[strlen("Film")+1];
strcpy(f.type, "Film");
cout << "Rating-ul filmului este de(0.0-10.0): " << endl;
in >> rating;
f.rating = rating;
in.get();
cout << "Introdu durata filmului(minute): " << endl;
in >> dur;
f.duration = dur;
in.get();
cout << "Directorul filmului este: " << endl;
in.getline(dummy, MAX_LENGTH);
if (f.director) delete[] f.director;
f.director = new char[strlen(dummy)+1];
strcpy(f.director, dummy);
return in;
}
friend ostream& operator<<(ostream &out, const Film &f) {
out << static_cast<const Program&>(f);
out << "Durata filmului este de: " << f.duration << " minute." << endl;
out << "Directorul filmului este: " << f.director << "." << endl;
return out;
}
virtual void playPreview() const override {
cout << "Preview pentru filmul " << getTitle() << " regizat de catre " << director << "." << endl;
cout << "Durata filmului este de " << duration << " minute." << endl;
}
float getDuration() const {
return duration;
}
char* getDirector() const {
return director;
}
};
class Serial : public virtual Program, public virtual Previewable {
protected:
int seasons, nrEpisodes;
public:
Serial(char* title, char* genre, float rating=0.0, int nrSeason=0, int nrEp=0): Program(title, "Serial", genre, rating), seasons(nrSeason), nrEpisodes(nrEp) {}
Serial() : Program() {
seasons = 0;
nrEpisodes = 0;
if (!getType())
setType("Serial");
}
Serial(const Serial &other) : Program(other), seasons(other.seasons), nrEpisodes(other.nrEpisodes) {}
virtual ~Serial() {}
Serial& operator=(const Serial &s) {
if (this != &s) {
Program::operator=(s);
this->nrEpisodes = s.nrEpisodes;
this->seasons = s.seasons;
}
return *this;
}
virtual void playPreview() const override {
cout << "Preview pentru serialul " << getTitle() << "." << endl;
cout << "Numarul de sezoane este de " << seasons << ", iar numarul de episoade este de " << nrEpisodes << "." << endl;
}
friend istream &operator>>(istream &in, Serial &s) {
float rating;
int nrs, nre;
char dummy[MAX_LENGTH];
cout<<"Numele serialului este: " << endl;
in.getline(dummy, MAX_LENGTH);
if (s.title)
delete[] s.title;
s.title = new char[strlen(dummy) + 1];
strcpy(s.title, dummy);
cout<<"Genul serialului este: " << endl;
in.getline(dummy, MAX_LENGTH);
if (s.genre)
delete[] s.genre;
s.genre = new char[strlen(dummy)+1];
strcpy(s.genre, dummy);
if (s.type)
delete[] s.type;
s.type = new char[strlen("Serial")+1];
strcpy(s.type, "Serial");
cout<<"Rating-ul serialului este de(0.0-10.0): " << endl;
in>>rating;
s.rating = rating;
in.get();
cout<<"Numarul de sezoane este de:" << endl;
in>>nrs;
s.seasons = nrs;
in.get();
cout<<"Numarul total de episoade este de:" << endl;
in>>nre;
s.nrEpisodes = nre;
in.get();
return in;
}
friend ostream &operator<<(ostream &out, const Serial &s) {
out<<static_cast<const Program&>(s) << endl;
out<<"Numarul de sezoane este de: " << s.seasons << ", iar de episoade este de: " << s.nrEpisodes << "." << endl;
return out;
}
int getSeasons() const {
return seasons;
}
int getEpisodes() const {
return nrEpisodes;
}
};
class Documentar : public Serial, public Film {
protected:
int nrEpisod;
float durata;
public:
Documentar(char* title, char* genre, float rating, int nrEpisod, float durata)
: Program(title, "Documentar", genre, rating),
Film(),
Serial(),
nrEpisod(nrEpisod), durata(durata) { }
Documentar() : Program(), Film(), Serial(), nrEpisod(0), durata(0.0f) {
if (type) { delete[] type; }
type = new char[strlen("Documentar") + 1];
strcpy(type, "Documentar");
}
Documentar(const Documentar &other)
: Program(other), Film(other), Serial(other), nrEpisod(other.nrEpisod), durata(other.durata) {}
Documentar& operator=(const Documentar &other) {
if (this != &other) {
Program::operator=(other);
if (director) {
delete[] director;
}
director = new char[strlen(other.director)+1];
strcpy(director, other.director);
duration = other.duration;
seasons = other.seasons;
nrEpisodes = other.nrEpisodes;
nrEpisod = other.nrEpisod;
durata = other.durata;
}
return *this;
}
virtual ~Documentar() { }
virtual void playPreview() const override {
cout << "Preview pentru documentarul: " << getTitle() << endl;
if (nrEpisod > 1) {
cout << "Acest documentar este impartit in: " << nrEpisod << " episoade. ";
cout << "Acesta are o durata de " << durata << " minute." << endl;
} else {
cout << "Acesta este un documentar autonom cu durata de: " << durata << " minute." << endl;
}
}
friend istream &operator>>(istream &in, Documentar &d) {
float rating;
int nrs, nre;
char dummy[MAX_LENGTH];
cout << "Numele documentarului este: " << endl;
in.getline(dummy, MAX_LENGTH);
if (d.title) delete[] d.title;
d.title = new char[strlen(dummy) + 1];
strcpy(d.title, dummy);
cout << "Genul documentarului este: " << endl;
in.getline(dummy, MAX_LENGTH);
if (d.genre) delete[] d.genre;
d.genre = new char[strlen(dummy)+1];
strcpy(d.genre, dummy);
if (d.type) delete[] d.type;
d.type = new char[strlen("Documentar")+1];
strcpy(d.type, "Documentar");
cout << "Rating-ul documentarului este de(0.0-10.0): " << endl;
in >> rating;
d.rating = rating;
in.get();
cout << "Numarul de episoade este de:" << endl;
in >> nrs;
d.nrEpisod = nrs;
in.get();
cout << "Durata totala este de(minute):" << endl;
in >> nre;
d.durata = nre;
in.get();
return in;
}
friend ostream &operator<<(ostream &out, const Documentar &d) {
out << static_cast<const Program&>(d) << endl;
out << "Numarul de episoade este de: " << d.nrEpisod << ", cu o durata totala de: " << d.durata << " minute." << endl;
return out;
}
int getNrEpisod() const {
return nrEpisod;
}
float getDurata() const {
return durata;
}
};
class Miniseries : public Film {
protected:
int nrEpisodes;
float episodeDuration;
public:
Miniseries(char* title, char* genre, float rating = 0.0, char* director = "Anonim",
int episodes = 1, float epDuration = 0.0)
: Program(title, "Miniseries", genre, rating),
Film(title,genre,rating,director,epDuration*episodes),
nrEpisodes(episodes), episodeDuration(epDuration) {
if (type) delete[] type;
type = new char[strlen("Miniseries") + 1];
strcpy(type, "Miniseries");
}
Miniseries() :Program(), Film(), nrEpisodes(1), episodeDuration(0.0) {
if (type) delete[] type;
type = new char[strlen("Miniseries") + 1];
strcpy(type, "Miniseries");
}
Miniseries(const Miniseries& other)
: Program(other), Film(other), nrEpisodes(other.nrEpisodes), episodeDuration(other.episodeDuration) {}
Miniseries& operator=(const Miniseries& other) {
if (this != &other) {
Film::operator=(other);
nrEpisodes = other.nrEpisodes;
episodeDuration = other.episodeDuration;
}
return *this;
}
virtual ~Miniseries() {}
virtual void playPreview() const override {
cout << "Preview pentru miniseria " << getTitle() << " regizata de catre " << director << "." << endl;
cout << "Aceasta contine " << nrEpisodes << " episoade, fiecare cu durata de "
<< episodeDuration << " minute." << endl;
cout << "Durata totala este de " << duration << " minute." << endl;
}
friend istream& operator>>(istream& in, Miniseries& m) {
char dummy[MAX_LENGTH];
float rating, epDur;
int episodes;
cout << "Numele miniseriei este: " << endl;
in.getline(dummy, MAX_LENGTH);
if (m.title) delete[] m.title;
m.title = new char[strlen(dummy) + 1];
strcpy(m.title, dummy);
cout << "Genul miniseriei este: " << endl;
in.getline(dummy, MAX_LENGTH);
if (m.genre) delete[] m.genre;
m.genre = new char[strlen(dummy) + 1];
strcpy(m.genre, dummy);
if (m.type) delete[] m.type;
m.type = new char[strlen("Miniseries") + 1];
strcpy(m.type, "Miniseries");
cout << "Rating-ul miniseriei este de(0.0-10.0): " << endl;
in >> rating;
m.rating = rating;
in.get();
cout << "Numarul de episoade este: " << endl;
in >> episodes;
m.nrEpisodes = episodes;
in.get();
cout << "Durata unui episod(minute): " << endl;
in >> epDur;
m.episodeDuration = epDur;
m.duration = episodes * epDur;
in.get();
cout << "Directorul miniseriei este: " << endl;
in.getline(dummy, MAX_LENGTH);
if (m.director) delete[] m.director;
m.director = new char[strlen(dummy) + 1];
strcpy(m.director, dummy);
return in;
}
friend ostream& operator<<(ostream& out, const Miniseries& m) {
out << static_cast<const Program&>(m);
out << "Numarul de episoade: " << m.nrEpisodes << endl;
out << "Durata per episod: " << m.episodeDuration << " minute." << endl;
out << "Durata totala: " << m.duration << " minute." << endl;
out << "Directorul miniseriei este: " << m.getDirector() << "." << endl;
return out;
}
int getNrEpisodes() const {
return nrEpisodes;
}
float getEpisodeDuration() const {
return episodeDuration;
}
void setNrEpisodes(int episodes) {
nrEpisodes = episodes;
duration = episodes * episodeDuration;
}
void setEpisodeDuration(float epDuration) {
episodeDuration = epDuration;
duration = nrEpisodes * epDuration;
}
};
void Program::addFilm(const Film& f) {
filmsList.push_back(f);
}
void Program::addSerial(const Serial& s) {
serialsList.push_back(s);
}
void Program::addDocumentar(const Documentar& d) {
documentarsList.push_back(d);
}
void Program::addMiniseries(const Miniseries& m){
miniseriesList.push_back(m);
}
void Program::showAllPrograms() {
for (auto& p : programsList) {
cout << p << "\n";
}
for (auto& f : filmsList) {
cout << f << "\n";
}
for (auto& s : serialsList) {
cout << s << "\n";
}
for (auto& d : documentarsList) {
cout << d << "\n";
}
for (auto& m:miniseriesList){
cout<<m<<"\n";
}
}
void Program::showAllProgramsById() {
for (auto& p : programsList) {
cout << p.type << "ul cu numele " << p.title<< " are ID-ul " << p.ProgrId << "\n";
}
for (auto& f : filmsList) {
cout << f.getType() << "ul cu numele " << f.getTitle()<< " are ID-ul " << f.getProgramId() << "\n";
}
for (auto& s : serialsList) {
cout << s.getType() << "ul cu numele " << s.getTitle()<< " are ID-ul " << s.getProgramId() << "\n";
}
for (auto& d : documentarsList) {
cout << d.getType() << "ul cu numele " << d.getTitle()<< " are ID-ul " << d.getProgramId() << "\n";
}
for (auto& m : miniseriesList) {
cout << m.getType() << "ul cu numele " << m.getTitle()<< " are ID-ul " << m.getProgramId() << "\n";
}
}
Program* Program::findProgramById(int id) {
for (auto &p : programsList) {
if (p.getProgramId() == id)
return &p;
}
for (auto &f : filmsList) {
if (f.getProgramId() == id)
return &f;
}
for (auto &s : serialsList) {
if (s.getProgramId() == id)
return &s;
}
for (auto &d : documentarsList) {
if (d.getProgramId() == id)
return &d;
}
for (auto &m : miniseriesList) {
if (m.getProgramId() == id)
return &m;
}
return nullptr;
}
bool Program::ProgramExists(const char* name) {
for (auto& p : programsList) {
if (!strcmp(p.title, name))
return true;
}
for (auto& f : filmsList) {
if (!strcmp(f.getTitle(), name))
return true;
}
for (auto& s : serialsList) {
if (!strcmp(s.getTitle(), name))
return true;
}
for (auto& d : documentarsList) {
if (!strcmp(d.getTitle(), name))
return true;
}
for (auto& m : miniseriesList) {
if (!strcmp(m.getTitle(), name))