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
Binary file added .DS_Store
Binary file not shown.
192 changes: 130 additions & 62 deletions 1/1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,122 +4,190 @@
#include <algorithm>
using namespace std;

class Person {
class Person
{
public:

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

}
string& getName() { return name; }
Person(const string _name, int _age)
{
this->name = _name;
this->age = _age;
}
Person(const Person &person)
{
name = person.name;
age = person.age;
}
string &getName() { return name; }
string getName() const { return name; }
friend class Group;
bool operator<(const Person &person) const
{
return (name < person.name);
}
friend void swap(Person &first, Person &second)
{
swap(first.name, second.name);
swap(first.age, second.age);
}
bool operator==(const Person &person) const
{
return (name == person.name);
}

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(Group);
friend ostream &operator<<(ostream &out, const Group &p);
Group operator+(Group const &group)
{
Group temp(cap + group.cap);
for (int i = 0; i < size; i++)
{
temp.members[i] = members[i];
}
for (int i = 0, j = size; i < group.size; i++, j++)
{
temp.members[j] = group.members[i];
}
temp.size = size + group.size;
return temp;
}
Group &operator+=(Group const &group)
{
cap += group.cap;
for (int i = 0, j = size; i < group.size; i++, j++)
{
members[j] = group.members[i];
}
size += group.size;
return *this;
}
Group(const Group &other) : cap(other.cap), size(other.size), members(new Person[other.cap])
{
for (int i = 0; i < size; i++)
{
members[i] = other.members[i];
}
}
Group &operator=(const Group &other)
{
if (this != &other)
{
delete[] members;
cap = other.cap;
size = other.size;
members = new Person[cap];
for (int i = 0; i < size; i++)
{
members[i] = other.members[i];
}
}
return *this;
}
~Group()
{
delete[] members;
}

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

Person *members;
};

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

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

int main()
{
/*
Person p1("somename");
Person p1("somename2");
cout << p1<<p2;
*/
/*
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;
*/
/*
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 = 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);
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);
*/








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);
}

Binary file added 1/terminal/1
Binary file not shown.
Binary file added 2.zip
Binary file not shown.
Binary file added 2/.DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions 2/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "macos-clang-arm64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "macos-clang-arm64",
"compilerArgs": [
""
]
}
],
"version": 4
}
39 changes: 39 additions & 0 deletions 2/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"program": "${workspaceFolder}/output/main"
},
"osx": {
"MIMode": "lldb",
"miDebuggerPath": "lldb-mi",
"program": "${workspaceFolder}/output/main"
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"program": "${workspaceFolder}/output/main.exe"
},
"preLaunchTask": "build"
},
{
"name": "C/C++ Runner: Debug Session",
"type": "lldb",
"request": "launch",
"args": [],
"cwd": "/Users/hastiesmailzade/University/term 2/ap/workshop assignments/5th/AP_Lab_Git_Practice_S4022/2",
"program": "/Users/hastiesmailzade/University/term 2/ap/workshop assignments/5th/AP_Lab_Git_Practice_S4022/2/build/Debug/outDebug"
}
]
}
59 changes: 59 additions & 0 deletions 2/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "clang",
"C_Cpp_Runner.cppCompilerPath": "clang++",
"C_Cpp_Runner.debuggerPath": "lldb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
Loading