diff --git a/1/.vscode/tasks.json b/1/.vscode/tasks.json new file mode 100644 index 0000000..7b0448d --- /dev/null +++ b/1/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++.exe build active file", + "command": "C:\\msys64\\ucrt64\\bin\\g++.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/1/1.cpp b/1/1.cpp index b83dbef..0eb4133 100644 --- a/1/1.cpp +++ b/1/1.cpp @@ -6,13 +6,23 @@ using namespace std; class Person { public: - + Person (){} Person(const string& name) { this->name = name; } - string& getName() { return name; } - + Person (string n , int a){ + this->age = a; + this->name = n; + } + string getName() const { return name; } + bool operator==(const Person& p) const { + return (name == p.name && age == p.age); + } + bool operator<(const Person& p) const { + return age < p.age; + } + friend class Group; private: string name; int age; @@ -20,7 +30,7 @@ class Person { }; ostream& operator<<(ostream& out, const Person& p) { - cout << p.getName(); + cout << p.getName() << endl; return out; } @@ -44,7 +54,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; } @@ -53,11 +63,34 @@ class Group { } size--; } - ~Group() { delete[] members; } + int getsize(){return size;} + Group operator+(const Group& other) { + Group result(cap + other.cap); + for (int i = 0; i < getsize(); ++i) { + result.add(members[i]); + } + for (int i = 0; i < other.size; ++i) { + result.add(other.members[i]); + } + return result; + } + Group& operator+=(const Group& other) { + for (int i = 0; i < other.size; ++i) { + if (isGroupFull(*this)) { + cout << "Cannot add more members. The group is full." << endl; + return *this; + } + add(other.members[i]); + } + return *this; + } + friend bool isGroupFull(Group g); + friend ostream& operator<<(ostream& out, const Group& g); + private: int size; int cap; @@ -65,39 +98,48 @@ class Group { }; +ostream& operator<<(ostream& out, const Group& g) { + for (int i = 0; i < g.size; ++i) { + out << g.members[i].getName(); + if (i != g.size - 1) { + out << '\t'; + } + } + return out; +} + + + bool isGroupFull(Group g) { return (g.size == g.cap); } + int main() { - /* + Person p1("somename"); - Person p1("somename2"); + Person p2("somename2"); cout << p1<score = score; this->label = label; this->detail = detail; - + ID_generator++; } - - diff --git a/2/Score.h b/2/Score.h index 0dd79cb..3c0e73f 100644 --- a/2/Score.h +++ b/2/Score.h @@ -1,25 +1,57 @@ + +#ifndef HEADERFILE_H +#define HEADERFILE_H #include #include using namespace std; + class Score { public: - friend void print(const Score& score); - - typedef enum { - GREAT, - GOOD, - NOTBAD, - BAD, - }Label; - - Score(int score, char* detail, Label label); + friend void print(const Score& score); + friend int main (); + typedef enum { + GREAT, + GOOD, + NOTBAD, + BAD, + } Label; + // Score() : score(0), label(GOOD), detail(""), ID(ID_generator++) {} + Score(int score, const char* detail, Label label); + static void setID_generator(int value) { + ID_generator = value; + } + Score() : score(0), label(GREAT), detail(""), ID(ID_generator) { + ID_generator++; + } + Score(int id) : ID(id) {} + Score(const string& detail) : score(0), label(GREAT), detail(detail), ID(ID_generator) { + ID_generator++; + } + Score(const string& detail, Label label) : detail(detail), label(label) , ID (ID_generator) { + ID_generator ++; + } + Score& operator=(const Score& other) { + // Copy things from other to this + // ... + return *this; + } private: - int score; - Label label; - string detail; - const int ID; - static int ID_generator; + int score; + Label label; + string detail; + const int ID; + static int ID_generator; }; +#endif + + + + + + + + + diff --git a/2/SomeRandomDotHFile.h b/2/SomeRandomDotHFile.h index 445514a..d0fdef0 100644 --- a/2/SomeRandomDotHFile.h +++ b/2/SomeRandomDotHFile.h @@ -1 +1,4 @@ -#include "Score.h" \ No newline at end of file +#ifndef HEADERFILE_H +#define HEADERFILE_H +#include "Score.h" +#endif diff --git a/2/main.cpp b/2/main.cpp index 64d213e..bb6b7b6 100644 --- a/2/main.cpp +++ b/2/main.cpp @@ -1,16 +1,30 @@ #include #include +#include #include #include #include "Score.h" #include "SomeRandomDotHFile.h" using namespace std; -#define FOR(n) for(int i=0;i(3-score/5)); + +void print(const Score& score) { + cout << "Score: " << score.score << ", Detail: " << score.detail << ", Label: " << score.label << endl; +} int main() {