Skip to content
Open

... #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64-2\\ucrt64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
28 changes: 28 additions & 0 deletions 1/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64-2\\ucrt64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
179 changes: 138 additions & 41 deletions 1/1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,42 @@
#include <algorithm>
using namespace std;

#define MAX_SIZE 100

class Person {
public:

Person(const string& name) {
this->name = name;
age = 0;
}


Person(string _name, int _age)
{
name = _name;
age = _age;
}
Person()
{
name = " ";
age = 0;
}

string getName() const {return name;}
string& getName() { return name; }
void setName(const string& _name) {name = _name;}
void setAge(int _age) {age = _age;}

bool operator<(const Person& person) const {
return name < person.name;
}
bool operator==(const Person& person) const
{
return (person.name == name);
}

friend class Group;

private:
string name;
Expand All @@ -20,12 +48,13 @@ class Person {
};

ostream& operator<<(ostream& out, const Person& p) {
cout << p.getName();
out << p.getName();
return out;
}




class Group {
public:

Expand All @@ -34,29 +63,98 @@ class Group {
this->members = new Person[max_lenght];
this->size = 0;
}
void add(Person p) {
if (this->size == this->cap) {
return;
Group(const Group& other) {
this->cap = other.cap;
this->size = other.size;
this->members = new Person[other.cap];

for (int i = 0; i < other.size; i++) {
this->members[i] = other.members[i];
}
}
Group(Group& g)
{
this->size = g.size;
this->cap = g.cap;
this->members = new Person[g.cap];
for(int i = 0;i < g.size;++i)
{
this->members[i] = g.members[i];
}
this->members[size] = p;
this->size++;
}
void deletePerson(string name) {
int i;
for (i = 0; i < size; i++) {
if(members[i].name == name)
break;

Group& operator=(const Group& other) {
if (this != &other) {
delete[] members;
this->cap = other.cap;
this->size = other.size;
this->members = new Person[other.cap];

for (int i = 0; i < other.size; i++) {
this->members[i] = other.members[i];
}
}
return *this;
}
void add(const Person& p) {
if (size == cap) {
return;
}
members[size] = p;
size++;
}
void deletePerson(const string& name) {
int i;
for (i = 0; i < size; i++) {
if (members[i].getName() == name)
break;
}
if (i == size) {
return;
}
for (int index = i; index < size - 1; index++) {
members[index] = members[index + 1];
}
members[size - 1].setName("");
size--;
}
Group operator+(const Group& g) const {
Group res(size + g.size);
for (int i = 0; i < size; ++i) {
res.members[i] = members[i];
}
for (int i = size, j = 0; i < size + g.size; ++i, ++j) {
res.members[i] = g.members[j];
}
res.size = size + g.size;
res.cap = size + g.size;
return res;
}
Group& operator+=(const Group& g) {
cap = size + g.size;
Person *tmp = new Person[cap];
for(int i = 0;i < size;++i)
{
tmp[i] = members[i];
}
for (int index = i; index < size - 1; index++) {
members[index] = members[index + 1];
members = new Person[cap];
for(int i = 0;i < size;++i)
{
members[i] = tmp[i];
}
size--;
}
for (int i = size, j = 0; i < size + g.size; ++i, ++j) {
members[i] = g.members[j];
size++;
}
delete []tmp;
return *this;
}

friend ostream& operator<< (ostream& out, const Group &g);

~Group() {
delete[] members;
}
friend bool isGroupFull(const Group& g);

private:
int size;
Expand All @@ -65,39 +163,47 @@ class Group {

};

bool isGroupFull(Group g) {
return (g.size == g.cap);
ostream& operator<< (ostream& out, const Group &g)
{
for(int i = 0;i < g.size; ++i)
{
out << g.members[i] << '\t';
}
return out;
}

bool isGroupFull(const Group& g) {
return (g.size == g.cap);
}

int main()
{
/*
Person p1("somename");
Person p1("somename2");
Person p2("somename2");
cout << p1<<p2;
*/
/*

Group g1(5);
g1.add({ "Erfan",20 });
g1.add({ "Saba",20 });
g1.add({ "Mahrokh",20 });
g1.add({ "Yasin",21 });
cout<<isGroupFull(g1)<<endl;
*/
/*


Group g2(g1);
Group g3(10);
g2.deletePerson("Erfan");
cout << g1<<endl;//should cout every person in it with a \t as the separator
cout << g2 << endl;
*/
/*


g3 = g1;
cout << g3;
g3 = g2 + g3;//adds members of g2 and g3 to each other
g3 += g3 += g3 += g3;
*/
/*



Person persons[10];
Person Erfan("Erfan",20);
persons[1]=Erfan;
Expand All @@ -108,18 +214,9 @@ int main()

for(int i=0;i<10;i++){
cout<<persons[i].getName()<<' ';
}*/
/*
}

cout<<*find(persons,persons+10,Erfan);
*/









}

return 0;
}
Binary file added 1/1.exe
Binary file not shown.
49 changes: 48 additions & 1 deletion 2/Score.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,59 @@
#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(int score,const string detail, Label label) :ID(Score::ID_generator) {
this->score = score;
this->label = label;
this->detail = detail;

ID_generator++;

}
Score::Score():ID(0)
{
score = 0;
label = GREAT;
detail = " ";
}

void print(const Score& score)
{
cout << "Score: " << score.score << endl;
cout << "Label: ";
switch (score.label)
{
case Score::GREAT:
cout << "GREAT";
break;
case Score::GOOD:
cout << "GOOD";
break;
case Score::NOTBAD:
cout << "NOTBAD";
break;
case Score::BAD:
cout << "BAD";
break;
}
cout << endl;
cout << "Detail: " << score.detail << endl;
}
void Score::set_score(int _score){score = _score;}
void Score::set_label(Label _label){label = _label;}
void Score::set_detail(const string& _detail){detail = _detail;}
void Score::setID_generator(int id_g){ID_generator = id_g;}
Score Score::operator=(const Score &sc)
{
Score res(sc.score,sc.detail,sc.label);
return res;
}
Score::~Score(){}
Loading