From 07706ac28cdf97e6a7952472fb9cf5c48eefde43 Mon Sep 17 00:00:00 2001 From: Yalda Jafari Date: Sat, 6 Apr 2024 06:49:33 -0700 Subject: [PATCH 1/4] first commit --- 1/1.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 14 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index b83dbef..408c7ee 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -3,7 +3,7 @@ #include #include using namespace std; - +class Group; class Person { public: @@ -11,12 +11,29 @@ class Person { this->name = name; } + Person(const string& name , int const _age) { + this->name = name; + this->age = _age; + + } + Person() : name(" ") , age(0) {} + string& getName() { return name; } + const string& getName() const { return name; } + + void operator = (Person const p) { + this->name = p.name; + this->age = p.age; + + } + private: string name; int age; + friend Group; + }; ostream& operator<<(ostream& out, const Person& p) { @@ -34,6 +51,11 @@ class Group { this->members = new Person[max_lenght]; this->size = 0; } + Group() { + this->size = 0; + this->cap = 0; + this->members = NULL; + } void add(Person p) { if (this->size == this->cap) { return; @@ -54,6 +76,34 @@ class Group { size--; } + Group operator + (Group const p) { + Group tmp; + + tmp.cap = this->cap + p.cap; + tmp.size = this->size + p.size; + tmp.members = new Person[tmp.cap]; + + for (int i = 0; i < this->size; i++) { + tmp.members[i] = this->members[i]; + } + + for (int i = this->size; i < p.size; i++) { + tmp.members[i] = p.members[i]; + } + + } + + void operator = (Group const g) { + this->size = g.size; + this->cap = g.cap; + this->members = new Person[cap]; + + for (int i = 0; i < this->size; i++) { + this->members[i] = g.members[i]; + } + + } + ~Group() { delete[] members; } @@ -63,41 +113,54 @@ class Group { int cap; Person* members; + friend bool isGroupFull(Group g); + friend ostream& operator<<(ostream& out, Group& p); + }; +ostream& operator<<(ostream& out, Group& p) { + Person* ptmp = p.members; + + for (int i = 0; i < p.size ; i++) { + cout << p.members[i] << endl; + } + + + return out; +} + bool isGroupFull(Group g) { return (g.size == g.cap); } int main() { - /* Person p1("somename"); - Person p1("somename2"); + Person p2("somename2"); cout << p1< Date: Mon, 8 Apr 2024 21:51:24 -0700 Subject: [PATCH 2/4] second commit --- 1/1.cpp | 117 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 35 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index 408c7ee..3f00abb 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -2,23 +2,24 @@ #include #include #include +#include using namespace std; class Group; class Person { public: - + Person(const string& name) { this->name = name; } - Person(const string& name , int const _age) { + Person(const string& name, int const _age) { this->name = name; this->age = _age; } - Person() : name(" ") , age(0) {} + Person() : name(" "), age(0) {} - string& getName() { return name; } + string& getName() { return name; } const string& getName() const { return name; } @@ -28,12 +29,20 @@ class Person { } + bool operator < (Person const p) { + return ((this->name < p.name) ? true : false); + } + + bool operator == (Person const p) { + return ((this->age == p.age && this->name == p.name) ? true : false); + } + private: string name; int age; friend Group; - + }; ostream& operator<<(ostream& out, const Person& p) { @@ -46,7 +55,7 @@ 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; @@ -56,6 +65,15 @@ class Group { this->cap = 0; this->members = NULL; } + Group(const Group& g) { + this->size = g.size; + this->cap = g.cap; + this->members = new Person[this->cap]; + + for (int i = 0; i < this->size; i++) { + this->members[i] = g.members[i]; + } + } void add(Person p) { if (this->size == this->cap) { return; @@ -66,9 +84,9 @@ 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]; @@ -76,7 +94,7 @@ class Group { size--; } - Group operator + (Group const p) { + Group& operator += (Group const p) { Group tmp; tmp.cap = this->cap + p.cap; @@ -87,10 +105,35 @@ class Group { tmp.members[i] = this->members[i]; } - for (int i = this->size; i < p.size; i++) { - tmp.members[i] = p.members[i]; + int i = this->size; + for (int j = 0; j < p.size; j++) { + tmp.members[i] = p.members[j]; + i++; } + + *this = tmp; + return *this; + } + + Group operator + (Group const p) { + Group tmp; + + tmp.cap = this->cap + p.cap; + tmp.size = this->size + p.size; + tmp.members = new Person[tmp.cap]; + + for (int i = 0; i < this->size; i++) { + tmp.members[i] = this->members[i]; + } + int i = this->size; + for (int j = 0; j < p.size; j++) { + tmp.members[i] = p.members[j]; + i++; + } + + return tmp; + } void operator = (Group const g) { @@ -121,7 +164,7 @@ class Group { ostream& operator<<(ostream& out, Group& p) { Person* ptmp = p.members; - for (int i = 0; i < p.size ; i++) { + for (int i = 0; i < p.size; i++) { cout << p.members[i] << endl; } @@ -137,45 +180,49 @@ int main() { Person p1("somename"); Person p2("somename2"); - cout << p1<= persons + 10) + cout << "There is no person with this name."; + else + cout << (*find(persons, persons + 10, Erfan)).getName(); + + + From e79868ccb633e91f50471338c606f0faa060ad89 Mon Sep 17 00:00:00 2001 From: Yalda Jafari Date: Tue, 9 Apr 2024 08:06:14 -0700 Subject: [PATCH 3/4] first commit --- 2/Score.cpp | 16 +++++++++++++++- 2/Score.h | 4 ++++ 2/main.cpp | 18 +++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/2/Score.cpp b/2/Score.cpp index c107032..ce0ed23 100644 --- a/2/Score.cpp +++ b/2/Score.cpp @@ -1,6 +1,8 @@ #include "Score.h" -Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) { +int Score :: ID_generator; + +Score::Score(int score, const char* detail, Label label) :ID(Score::ID_generator) { this->score = score; this->label = label; this->detail = detail; @@ -9,4 +11,16 @@ Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) { } +Score :: Score() : ID(ID_generator) , score(0) , label(GREAT) , detail("") { + ID_generator++; +} + +void Score :: setID_generator(int _ID_generator) { + ID_generator = _ID_generator; +} +void :: Score :: operator = (const Score& _score){ + this->score = _score.score; + this->label = _score.label; + this->detail = _score.detail; +} \ No newline at end of file diff --git a/2/Score.h b/2/Score.h index 0dd79cb..ea7449e 100644 --- a/2/Score.h +++ b/2/Score.h @@ -1,9 +1,11 @@ #include #include using namespace std; +#pragma once class Score { public: friend void print(const Score& score); + friend int main(); typedef enum { GREAT, @@ -13,6 +15,8 @@ class Score { }Label; Score(int score, char* detail, Label label); + Score(); + static void setID_generator(int _ID_generator); private: int score; Label label; diff --git a/2/main.cpp b/2/main.cpp index 64d213e..41eb180 100644 --- a/2/main.cpp +++ b/2/main.cpp @@ -3,12 +3,28 @@ #include #include #include +#include #include "Score.h" #include "SomeRandomDotHFile.h" using namespace std; #define FOR(n) for(int i=0;i Date: Thu, 11 Apr 2024 04:29:17 -0700 Subject: [PATCH 4/4] third commit --- 1/1.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/1/1.cpp b/1/1.cpp index 3f00abb..de5c357 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -165,7 +164,7 @@ ostream& operator<<(ostream& out, Group& p) { Person* ptmp = p.members; for (int i = 0; i < p.size; i++) { - cout << p.members[i] << endl; + cout << p.members[i] << '\t'; } @@ -231,5 +230,4 @@ int main() -} - +} \ No newline at end of file