From 19cb1bf3910d198e01193f17f97969edc38d21ce Mon Sep 17 00:00:00 2001 From: zahra2823 Date: Sat, 6 Apr 2024 17:03:41 +0330 Subject: [PATCH 1/4] update file 1.cpp zahra karimian --- 1/1.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index b83dbef..8fc307f 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace std; class Person { @@ -11,7 +12,10 @@ class Person { this->name = name; } + Person() {} + string& getName() { return name; } + string getName ()const { return name; } private: string name; @@ -26,6 +30,7 @@ ostream& operator<<(ostream& out, const Person& p) { + class Group { public: @@ -41,10 +46,10 @@ class Group { this->members[size] = p; this->size++; } - void deletePerson(string name) { + void deletePerson(const string &name) { int i; for (i = 0; i < size; i++) { - if(members[i].name == name) + if(members[i].getName() == name) break; } @@ -57,6 +62,8 @@ class Group { ~Group() { delete[] members; } + + friend bool isGroupFull(const Group& g); private: int size; @@ -65,7 +72,7 @@ class Group { }; -bool isGroupFull(Group g) { +bool isGroupFull(const Group& g) { return (g.size == g.cap); } From 7370dd1b24abf4f75225f76c87a17b9fb97d1a9f Mon Sep 17 00:00:00 2001 From: zahra2823 Date: Fri, 12 Apr 2024 12:37:05 +0330 Subject: [PATCH 2/4] Fix code problems in the main function --- 1/1.cpp | 68 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index 8fc307f..6d32dd9 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -11,20 +11,25 @@ class Person { Person(const string& name) { this->name = name; + } + Person(const string& name , int g) { + this->name = name; + this->age; + } Person() {} string& getName() { return name; } string getName ()const { return name; } - private: string name; int age; + }; ostream& operator<<(ostream& out, const Person& p) { - cout << p.getName(); + out << p.getName(); return out; } @@ -64,7 +69,14 @@ class Group { } friend bool isGroupFull(const Group& g); - + friend ostream& operator<<(ostream& out, const Group G); + friend Group operator+(const Group& G1, const Group& G2); + Group& operator+=( const Group& G2) { + for (int i = 0; i < size && i < G2.size; i++) { + members[i] += G2.members[i]; + } + return *this; +} private: int size; int cap; @@ -75,36 +87,54 @@ class Group { bool isGroupFull(const Group& g) { return (g.size == g.cap); } +ostream& operator<<(ostream& out, const Group G) { + for(int i=0 ; i Date: Fri, 12 Apr 2024 19:31:22 +0330 Subject: [PATCH 3/4] Last edit --- 1/1.cpp | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index 6d32dd9..d273f41 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -21,6 +21,20 @@ class Person { string& getName() { return name; } string getName ()const { return name; } + Person operator+(const Person& other) const { + string newName = this->name + " " + other.name; + int newAge = this->age + other.age; + return Person(newName, newAge); + } + Person& operator+=(const Person& other) { + this->name += other.name; + this->age += other.age; + return *this; +} + + + + private: string name; int age; @@ -70,13 +84,17 @@ class Group { friend bool isGroupFull(const Group& g); friend ostream& operator<<(ostream& out, const Group G); - friend Group operator+(const Group& G1, const Group& G2); - Group& operator+=( const Group& G2) { - for (int i = 0; i < size && i < G2.size; i++) { - members[i] += G2.members[i]; - } - return *this; -} + friend class person; + Group operator+ (const Group& other) const { + for(int i=0 ; size>i && other.size>i ; i++ ){ + members[i].operator+(other.members[i]); + } + } + Group& operator+=(const Group& other){ + for(int i=0 ; size>i && other.size>i ; i++ ){ + members[i].operator+=(other.members[i]); + } + } private: int size; int cap; @@ -93,17 +111,6 @@ ostream& operator<<(ostream& out, const Group G) { } return out; } -Group operator+(const Group& G1, const Group& G2) { - Group result(G1.cap + G2.cap); - - for (int i = 0; i < G1.size && i < G2.size; i++) { - result.members[i] = G1.members[i] + G2.members[i]; - } - - result.size = min(G1.size, G2.size); - - return result; -} int main() { From ef72dc9841e9a8282203a287eae09b714deb3a67 Mon Sep 17 00:00:00 2001 From: zahra2823 Date: Fri, 12 Apr 2024 19:52:10 +0330 Subject: [PATCH 4/4] first edit --- 2/Score.cpp | 6 ++++++ 2/Score.h | 1 + 2/main.cpp | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/2/Score.cpp b/2/Score.cpp index c107032..3f5cf69 100644 --- a/2/Score.cpp +++ b/2/Score.cpp @@ -8,5 +8,11 @@ Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) { ID_generator++; } +Score::Score(){ + this->score = -0; + + this->detail = ""; + ID_generator=0; +} diff --git a/2/Score.h b/2/Score.h index 0dd79cb..03aa753 100644 --- a/2/Score.h +++ b/2/Score.h @@ -13,6 +13,7 @@ class Score { }Label; Score(int score, char* detail, Label label); + Score(); private: int score; Label label; diff --git a/2/main.cpp b/2/main.cpp index 64d213e..1d26ed9 100644 --- a/2/main.cpp +++ b/2/main.cpp @@ -13,14 +13,14 @@ scores[i] = Score( score,("some string " + to_string(i)).c_str(),Score::Label(3- int main() { - + int i; srand(time(NULL)); Score s1(1, "do better next time", Score::BAD); Score scores[10];//we have default constructor so we should be fine right?:) FOR(10) { - SETSCORE(i) + SETSCORE(i); //why = betwean two scores raises an error?:) } FOR(10) {