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
187 changes: 135 additions & 52 deletions 1/1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,195 @@
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

class Person {
class Person
{
public:

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

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

}
Person(const string name, int age)
{
this->name = name;
this->age = age;
}
bool operator<(const Person& other) const {
return name < other.name;
}
//friend ostream &operator<<(ostream &out, const Person &p);
const string& getName() const { return name; }
string& getName() { return name; }

friend class Group;

private:
string name;
int age;

};

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



class Group {
class Group
{
public:

Group(int max_lenght) {
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) {
void add(Person p)
{
if (this->size == this->cap)
{
return;
}
this->members[size] = p;
this->size++;
}
void deletePerson(string name) {
void deletePerson(string name)
{
int i;
for (i = 0; i < size; i++) {
if(members[i].name == name)
for (i = 0; i < size; i++)
{
if (members[i].name == name)
break;

}
for (int index = i; index < size - 1; index++) {
for (int index = i; index < size - 1; index++)
{
members[index] = members[index + 1];
}
size--;
}

~Group() {
friend bool isGroupFull(const Group &g);
friend ostream &operator<<(ostream &out, const Group &p);
~Group()
{
delete[] members;
}
Group operator+(const Group &other) const
{
Group result(cap + other.cap);
for (int i = 0; i < size; ++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)
{
if (size + other.size > cap) {
int newCap = size + other.size;
Person *newMembers = new Person[newCap];

for (int i = 0; i < size; ++i)
{
newMembers[i] = members[i];
}
for (int i = 0; i < other.size; ++i)
{
newMembers[size + i] = other.members[i];
}

delete[] members;
members = newMembers;
size = size + other.size;
cap = newCap;
} else {
for (int i = 0; i < other.size; ++i)
{
members[size + i] = other.members[i];
}
size = size + other.size;
}

return *this;
}
Group &operator=(const Group &other)
{
if (this != &other)
{
delete[] members;
size = other.size;
cap = other.cap;
members = new Person[other.cap];
for (int i = 0; i < other.size; ++i)
{
members[i] = other.members[i];
}
}
return *this;
}

private:
int size;
int cap;
Person* members;

Person *members;
};
ostream &operator<<(ostream &out, const Group &g)
{
for(int i=0;i<g.size;i++){

bool isGroupFull(Group g) {
cout << g.members[i]<<"\t";
}

return out;
}

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

int main()
{
/*

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

Group g1(5);
g1.add({ "Erfan",20 });
g1.add({ "Saba",20 });
g1.add({ "Mahrokh",20 });
g1.add({ "Yasin",21 });
cout<<isGroupFull(g1)<<endl;
*/
/*
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 +201,8 @@ int main()

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

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









}

Binary file added 1/1.exe
Binary file not shown.
20 changes: 19 additions & 1 deletion 2/Score.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Score.h"

Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) {
Score::Score(int score,const char* detail, Label label) :ID(Score::ID_generator) {
this->score = score;
this->label = label;
this->detail = detail;
Expand All @@ -9,4 +9,22 @@ Score::Score(int score,char* detail, Label label) :ID(Score::ID_generator) {

}

void print(const Score& score) {
cout << "Score: " << score.score << ", Detail: " << score.detail << ", 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;
}

23 changes: 21 additions & 2 deletions 2/Score.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,34 @@ using namespace std;
class Score {
public:
friend void print(const Score& score);

friend int main();
typedef enum {
GREAT,
GOOD,
NOTBAD,
BAD,
}Label;
Score();
Score(int score, const char* detail, Label label);


Score& operator=(const Score& other) {

if (this != &other) {

Score(int score, char* detail, Label label);
this->score = other.score;
this->label = other.label;
this->detail = other.detail;
}

return *this;
}
static void setID_generator(int value) {
ID_generator = value;
}



private:
int score;
Label label;
Expand Down
2 changes: 2 additions & 0 deletions 2/SomeRandomDotHFile.h
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#pragma once

#include "Score.h"
3 changes: 2 additions & 1 deletion 2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <algorithm>
#include "Score.h"
#include "SomeRandomDotHFile.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(n) for(int i=0;i<n;i++)
#define SETSCORE(i) int score=rand()%20+1;/*no 0s*/\
Expand All @@ -13,7 +14,7 @@ scores[i] = Score( score,("some string " + to_string(i)).c_str(),Score::Label(3-

int main()
{

srand(time(NULL));

Score s1(1, "do better next time", Score::BAD);
Expand Down