From 86490d0d118768e7b436267382431b41fff82e81 Mon Sep 17 00:00:00 2001 From: Morteza0Nazarzade <165780917+Morteza0Nazarzade@users.noreply.github.com> Date: Wed, 10 Apr 2024 18:17:46 +0330 Subject: [PATCH 01/10] fixed the classes and methods for <1.cpp> --- 1/1.cpp | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index b83dbef..763327c 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -6,13 +5,15 @@ using namespace std; class Person { public: - + Person(const string& name) { this->name = name; } - string& getName() { return name; } - + Person() {} + string& getName() { return name; } + const string& getName()const { return name; } + friend class Group; private: string name; int age; @@ -25,11 +26,10 @@ ostream& operator<<(ostream& out, const Person& p) { } - class Group { public: - Group(int max_lenght) { + Group(int max_lenght) { this->cap = max_lenght; this->members = new Person[max_lenght]; this->size = 0; @@ -44,16 +44,16 @@ class Group { void deletePerson(string name) { int i; for (i = 0; i < size; i++) { - if(members[i].name == name) + if (members[i].name == name) break; - + } for (int index = i; index < size - 1; index++) { members[index] = members[index + 1]; } size--; } - + friend bool isGroupFull(Group g); ~Group() { delete[] members; } @@ -71,11 +71,12 @@ bool isGroupFull(Group g) { int main() { - /* + Person p1("somename"); - Person p1("somename2"); - cout << p1< to to pervent redefinition + Person p2("somename2"); + cout << p1 << p2; + /* Group g1(5); g1.add({ "Erfan",20 }); @@ -112,14 +113,7 @@ int main() /* cout<<*find(persons,persons+10,Erfan); */ - - - - - - } - From 925a91996c407c8cc7bbce15883d33b5afd904e5 Mon Sep 17 00:00:00 2001 From: Morteza0Nazarzade <165780917+Morteza0Nazarzade@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:16:50 +0330 Subject: [PATCH 02/10] second part main fixed --- 1/1.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index 763327c..b6632f5 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -10,6 +10,7 @@ class Person { this->name = name; } + Person(const string n, const int a) { name = n; age = a; } Person() {} string& getName() { return name; } const string& getName()const { return name; } @@ -34,6 +35,14 @@ class Group { this->members = new Person[max_lenght]; this->size = 0; } + Group(const Group& g) + { + this->cap = g.cap; + this->size = g.size; + this->members = new Person[this->size]; + for (int i = 0; i < g.size; i++) + this->members[i] = g.members[i]; + } void add(Person p) { if (this->size == this->cap) { return; @@ -77,14 +86,14 @@ int main() Person p2("somename2"); cout << p1 << p2; - /* + Group g1(5); g1.add({ "Erfan",20 }); g1.add({ "Saba",20 }); g1.add({ "Mahrokh",20 }); g1.add({ "Yasin",21 }); - cout< Date: Thu, 11 Apr 2024 12:30:19 +0330 Subject: [PATCH 03/10] third part of main fixed --- 1/1.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index b6632f5..4a15140 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -63,6 +63,7 @@ class Group { size--; } friend bool isGroupFull(Group g); + friend ostream& operator<<(ostream& out, const Group& g); ~Group() { delete[] members; } @@ -78,6 +79,13 @@ 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() { @@ -94,13 +102,13 @@ int main() g1.add({ "Yasin",21 }); cout << isGroupFull(g1) << endl; - /* + Group g2(g1); Group g3(10); g2.deletePerson("Erfan"); - cout << g1< Date: Thu, 11 Apr 2024 15:00:31 +0330 Subject: [PATCH 04/10] forth part of main fixed --- 1/1.cpp | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index 4a15140..9c7097f 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -39,7 +39,7 @@ class Group { { this->cap = g.cap; this->size = g.size; - this->members = new Person[this->size]; + this->members = new Person[this->cap]; for (int i = 0; i < g.size; i++) this->members[i] = g.members[i]; } @@ -62,6 +62,39 @@ class Group { } size--; } + Group operator +(const Group g) + { + Group result(this->cap + g.cap); + result.size = this->size + g.size; + for (int i = 0; i < this->size; i++) + result.members[i] = this->members[i]; + for (int i = 0; i < g.size; i++) + result.members[i + this->size] = g.members[i]; + return result; + } + Group operator +=(const Group g) + { + Group temp = *this; + this->cap += g.cap; + this->size += g.size; + delete[] this->members; + this->members = new Person[this->cap]; + for (int i = 0; i < temp.size; i++) + this->members[i] = temp.members[i]; + for (int i = 0; i < g.size; i++) + this->members[i + temp.size] = g.members[i]; + return *this; + } + Group operator =(const Group g) + { + this->cap = g.cap; + this->size = g.size; + delete[] this->members; + this->members = new Person[this->cap]; + for (int i = 0; i < this->size; i++) + this->members[i] = g.members[i]; + return *this; + } friend bool isGroupFull(Group g); friend ostream& operator<<(ostream& out, const Group& g); ~Group() { @@ -109,12 +142,12 @@ int main() cout << g1 << endl;//should cout every person in it with a \t as the separator cout << g2 << endl; - /* + g3 = g1; cout << g3; - g3 = g2 + g3;//adds members of g2 and g3 to each other + g3 = g2 + g3;//adds members of g2 and g3 to each other g3 += g3 += g3 += g3; - */ + /* Person persons[10]; Person Erfan("Erfan",20); From 284f35a257aaf2633b74cc99e0ddb77a7ab0ae64 Mon Sep 17 00:00:00 2001 From: Morteza0Nazarzade <165780917+Morteza0Nazarzade@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:16:11 +0330 Subject: [PATCH 05/10] fifth part of main fixed --- 1/1.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index 9c7097f..2653a52 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -148,18 +148,18 @@ int main() g3 = g2 + g3;//adds members of g2 and g3 to each other g3 += g3 += g3 += g3; - /* - Person persons[10]; - Person Erfan("Erfan",20); - persons[1]=Erfan; - for(int i=0;i<10;i++){ - persons[i].getName()=to_string(rand()%100); - } - sort(persons,persons+10);//what operator should be overloaded for sort? :) - - for(int i=0;i<10;i++){ - cout< Date: Thu, 11 Apr 2024 15:49:29 +0330 Subject: [PATCH 06/10] main is now compeletly fixed --- 1/1.cpp | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index 2653a52..380492d 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -1,6 +1,7 @@ #include #include #include +#include using namespace std; class Person { @@ -14,6 +15,20 @@ class Person { Person() {} string& getName() { return name; } const string& getName()const { return name; } + bool operator <(const Person p) + { + if (this->name < p.name) + return true; + else + return false; + } + bool operator ==(const Person p) + { + if (this->age == p.age) + return true; + else + return false; + } friend class Group; private: string name; @@ -148,21 +163,21 @@ int main() g3 = g2 + g3;//adds members of g2 and g3 to each other g3 += g3 += g3 += g3; - - //Person persons[10]; - //Person Erfan("Erfan",20); - //persons[1]=Erfan; - //for(int i=0;i<10;i++){ - // persons[i].getName()=to_string(rand()%100); - //} - //sort(persons,persons+10);//what operator should be overloaded for sort? :) - - //for(int i=0;i<10;i++){ - // cout< Date: Thu, 11 Apr 2024 16:23:27 +0330 Subject: [PATCH 07/10] pragma once and constructors added --- 2/Score.cpp | 14 ++++++++++++++ 2/Score.h | 3 +++ 2/SomeRandomDotHFile.h | 1 + 3 files changed, 18 insertions(+) diff --git a/2/Score.cpp b/2/Score.cpp index c107032..13631e9 100644 --- a/2/Score.cpp +++ b/2/Score.cpp @@ -8,5 +8,19 @@ Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) { ID_generator++; } +Score::Score(int score, const char* detail, Label label) :ID(Score::ID_generator) +{ + this->score = score; + this->label = label; + this->detail = detail; + + ID_generator++; +} +Score::Score() : ID(-1) +{ + this->score = 0; + this->label = BAD; + this->detail = ""; +} diff --git a/2/Score.h b/2/Score.h index 0dd79cb..1f8fd2e 100644 --- a/2/Score.h +++ b/2/Score.h @@ -1,3 +1,4 @@ +#pragma once #include #include using namespace std; @@ -13,6 +14,8 @@ class Score { }Label; Score(int score, char* detail, Label label); + Score(int score, const char* detail, Label label); + Score(); private: int score; Label label; diff --git a/2/SomeRandomDotHFile.h b/2/SomeRandomDotHFile.h index 445514a..bb3ff51 100644 --- a/2/SomeRandomDotHFile.h +++ b/2/SomeRandomDotHFile.h @@ -1 +1,2 @@ +#pragma once #include "Score.h" \ No newline at end of file From e6d950e5eace38fe981d2fbe79756dc4db631c9a Mon Sep 17 00:00:00 2001 From: Morteza0Nazarzade <165780917+Morteza0Nazarzade@users.noreply.github.com> Date: Thu, 11 Apr 2024 18:15:29 +0330 Subject: [PATCH 08/10] id_generator fixed --- 2/Score.cpp | 7 +++++++ 2/Score.h | 1 + 2 files changed, 8 insertions(+) diff --git a/2/Score.cpp b/2/Score.cpp index 13631e9..032eb04 100644 --- a/2/Score.cpp +++ b/2/Score.cpp @@ -22,5 +22,12 @@ Score::Score() : ID(-1) this->label = BAD; this->detail = ""; } +void Score::setID_generator(int input) +{ + if (ID_generator < input) + ID_generator += input - ID_generator; + else + ID_generator -= ID_generator - input; +} diff --git a/2/Score.h b/2/Score.h index 1f8fd2e..3bba521 100644 --- a/2/Score.h +++ b/2/Score.h @@ -16,6 +16,7 @@ class Score { Score(int score, char* detail, Label label); Score(int score, const char* detail, Label label); Score(); + void setID_generator(int input); private: int score; Label label; From b0dfd6d15339d8081ffef7c778caf464ad1bdc45 Mon Sep 17 00:00:00 2001 From: Morteza0Nazarzade <165780917+Morteza0Nazarzade@users.noreply.github.com> Date: Thu, 11 Apr 2024 21:42:44 +0330 Subject: [PATCH 09/10] id_generator fixed for real --- 2/Score.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2/Score.h b/2/Score.h index 3bba521..7b33547 100644 --- a/2/Score.h +++ b/2/Score.h @@ -5,7 +5,7 @@ using namespace std; class Score { public: friend void print(const Score& score); - + friend int main(); typedef enum { GREAT, GOOD, @@ -16,7 +16,7 @@ class Score { Score(int score, char* detail, Label label); Score(int score, const char* detail, Label label); Score(); - void setID_generator(int input); + static void setID_generator(int input); private: int score; Label label; From 4cbae66935d9892c1f6028b4a7217c40f1487c35 Mon Sep 17 00:00:00 2001 From: Morteza0Nazarzade <165780917+Morteza0Nazarzade@users.noreply.github.com> Date: Thu, 11 Apr 2024 22:23:26 +0330 Subject: [PATCH 10/10] SCORESET and External link errors fixed --- 2/Score.cpp | 15 +++++++++++++-- 2/Score.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/2/Score.cpp b/2/Score.cpp index 032eb04..51295cb 100644 --- a/2/Score.cpp +++ b/2/Score.cpp @@ -8,7 +8,7 @@ Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) { ID_generator++; } -Score::Score(int score, const char* detail, Label label) :ID(Score::ID_generator) +Score::Score(int score, const char* detail, Label label) : ID(ID_generator) { this->score = score; this->label = label; @@ -29,5 +29,16 @@ void Score::setID_generator(int input) else ID_generator -= ID_generator - input; } - +Score Score::operator =(const Score s) +{ + this->score = s.score; + this->detail = s.detail; + this->label = s.label; + return *this; +} +void print(const Score& score) +{ + cout << score.score << " "; +} +int Score::ID_generator = 0; diff --git a/2/Score.h b/2/Score.h index 7b33547..5b2591d 100644 --- a/2/Score.h +++ b/2/Score.h @@ -17,6 +17,7 @@ class Score { Score(int score, const char* detail, Label label); Score(); static void setID_generator(int input); + Score operator =(const Score s); private: int score; Label label;