From 91f72e9ace40960243ce3e66585a28fe6b406aef Mon Sep 17 00:00:00 2001 From: maryam Date: Fri, 12 Apr 2024 14:27:19 +0330 Subject: [PATCH 1/5] testing --- 1/1.cpp | 122 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 99 insertions(+), 23 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index b83dbef..22792d3 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -2,16 +2,38 @@ #include #include #include +#include using namespace std; class Person { public: - + Person(const string& name) { this->name = name; + } + Person(){}; + Person(const string n, const int a){ + this->name = n; + this->age = a; } string& getName() { return name; } + bool operator <(const Person p) + { + if ( name < p.name) + return true; + else + return false; + } + bool operator ==(const Person p) + { + if (age == p.age) + return true; + else + return false; + } + friend class Group; + friend ostream& operator<<(ostream& out, const Person& p); private: string name; @@ -19,16 +41,23 @@ class Person { }; -ostream& operator<<(ostream& out, const Person& p) { - cout << p.getName(); +ostream& operator<<(ostream& out, Person& p) { + cout << p.getName() ; return out; } - class Group { public: - + Group(){}; + Group(Group& g){ + cap = g.cap; + size = g.size; + this->members = new Person[g.cap]; + for(int i=0; i < size; i++){ + members[i] = g.members[i]; + } + } Group(int max_lenght) { this->cap = max_lenght; this->members = new Person[max_lenght]; @@ -46,17 +75,62 @@ class Group { for (i = 0; i < size; i++) { if(members[i].name == name) break; - + } for (int index = i; index < size - 1; index++) { members[index] = members[index + 1]; } size--; } + Group& operator=(const Group g){ + this->cap = g.cap; + this->size = g.size; + this->members = new Person[g.cap]; + for (int i = 0; i < size; i++) { + this->members[i] = g.members[i]; + } + return *this; + } + + Group operator+(const Group g){ + Group outPut(cap + g.cap); + int i = 0, j =0; + for (; i < size; i++){ + outPut.members[i] = members[i]; + } + for(; j < g.size; j++){ + outPut.members[i] = g.members[j]; + i++; + } + return outPut; + } + Group& operator+=(Group g){ + Person* tmp = new Person[g.cap + cap]; + int i = 0, j =0; + for (; i < size; i++) { + + tmp[i] = members[i]; + + } + for (; j < g.size; j++) { + + tmp[i] = members[j]; + i++; + + } + members = tmp; + cap += g.cap; + size += g.size; + + return *this; + } ~Group() { delete[] members; } + friend bool isGroupFull(Group g); + friend ostream& operator<<(ostream& out, const Group& g); + friend class Person; private: int size; @@ -68,36 +142,39 @@ class Group { bool isGroupFull(Group g) { return (g.size == g.cap); } +ostream& operator<<(ostream& out, const Group& g) { + for (int i = 0; i < g.size; i++) + out << g.members[i] << "\t"; + return out; +} int main() { - /* + Person p1("somename"); - Person p1("somename2"); - cout << p1< Date: Fri, 12 Apr 2024 14:31:57 +0330 Subject: [PATCH 2/5] all the bugs are fixed --- 1/1.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index 22792d3..6a1b934 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -110,18 +110,15 @@ class Group { for (; i < size; i++) { tmp[i] = members[i]; - } for (; j < g.size; j++) { tmp[i] = members[j]; i++; - } members = tmp; cap += g.cap; size += g.size; - return *this; } From 7e1465af451bd7669713d22b6c93d05fdd6f829e Mon Sep 17 00:00:00 2001 From: maryam Date: Fri, 12 Apr 2024 15:40:40 +0330 Subject: [PATCH 3/5] fix bugs --- 2/Score.cpp | 28 +++++++++++++++++++++++++++- 2/Score.h | 9 +++++++-- 2/main.cpp | 6 ++---- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/2/Score.cpp b/2/Score.cpp index c107032..14b34ef 100644 --- a/2/Score.cpp +++ b/2/Score.cpp @@ -1,12 +1,38 @@ #include "Score.h" +int Score::ID_generator = 0; Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) { this->score = score; this->label = label; this->detail = detail; - ID_generator++; } +Score::Score(int s, string d, Label l):ID(ID_generator) { + this->score = s; + this->detail = d; + this->label = l; + ID_generator ++; + + } +Score::Score():ID(ID_generator) { + score = 0; + detail = ""; + label = NOTBAD; + ID_generator++; + } +Score& Score::operator= (const Score& s) { + score = s.score; + detail = s.detail; + label = s.label; + return *this; + } +void print(const Score& s) { + cout << "Score: " << s.score << endl << "Detail: " << s.detail << endl << "Lable: " << s.label << endl << "ID: " << s.ID << endl; +} +void setID_generator(int id) { + Score::ID_generator = id; + return ; +} diff --git a/2/Score.h b/2/Score.h index 0dd79cb..fb730d4 100644 --- a/2/Score.h +++ b/2/Score.h @@ -4,7 +4,6 @@ using namespace std; class Score { public: friend void print(const Score& score); - typedef enum { GREAT, GOOD, @@ -13,6 +12,11 @@ class Score { }Label; Score(int score, char* detail, Label label); + Score(); + Score(int s, string d, Label l); + Score& operator= (const Score& S); + friend void setID_generator(int id); + friend int main(); private: int score; Label label; @@ -20,6 +24,7 @@ class Score { const int ID; static int ID_generator; }; - +void setID_generator(int id); +void print(const Score& s); diff --git a/2/main.cpp b/2/main.cpp index 64d213e..b5876c4 100644 --- a/2/main.cpp +++ b/2/main.cpp @@ -9,11 +9,9 @@ using namespace std; #define FOR(n) for(int i=0;i Date: Fri, 12 Apr 2024 15:48:25 +0330 Subject: [PATCH 4/5] fix problems --- 2/Score.cpp | 21 ++++++++++++--------- 2/Score.o | Bin 0 -> 4384 bytes 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 2/Score.o diff --git a/2/Score.cpp b/2/Score.cpp index 14b34ef..4c3763a 100644 --- a/2/Score.cpp +++ b/2/Score.cpp @@ -8,27 +8,30 @@ Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) { ID_generator++; } +Score::Score():ID(ID_generator) { + label = GOOD; + score = 0; + detail = " "; + ID_generator++; +} Score::Score(int s, string d, Label l):ID(ID_generator) { this->score = s; this->detail = d; this->label = l; ID_generator ++; - } -Score::Score():ID(ID_generator) { - score = 0; - detail = ""; - label = NOTBAD; - ID_generator++; - } +} Score& Score::operator= (const Score& s) { score = s.score; detail = s.detail; label = s.label; return *this; - } +} void print(const Score& s) { - cout << "Score: " << s.score << endl << "Detail: " << s.detail << endl << "Lable: " << s.label << endl << "ID: " << s.ID << endl; + cout << "Score: " << s.score << endl; + cout << "Detail: " << s.detail << endl; + cout << "Lable: " << s.label << endl; + cout << "ID: " << s.ID << endl; } void setID_generator(int id) { Score::ID_generator = id; diff --git a/2/Score.o b/2/Score.o new file mode 100644 index 0000000000000000000000000000000000000000..2224915871d9f32a8c26bd500e027c4514df5d84 GIT binary patch literal 4384 zcmb_eUuauZ7(cg3y3P#={#&OTyX*d#>CBR@-MZmJSR1{i-3+-cvbu4WCU;$Cnv~>r z>xRg*FucTIK_@bN5D_1Ik)hy&3UjUOMIQtaA4Fj&hz|6@m%TWD-}!ECZko2(vIF;= z-}!xi&UeoDoqKQY@_Iq-qYfcr3I#>fwq|UFxzhteyrc>7Yl!Ehr;F67Xf9)Ce0od4 zgh*YFj#nyvS=c{u@g>rmX?A!CvUh_*EUaTCgdq|lmWWO@>lxs;Ahuhs-UD^La7W*LO(G>mBKR554ym>5ZDk z?CpqAE9}$_=cw+CMuweaY`{6%XH=8AF?+qkaK8GTyi^~io>(Upp`kh&al#DxoK#Th z*NhH~F~hmRHfjg6*EL6hKerjqywdaeHJl&oOUxOw3y~L2&d)81YOzU6C^r*9+BoUm zq$m|q!PhwI`X260JZm~7W6{}Au+>pIx$0V@GMwL#JxW~Ia7H`fv9n4U39Gzx8nqN< zBka$j(ox9@bIu@L&`-{f`hC?xZFGjt4TD3g=LaMCs|q*0YOaE>C)}uo?pw)}L*e3B z()z)btgDION-ICMvTbBpTdF(v3~-cmeri*5sKm`1g1a^Z+K;rwv=rQnyLYwq$3rFY zn$}KJv6S2l<;ANj$e;7sYaM}5M|Utl-kWf+EyS!4SJX>r>^@Su1Pr(c}B0@o3Cvv;y1>*)BXmu^0U&g~remA5@Vu zm-nPE13j*!4*G~f*U+<<&w$wC7SL8D{R2Jw``eS=@zDL)Ap6@4#QuhX*k2lm{hb5a zqx@a=xHmlX0T6rn7>K>x24ag%IDL*~J5ZPMvIpo1g$@BdsZc-A4uyt*=tP1d4aBx5 zfVvcy17h3rKu;;|6(F{CfY^2ph;6R|bt%2~f!OvFAYS)NAh!J)h;6?CV%r~px|HqD zKy3RL5Zm4XVp}axx9tStQ`-o;op=JuE2CkL0}ynx1K4LBbpUNv9NDro?4gG|X{X0+ z@sRFGX(hI$Tri@2v1cky=IHavsLzu=?QsbY4R}%j5ygY#qU}>CdOBaQ)Le*v?+P)Y zsaqAzPEENi4`p|z30<_YgC;pmUia%L{2_X}lJ9B#+hV8+07 zd5r&G55`!F-ddEqM)UvYQG5YXT-5ykc(igrqiSnz{{K6Y2DD4mH!1o5?Ltb&Ku>>k zjTZI&*QtGJI~qbCs!_0L>+l3Lx=F3=9ao26?28btZB#N*)y54w9A>iT^YwUiOqvJelAf}q zXY51A5S_f8=cJ3YkvU;c>PgxrHH$gy~D#j*znCM@K(Bq_%gnXky{VkJLOv~q)IlPWc Date: Fri, 12 Apr 2024 15:50:06 +0330 Subject: [PATCH 5/5] Delete 2/Score.o --- 2/Score.o | Bin 4384 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 2/Score.o diff --git a/2/Score.o b/2/Score.o deleted file mode 100644 index 2224915871d9f32a8c26bd500e027c4514df5d84..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4384 zcmb_eUuauZ7(cg3y3P#={#&OTyX*d#>CBR@-MZmJSR1{i-3+-cvbu4WCU;$Cnv~>r z>xRg*FucTIK_@bN5D_1Ik)hy&3UjUOMIQtaA4Fj&hz|6@m%TWD-}!ECZko2(vIF;= z-}!xi&UeoDoqKQY@_Iq-qYfcr3I#>fwq|UFxzhteyrc>7Yl!Ehr;F67Xf9)Ce0od4 zgh*YFj#nyvS=c{u@g>rmX?A!CvUh_*EUaTCgdq|lmWWO@>lxs;Ahuhs-UD^La7W*LO(G>mBKR554ym>5ZDk z?CpqAE9}$_=cw+CMuweaY`{6%XH=8AF?+qkaK8GTyi^~io>(Upp`kh&al#DxoK#Th z*NhH~F~hmRHfjg6*EL6hKerjqywdaeHJl&oOUxOw3y~L2&d)81YOzU6C^r*9+BoUm zq$m|q!PhwI`X260JZm~7W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