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: 61 additions & 25 deletions 1/1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,32 @@ using namespace std;

class Person {
public:

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

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

const string& getName() const { return name; }

bool operator==(const Person &p) const {
return this->age == p.age && this->name == p.name;
}

bool operator<(const Person &p)const{
return this->age < p.age && this->name < p.name;
}


private:
string name;
int age;
Expand Down Expand Up @@ -41,22 +60,47 @@ class Group {
this->members[size] = p;
this->size++;
}

void deletePerson(string name) {
int i;
for (i = 0; i < size; i++) {
if(members[i].name == name)
if(members[i].getName() == name)
break;

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

int& getSize() { return size; }
int& getCap() { return cap; }

~Group() {
delete[] members;
}
friend ostream& operator<<(ostream& out,const Group& g) {
for(int i = 0;i < g.size;i++){
out << g.members[i] << "\t";
}
return out;
}

friend Group operator+(const Group& g1, const Group& g2) {
Group result(g1.cap + g2.cap);
copy(g1.members, g1.members + g1.size, result.members);
copy(g2.members, g2.members + g2.size, result.members + g1.size);
result.size = min(g1.size + g2.size, result.cap);
return result;
}
friend Group& operator+=(Group& g1, const Group& g2) {
if (g1.size + g2.size <= g1.cap) {
copy(g2.members, g2.members + g2.size, g1.members + g1.size);
g1.size += g2.size;
}
return g1;
}

private:
int size;
Expand All @@ -66,38 +110,37 @@ class Group {
};

bool isGroupFull(Group g) {
return (g.size == g.cap);
return (g.getSize() == g.getCap());
}

int main()
{
/*

Person p1("somename");
Person p1("somename2");
cout << p1<<p2;
*/
/*
Person p2("somename2");
cout << p1 << "\n" << p2 << endl;


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 << 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,16 +151,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);



Expand Down
Binary file added 1/1.exe
Binary file not shown.
Binary file added 1/1.o
Binary file not shown.
33 changes: 28 additions & 5 deletions 2/Score.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
#include "Score.h"

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

ID_generator++;
Score::Score(int score, const char* detail, Label label)
: score(score), label(label), detail(detail), ID(++ID_generator) {
}

Score::Score()
: score(0), label(Label::GREAT), detail(""), ID(ID_generator) {
ID_generator++;
}

Score::Score(const Score& other)
: score(other.score), label(other.label), detail(other.detail), ID(++ID_generator) {
}

Score& Score::operator=(const Score& other) {
score = other.score;
label = other.label;
detail = other.detail;
return *this;
}

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

void Score::setID_generator(int value) {
ID_generator = value;
}

int Score::getID_generator() {
return ID_generator;
}
42 changes: 26 additions & 16 deletions 2/Score.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
#ifndef SCORE_H
#define SCORE_H

#include <iostream>
#include <string>
using namespace std;

class Score {
public:
friend void print(const Score& score);

typedef enum {
GREAT,
GOOD,
NOTBAD,
BAD,
}Label;
typedef enum Label{
GREAT,
GOOD,
NOTBAD,
BAD,
}Label;

Score(int score, char* detail, Label label);
private:
int score;
Label label;
string detail;
const int ID;
static int ID_generator;
};
Score(int score, const char* detail, Label label);
Score();
Score(const Score& other);
Score& operator=(const Score& other);

friend void print(const Score& score);

static void setID_generator(int value);
static int getID_generator();

private:
int score;
Label label;
string detail;
const int ID;
static int ID_generator;
};

#endif // SCORE_H
38 changes: 38 additions & 0 deletions 2/Score/Score.cbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Score" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Score" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Score" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>
35 changes: 35 additions & 0 deletions 2/Score/Score.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "Score.h"

int Score::ID_generator = 0;

Score::Score(int score, const char* detail, Label label)
: score(score), label(label), detail(detail), ID(++ID_generator) {
}

Score::Score()
: score(0), label(Label::GREAT), detail(""), ID(ID_generator) {
ID_generator++;
}

Score::Score(const Score& other)
: score(other.score), label(other.label), detail(other.detail), ID(++ID_generator) {
}

Score& Score::operator=(const Score& other) {
score = other.score;
label = other.label;
detail = other.detail;
return *this;
}

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

void Score::setID_generator(int value) {
ID_generator = value;
}

int Score::getID_generator() {
return ID_generator;
}
8 changes: 8 additions & 0 deletions 2/Score/Score.depend
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# depslib dependency file v1.0
1712862646 source:c:\users\lenovo\desktop\ap_lab_git_practice_s4022\2\score\score.cpp
"Score.h"

1712862612 c:\users\lenovo\desktop\ap_lab_git_practice_s4022\2\score\score.h
<iostream>
<string>

35 changes: 35 additions & 0 deletions 2/Score/Score.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef SCORE_H
#define SCORE_H

#include <iostream>
#include <string>
using namespace std;

class Score {
public:
typedef enum Label{
GREAT,
GOOD,
NOTBAD,
BAD,
}Label;

Score(int score, const char* detail, Label label);
Score();
Score(const Score& other);
Score& operator=(const Score& other);

friend void print(const Score& score);

static void setID_generator(int value);
static int getID_generator();

private:
int score;
Label label;
string detail;
const int ID;
static int ID_generator;
};

#endif // SCORE_H
1 change: 1 addition & 0 deletions 2/Score/SomeRandomDotHFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Score.h"
Binary file added 2/Score/bin/Debug/Score.exe
Binary file not shown.
Loading