diff --git a/1/1.cpp b/1/1.cpp index b83dbef..4ebb4ff 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -2,27 +2,62 @@ #include #include #include +#include using namespace std; class Person { public: - + Person(const string& _name , int _age ) : name(_name) , age(_age) { //me + } Person(const string& name) { this->name = name; - + } + Person() { //me + name = " "; + age = 0; } string& getName() { return name; } - + string getName()const { return name; } //me + int getAge()const { return age; } //me + bool operator < (const Person& other) const{ //me + return this->name < other.name; + } + bool operator ==(const Person& other) const { //me + return this->name == other.name && this->age == other.age; + } + + friend class Group; private: string name; int age; }; -ostream& operator<<(ostream& out, const Person& p) { + + +/*ostream& operator<< (ostream& out, const Person* p) { + if (p == NULL) { + cout << "can not find\n"; + return out; + } + cout << p->getName(); + return out; +}*/ +ostream& operator<<(ostream& out, const Person& p) { //check cout << p.getName(); return out; } +/*Person* find(Person* start, Person* end, const Person& goal) { //me + cout << "here"; + for (Person* i = start; i <= end; ++i) { + if (i->getName() == goal.getName() && i->getAge() == goal.getAge()) { + cout << "Hey"; + return i; + } + } + cout << "can not find\n"; + return end; +}*/ @@ -31,9 +66,17 @@ class Group { Group(int max_lenght) { this->cap = max_lenght; - this->members = new Person[max_lenght]; + this->members = new Person[max_lenght]; //check this->size = 0; } + Group(Group& obj) { + this->cap = obj.cap; + this->size = obj.size; + this->members = new Person[this->cap]; + for (int i = 0; i < this->size; ++i) { + this->members[i] = obj.members[i]; + } + } void add(Person p) { if (this->size == this->cap) { return; @@ -46,80 +89,126 @@ 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& obj) { //me + this->size = obj.size; + this->cap = obj.cap; + this->members = new Person[this->cap]; + for (int i = 0; i < this->size; ++i) { + this->members[i] = obj.members[i]; + } + return *this; + } + Group operator+(const Group &obj) { //me + Group sum(this->cap + obj.cap); + sum.size = this->size + obj.size; + sum.cap = this->cap + obj.cap; + for (int i = 0; i < this->size ; ++i) { + sum.members[i] = this->members[i]; + } + for (int i = 0; i < obj.size; ++i) { + sum.members[this->size + i] = obj.members[i]; + } + return sum; + } + Group& operator+=(const Group& obj) { //me + Group temp(this->cap); + temp.size = this->size; + int pirmary_size = obj.size; + for (int i = 0; i < this->size; ++i) { + temp.members[i] = this->members[i]; + } + delete[] this->members; + this->size = temp.size + obj.size; + this->cap = this->cap + obj.cap; + 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 < pirmary_size; ++i) { + this->members[temp.size + i] = obj.members[i]; + } + return *this; + } + friend bool isGroupFull(Group ); //me + friend ostream& operator<<(ostream& ,const Group& ); //me + ~Group() { delete[] members; } - + private: int size; int cap; Person* members; }; +ostream& operator<<(ostream& out ,const Group& obj) { //me + for (int i = 0; i < obj.size ; ++i) { + out << obj.members[i] << "\t"; + } + cout << endl; + return out; +} -bool isGroupFull(Group g) { - return (g.size == g.cap); +bool isGroupFull(Group g) { //check + return (g.size == g.cap); } int main() { - /* + Person p1("somename"); - Person p1("somename2"); + Person p2("somename2"); cout << p1<score = score; @@ -6,7 +11,30 @@ Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) { this->detail = detail; 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(Score::ID_generator) { + this->score =0; + this->detail = ""; + this->label = GREAT; + ID_generator++; +} +Score& Score::operator=(const Score& obj) +{ + this->score = obj.score; + this->detail = obj.detail; + this->label = obj.label; + return *this; } + + diff --git a/2/Score.h b/2/Score.h index 0dd79cb..d2bb557 100644 --- a/2/Score.h +++ b/2/Score.h @@ -1,10 +1,12 @@ +#pragma once #include #include using namespace std; class Score { public: - friend void print(const Score& score); - + friend void print( const Score& score); //check + friend int main(); + static void setID_generator(int ); typedef enum { GREAT, GOOD, @@ -13,6 +15,9 @@ class Score { }Label; Score(int score, char* detail, Label label); + Score(int, const char* , Label); //me + Score();//me + Score& operator=(const Score& obj); private: int score; Label label; diff --git a/2/SomeRandomDotHFile.h b/2/SomeRandomDotHFile.h index 445514a..834fc0d 100644 --- a/2/SomeRandomDotHFile.h +++ b/2/SomeRandomDotHFile.h @@ -1 +1,5 @@ -#include "Score.h" \ No newline at end of file +#pragma once +#include "Score.h" +void print(const Score& obj) { + cout << "score : " << obj.score << " Label : " << obj.label << " detail : " << obj.detail << " ID : " << obj.ID << endl; +} \ No newline at end of file diff --git a/2/main.cpp b/2/main.cpp index 64d213e..d0c8d89 100644 --- a/2/main.cpp +++ b/2/main.cpp @@ -16,16 +16,17 @@ int main() 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?:) + Score s1(1, "do better next time", Score::BAD); //check + Score scores[10];//we have default constructor so we should be fine right?:) //check FOR(10) { - SETSCORE(i) + SETSCORE(i); //check //why = betwean two scores raises an error?:) } FOR(10) { print(scores[i]); } + Score::setID_generator(Score::ID_generator+100);//just a setter for ID_generator }