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
122 changes: 122 additions & 0 deletions 1/HosseinProject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
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<<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;
for(int i=0;i<10;i++){
persons[i].getName()=to_string(rand()%100);
}
sort(persons,persons+10);//what operator should be overloaded for sort? :)

for (int i = 0; i < 10; i++) {
cout << persons[i].getName() << ' ';
}
cout<<*find(persons,persons+10,Erfan);
}
32 changes: 26 additions & 6 deletions 2/Score.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
18 changes: 10 additions & 8 deletions 2/Score.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#pragma once
#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);
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;
};



};