diff --git a/1/1.cpp b/1/1.cpp index b83dbef..fd97d7c 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace std; class Person { @@ -11,12 +12,47 @@ class Person { this->name = name; } - string& getName() { return name; } + Person(string s, int g) { + name = s; + age = g; + } + Person() { name = " "; age = 0; }; + string& GetName(const string& newName = "") { + if (!newName.empty()) { + name = newName; + } + return name; + } + friend ostream& operator<<(ostream& out, const Person& p); + const Person& operator=(const Person& other) { + name = other.name; + age = other.age; + + return *this; + } + string getName() const { return name; } + void setName(string n) { + name = n; + } + bool operator <( const Person p) const { + if (strcmp(&name[0], &p.name[0]) > 0) + return 1; + return 0; + } + bool operator >(const Person p) const { + if (strcmp(&name[0], &p.name[0]) > 0) + return 0; + return 1; + } + bool operator ==(const Person p) const { + if (strcmp(&name[0], &p.name[0]) ==0) + return 0; + return 1; + } private: string name; int age; - }; ostream& operator<<(ostream& out, const Person& p) { @@ -31,7 +67,7 @@ class Group { Group(int max_lenght) { this->cap = max_lenght; - this->members = new Person[max_lenght]; + this->members = new Person[max_lenght +1]; this->size = 0; } void add(Person p) { @@ -44,7 +80,7 @@ class Group { void deletePerson(string name) { int i; for (i = 0; i < size; i++) { - if(members[i].name == name) + if(members[i].getName() == name) break; } @@ -52,74 +88,144 @@ class Group { members[index] = members[index + 1]; } size--; + cap--; } + Group() { - ~Group() { - delete[] members; } - + Group( const Group& g) { + this->members = new Person[g.cap + 1]; + size = g.size; + cap = g.cap; + for (int i = 0; i < g.cap; i++) { + members[i] = g.members[i]; + } + } + //~Group() { + //delete[] members; + //} + int getSize() { return size; } + int getCap() { return cap; } + void setCap(int f) { cap = f; } + void setSize(int f) { size = f; } + friend ostream& operator << (ostream& out, Group p); + Group operator +( Group g2) + { + Group all; + int i = 0; + all.setCap(cap+ g2.getCap()); + all.setSize(size + g2.getSize()); + all.members = new Person[all.getCap()]; + for (i = 0; i < size; i++) + { + all.members[i] = members[i]; + } + for (int j = 0; j < g2.getSize(); j++) + { + all.members[i] = members[j]; + i++; + } + return all; + + + + } + Group operator +=( Group g2) + { + Group all; + int i = 0; + all.size = size + g2.size; + all.setCap(cap + g2.cap); + all.members = new Person[all.getCap()]; + for (i = 0; i < cap; i++) + { + all.members[i] =members[i]; + } + for (int j = 0; j < g2.cap; j++) + { + all.members[i] =members[j]; + i++; + } + *this = all; + return *this; + + + + } + void operator =(const Group g) { + members = new Person[g.cap + 1]; + for (int i = 0; i < g.cap; i++) + members[i] = g.members[i]; + size = g.size; + cap = g.cap; + } private: int size; int cap; Person* members; }; +ostream& operator << (ostream& out, Group p) { + for (int i = 0; i < p.size; i++) + { + cout << p.members[i]; + cout<<'\t'; + } + cout << endl; + return out; +} + bool isGroupFull(Group g) { - return (g.size == g.cap); + if(g.getSize() == g.getCap()) + return 0; + return 1; + } int main() { - /* + Person p1("somename"); - Person p1("somename2"); - cout << p1<score = score; + // this->label = label; // Uncomment this line if needed + this->detail = detail; + label = l; + ID_generator++; +} -Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) { - this->score = score; - this->label = label; - this->detail = detail; - +void Score::setID_generator(static int h) +{ + ID_generator = h; +} +Score::Score():ID(Score::ID_generator) +{ ID_generator++; - } - +void print(const Score& score) { + cout << score.detail << endl ; +} +Score::Score( const Score& s):ID(Score::ID_generator) +{ + score = s.score; + label = s.label; + detail = s.detail; +} +void Score:: operator=(Score s) +{ + score = s.score; + label = s.label; + detail = s.detail; +} diff --git a/2/Score.h b/2/Score.h index 0dd79cb..7d07c2c 100644 --- a/2/Score.h +++ b/2/Score.h @@ -4,6 +4,7 @@ using namespace std; class Score { public: friend void print(const Score& score); + friend int main(); typedef enum { GREAT, @@ -12,7 +13,11 @@ class Score { BAD, }Label; - Score(int score, char* detail, Label label); + Score(int score, string detail, Label label); + Score(); + Score(const Score& s); + static void setID_generator(static int h); + void operator=(Score s); private: int score; Label label; diff --git a/2/main.cpp b/2/main.cpp index 64d213e..7e5fede 100644 --- a/2/main.cpp +++ b/2/main.cpp @@ -1,9 +1,8 @@ - #include #include #include #include -#include "Score.h" +//#include "Score.h" #include "SomeRandomDotHFile.h" using namespace std; #define FOR(n) for(int i=0;i