From 3681757771f49d0fae5e473e71a2e077f6e5dee6 Mon Sep 17 00:00:00 2001 From: hosseinoruji1384 Date: Sat, 6 Apr 2024 17:49:14 +0330 Subject: [PATCH 1/2] file added --- 1/HosseinProject.cpp | 122 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 1/HosseinProject.cpp diff --git a/1/HosseinProject.cpp b/1/HosseinProject.cpp new file mode 100644 index 0000000..7c2b393 --- /dev/null +++ b/1/HosseinProject.cpp @@ -0,0 +1,122 @@ + +#include +#include +#include +#include +using namespace std; + +class Person { +public: + + Person(const string& name, const int& age) { + this->name = name; + this->age = age; + } + Person(const string& name) { + this->name = name; + } + string& getName() { return name; } + + string getName()const { return name; } + +private: + string name; + int age; + +}; + +ostream& operator<<(ostream& out, const Person& p) { + cout << p.getName(); + return out; +} + +ostream& operator<<(ostream& out, const Group p) { + return out; +} + +class Group { +public: + Group(int max_lenght) { + this->cap = max_lenght; + this->members = new Person[max_lenght]; + this->size = 0; + } + void add(Person p) { + if (this->size == this->cap) { + return; + } + this->members[size] = p; + this->size++; + } + void deletePerson(string name) { + int i; + for (i = 0; i < size; i++) { + if(members[i].getName() == name) + break; + + } + for (int index = i; index < size - 1; index++) { + members[index] = members[index + 1]; + } + size--; + } + + ~Group() { + delete[] members; + } + + int getSize() { return size; } + + int getCap() { return cap; } + + Group operator+(Group const& p) { + return *this; + } + + Group operator+=(Group const& p) { + return *this; + } +private: + int size; + int cap; + Person* members; + +}; + +bool isGroupFull(Group g) { + return (g.getSize() == g.getCap()); +} + +int main() +{ + Person p1("somename"); + Person p2("somename2"); + cout << p1< Date: Fri, 12 Apr 2024 23:20:44 +0330 Subject: [PATCH 2/2] copy constructors created --- 2/Score.cpp | 32 ++++++++++++++++++++++++++------ 2/Score.h | 18 ++++++++++-------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/2/Score.cpp b/2/Score.cpp index c107032..6fb4392 100644 --- a/2/Score.cpp +++ b/2/Score.cpp @@ -1,12 +1,32 @@ #include "Score.h" - -Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) { +int Score::ID_generator = 0; +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() :score(0), label(Label()), detail(""), ID(ID_generator++) { + this->score = score; + this->label = label; + this->detail = detail; + ID_generator++; +} +void Score::setID_generator(int _id_generator) { + ID_generator = _id_generator; +} +void print(const Score& score) { + cout << "score:" << score.score; + cout << "\nlabel:" << score.label; + cout << "\ndetail:" << score.detail; + cout << "\nID:" << score.ID; +} +Score& Score::operator=(const Score& p) { + if (this != &p) + { + this->label = p.label; + this->detail = p.detail; + this->score = p.score; + } + return *this; +} \ No newline at end of file diff --git a/2/Score.h b/2/Score.h index 0dd79cb..783e5c3 100644 --- a/2/Score.h +++ b/2/Score.h @@ -1,25 +1,27 @@ +#pragma once #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); + Score(int score, const char* detail, Label label); + void static setID_generator(int id_generator); + Score& Score::operator=(const Score& p); + Score(); + friend int main(); + //Score::Score() :score(0), label(Label()), detail(""), ID(Score::ID_generator) {}; + void print(const Score&); private: + const int ID; int score; Label label; string detail; - const int ID; static int ID_generator; -}; - - - +}; \ No newline at end of file