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
86 changes: 65 additions & 21 deletions 1/1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <iostream>
#include <vector>
#include <algorithm>
#include<string>
using namespace std;

class Person {
Expand All @@ -11,21 +12,44 @@ class Person {
this->name = name;

}
Person(const string& name , int g) {
this->name = name;
this->age;

}
Person() {}

string& getName() { return name; }
string getName ()const { return name; }
Person operator+(const Person& other) const {
string newName = this->name + " " + other.name;
int newAge = this->age + other.age;
return Person(newName, newAge);
}
Person& operator+=(const Person& other) {
this->name += other.name;
this->age += other.age;
return *this;
}




private:
string name;
int age;


};

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




class Group {
public:

Expand All @@ -41,10 +65,10 @@ class Group {
this->members[size] = p;
this->size++;
}
void deletePerson(string name) {
void deletePerson(const string &name) {
int i;
for (i = 0; i < size; i++) {
if(members[i].name == name)
if(members[i].getName() == name)
break;

}
Expand All @@ -57,47 +81,67 @@ class Group {
~Group() {
delete[] members;
}


friend bool isGroupFull(const Group& g);
friend ostream& operator<<(ostream& out, const Group G);
friend class person;
Group operator+ (const Group& other) const {
for(int i=0 ; size>i && other.size>i ; i++ ){
members[i].operator+(other.members[i]);
}
}
Group& operator+=(const Group& other){
for(int i=0 ; size>i && other.size>i ; i++ ){
members[i].operator+=(other.members[i]);
}
}
private:
int size;
int cap;
Person* members;

};

bool isGroupFull(Group g) {
bool isGroupFull(const 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];
}
return out;
}

int main()
{
/*

Person p1("somename");
Person p1("somename2");
cout << p1<<p2;
*/
/*
//Person p1("somename2");
Person p2("somename1");
cout << p1 << p2;


Group g1(5);
g1.add({ "Erfan",20 });
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 << 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,10 +152,10 @@ int main()

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

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




Expand Down
6 changes: 6 additions & 0 deletions 2/Score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) {
ID_generator++;

}
Score::Score(){
this->score = -0;

this->detail = "";

ID_generator=0;
}

1 change: 1 addition & 0 deletions 2/Score.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Score {
}Label;

Score(int score, char* detail, Label label);
Score();
private:
int score;
Label label;
Expand Down
4 changes: 2 additions & 2 deletions 2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ scores[i] = Score( score,("some string " + to_string(i)).c_str(),Score::Label(3-

int main()
{

int i;
srand(time(NULL));

Score s1(1, "do better next time", Score::BAD);
Score scores[10];//we have default constructor so we should be fine right?:)

FOR(10) {
SETSCORE(i)
SETSCORE(i);
//why = betwean two scores raises an error?:)
}
FOR(10) {
Expand Down