Skip to content
Open
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 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\\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"
}
89 changes: 61 additions & 28 deletions 1/1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@ 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;

};

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

Expand All @@ -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;

}
Expand All @@ -53,51 +63,83 @@ 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;
Person* members;

};

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<<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");
g1.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 +150,9 @@ int main()

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







}

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

}

Binary file added 1/1.exe
Binary file not shown.
28 changes: 28 additions & 0 deletions 2/.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\\ucrt64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}", "Score.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
9 changes: 4 additions & 5 deletions 2/Score.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "Score.h"

Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) {
using namespace std;
int Score::ID_generator = 0;
Score :: Score(int score,char* detail, Label label) : Score::ID(Score::ID_generator) {
this->score = score;
this->label = label;
this->detail = detail;

ID_generator++;

}


62 changes: 47 additions & 15 deletions 2/Score.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,57 @@

#ifndef HEADERFILE_H
#define HEADERFILE_H
#include <iostream>
#include <string>
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











5 changes: 4 additions & 1 deletion 2/SomeRandomDotHFile.h
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
#include "Score.h"
#ifndef HEADERFILE_H
#define HEADERFILE_H
#include "Score.h"
#endif
20 changes: 17 additions & 3 deletions 2/main.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include "Score.h"
#include "SomeRandomDotHFile.h"
using namespace std;
#define FOR(n) for(int i=0;i<n;i++)
#define SETSCORE(i) int score=rand()%20+1;/*no 0s*/\
scores[i] = Score( score,("some string " + to_string(i)).c_str(),Score::Label(3-score/5)) ;

string convertToString(char* str) {
string result;
int length = strlen(str);
for (int i = 0; i < length; ++i) {
result.push_back(str[i]);
}
return result;
}
int Score::ID_generator = 0;

#define FOR(n) for(int i=0;i<n;i++)
#define SETSCORE(i) int score=rand()%20+1;\
scores[i] = Score("some string " + to_string(i), static_cast<Score::Label>(3-score/5));

void print(const Score& score) {
cout << "Score: " << score.score << ", Detail: " << score.detail << ", Label: " << score.label << endl;
}
int main()
{

Expand Down