Last active
June 29, 2016 20:52
-
-
Save Soulstorm50/0b6b51c3d2a13efa8811f9fed3d7b415 to your computer and use it in GitHub Desktop.
class Group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Adress.h" | |
Adress::Adress() :Adress(nullptr, nullptr, nullptr) | |
{ | |
} | |
Adress::Adress(char*home, char*street, char*city) | |
{ | |
SetHome(home); | |
SetStreet(street); | |
SetCity(city); | |
} | |
Adress::Adress(char*home, char*street) :Adress(home, street, nullptr){}; | |
Adress::Adress(char*home) :Adress(home, nullptr, nullptr){}; | |
Adress::~Adress() | |
{ | |
if (home) | |
{ | |
delete[]home; | |
home = nullptr; | |
} | |
if (street) | |
{ | |
delete[]street; | |
street = nullptr; | |
} | |
if (city) | |
{ | |
delete[]city; | |
city = nullptr; | |
} | |
} | |
char*Adress::GetHome()const | |
{ | |
if (home == nullptr) | |
return "no info"; | |
int leng = strlen(home) + 1; | |
char *copyHome = new char[leng]; | |
strcpy_s(copyHome, leng, home); | |
return copyHome; | |
} | |
char*Adress::GetStreet()const | |
{ | |
if (street == nullptr) | |
return "no info"; | |
int leng = strlen(street) + 1; | |
char *copyStreet = new char[leng]; | |
strcpy_s(copyStreet, leng, street); | |
return copyStreet; | |
} | |
char*Adress::GetCity()const | |
{ | |
if (city == nullptr) | |
return "no info"; | |
int leng = strlen(city) + 1; | |
char *copyCity = new char[leng]; | |
strcpy_s(copyCity, leng, city); | |
return copyCity; | |
} | |
void Adress::SetHome(char*home) | |
{ | |
if (this->home) | |
{ | |
delete[]this->home; | |
this->home = nullptr; | |
} | |
this->home = home; | |
} | |
void Adress::SetStreet(char*street) | |
{ | |
if (this->street) | |
{ | |
delete[]this->street; | |
this->street = nullptr; | |
} | |
this->street = street; | |
} | |
void Adress::SetCity(char*city) | |
{ | |
if (this->city) | |
{ | |
delete[]this->city; | |
this->city = nullptr; | |
} | |
this->city = city; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include<iostream> | |
using namespace std; | |
class Adress | |
{ | |
char*home; | |
char*street; | |
char*city; | |
public: | |
char*GetHome()const; | |
char*GetStreet()const; | |
char*GetCity()const; | |
void SetHome(char*home); | |
void SetStreet(char*street); | |
void SetCity(char*city); | |
Adress(); | |
Adress(char*home); | |
Adress(char*home, char*street); | |
Adress(char*home, char*street, char*city); | |
~Adress(); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Dob.h" | |
Dob::Dob() | |
{ | |
day = 0; | |
month = 0; | |
year = 0; | |
} | |
Dob::Dob(short day, short month, short year) | |
{ | |
SetYear(year); | |
SetMonth(month); | |
SetDay(day); | |
} | |
Dob::~Dob() | |
{ | |
} | |
short Dob::GetDay()const | |
{ | |
if (!day) | |
return 1; | |
return day; | |
} | |
short Dob::GetMonth()const | |
{ | |
if (!month) | |
return 1; | |
return month; | |
} | |
short Dob::GetYear()const | |
{ | |
if (!year) | |
return 1; | |
return year; | |
} | |
void Dob::SetDay(short day) | |
{ | |
if (day>0 && day <= AllowedDay()) | |
this->day = day; | |
else this->day = 1; | |
} | |
void Dob::SetMonth(short month) | |
{ | |
if (month > 0 && month <= 12) | |
this->month = month; | |
else this->month = 1; | |
} | |
void Dob::SetYear(short year) | |
{ | |
if (year < 2015) | |
this->year = year; | |
else this->year = 1; | |
} | |
short Dob::AllowedDay() | |
{ | |
short a; | |
bool b = (year % 4 == 0 && this->year % 100 != 0 || this->year % 400 == 0); | |
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) | |
a = 31; | |
if (month == 4 || month == 6 || month == 9 || month == 11); | |
a = 30; | |
if (month == 2 && b>0) | |
a = 29; | |
if (month == 2 && b == 0) | |
a = 28; | |
return a; | |
} | |
char*Dob::ShowDob() | |
{ | |
char*re = new char[250]; | |
char*temp = new char[250]; | |
_itoa_s(this->day, temp, 3, 10); | |
strcpy_s(re, strlen(temp) + 1, temp); | |
strcat_s(re, 250, "."); | |
_itoa_s(this->month, temp, 3, 10); | |
strcat_s(re, 250, temp); | |
strcat_s(re, 250, "."); | |
_itoa_s(this->year, temp, 5, 10); | |
strcat_s(re, 250, temp); | |
strcat_s(re, 250, ".\n"); | |
char*res = new char[strlen(re) + 1]; | |
strcpy_s(res, strlen(re) + 1, re); | |
return res; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include<iostream> | |
using namespace std; | |
class Dob | |
{ | |
short day; | |
short month; | |
short year; | |
short AllowedDay(); | |
public: | |
short GetDay()const; | |
short GetMonth()const; | |
short GetYear()const; | |
void SetDay(short day); | |
void SetMonth(short month); | |
void SetYear(short year); | |
Dob(); | |
Dob(short day, short month, short year); | |
~Dob(); | |
char*ShowDob(); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include"Group.h" | |
Group::Group() | |
{ | |
group_size = 0; | |
group_name = nullptr; | |
group_spec = nullptr; | |
course_num = nullptr; | |
students = nullptr; | |
} | |
Group::Group(const char*group_name, const char*group_spec, const char*course_num) | |
{ | |
SetName(group_name); | |
SetSpec(group_spec); | |
SetNum(course_num); | |
students = nullptr; | |
} | |
Group::~Group() | |
{ | |
if (students) | |
delete[]students; | |
if (group_name) | |
delete[]group_name; | |
group_name = nullptr; | |
if (group_spec) | |
delete[]group_spec; | |
group_spec = nullptr; | |
if (course_num) | |
delete[]course_num; | |
course_num = nullptr; | |
}; | |
void Group::SetName(const char*group_name) | |
{ | |
if (this->group_name) | |
delete[]this->group_name; | |
this->group_name = new char[strlen(group_name) + 1]; | |
strcpy_s(this->group_name, strlen(group_name) + 1, group_name); | |
} | |
void Group::SetSpec(const char*group_spec) | |
{ | |
if (this->group_spec) | |
delete[]this->group_spec; | |
this->group_spec = new char[strlen(group_spec) + 1]; | |
strcpy_s(this->group_spec, strlen(group_spec) + 1, group_spec); | |
} | |
void Group::SetNum(const char*course_num) | |
{ | |
if (this->course_num) | |
delete[]this->course_num; | |
this->course_num = new char[strlen(course_num) + 1]; | |
strcpy_s(this->course_num, strlen(course_num) + 1, course_num); | |
} | |
Group::Group(ushort group_size) | |
{ | |
if (!group_size) | |
return; | |
SetName("No group name"); | |
SetSpec("Not group spec"); | |
SetNum("No course number"); | |
//this->group_size = group_size; | |
Student *temp; | |
for (int i = 0; i < group_size; i++) | |
{ | |
temp = new Student("No phone", "No name", "No secondname", "No lastname"); | |
AddStudToGroup(*temp); | |
} | |
} | |
char*Group::Getter(char*str)const | |
{ | |
char*temp = new char[strlen(str) + 1]; | |
strcpy_s(temp, strlen(str) + 1, str); | |
return temp; | |
} | |
char*Group::GetGroup_name()const | |
{ | |
return Getter(this->group_name); | |
} | |
char*Group::GetGroup_spec()const | |
{ | |
return Getter(this->group_spec); | |
} | |
char*Group::GetCourse_num()const | |
{ | |
return Getter(this->course_num); | |
} | |
void Group::AddStudToGroup(Student & student) | |
{ | |
Student**buf = new Student*[group_size + 1]; | |
if ((group_size + 1) < 30) | |
for (int i = 0; i < group_size; i++) | |
buf[i] = (this->students[i]); | |
buf[group_size] = &student; | |
if (this->students) | |
delete[]this->students; | |
this->students = buf; | |
group_size++; | |
} | |
Group::Group(Group & other) | |
{ | |
this->group_name = other.GetGroup_name(); | |
this->group_spec = other.GetGroup_spec(); | |
this->course_num = other.GetCourse_num(); | |
this->group_size = 0; | |
for (int i = 0; i < other.group_size; i++) | |
AddStudToGroup(*other.students[i]); | |
} | |
char*Group::GroupList() | |
{ | |
SortStud(); | |
ushort capasity = 250; | |
char*temp = new char[capasity]; | |
strcpy_s(temp, strlen(GroupInfo()) + 1, GroupInfo()); | |
for (int i = 0; i < group_size; i++) | |
{ | |
if (capasity < strlen(temp) + 50) | |
capasity += 100; | |
char*a = new char[3]; | |
_itoa_s(i + 1, a, 3, 10); | |
strcat_s(temp, capasity, a); | |
strcat_s(temp, capasity, ")"); | |
strcat_s(temp, capasity, (*students[i]).FullName()); | |
strcat_s(temp, capasity, "\n"); | |
} | |
char*res = new char[strlen(temp) + 1]; | |
strcpy_s(res, strlen(temp) + 1, temp); | |
return res; | |
} | |
char*Group::GroupInfo() | |
{ | |
char*temp = new char[250]; | |
strcpy_s(temp, strlen(GetGroup_spec()) + 1, GetGroup_spec()); | |
strcat_s(temp, 250, ","); | |
strcat_s(temp, 250, GetGroup_name()); | |
strcat_s(temp, 250, "-"); | |
strcat_s(temp, 250, GetCourse_num()); | |
strcat_s(temp, 250, ":\n"); | |
char *res = new char[strlen(temp) + 1]; | |
res = temp; | |
return res; | |
} | |
void Group::GroupUnion(Group &some) | |
{ | |
if (!some.group_size) | |
return; | |
if (this->group_size + some.group_size > 30) | |
return; | |
for (int i = 0; i < some.group_size; i++) | |
AddStudToGroup(*some.students[i]); | |
} | |
void Group::SortStud() | |
{ | |
if (group_size < 2) | |
return; | |
char * name1 = new char[255]; | |
char * name2 = new char[255]; | |
for (int i = 0; i < group_size - 1; i++) | |
{ | |
name1 = students[i]->GetLastname(); | |
name2 = students[i + 1]->GetLastname(); | |
if (_stricmp(name1, name2) < 0) | |
{ | |
Student*temp = students[i]; | |
students[i] = students[i + 1]; | |
students[i + 1] = temp; | |
} | |
} | |
} | |
void Group::StudDelete(ushort stud_num) | |
{ | |
if (group_size < stud_num) | |
return; | |
Student**temp = new Student*[group_size - 1]; | |
for (int i = 0; i<stud_num - 1; i++) | |
{ | |
temp[i] = students[i]; | |
} | |
for (int j = stud_num - 1; j < group_size; j++) | |
temp[j] = students[j + 1]; | |
group_size--; | |
delete[]students; | |
students = temp; | |
} | |
void Group::StudMove(Group &target, ushort stud_num) | |
{ | |
if (this->group_size < stud_num) | |
return; | |
target.AddStudToGroup(*this->students[stud_num - 1]); | |
StudDelete(stud_num); | |
} | |
Group& Group::operator=(Group&other) | |
{ | |
SetName(other.group_name); | |
SetSpec(other.group_spec); | |
SetNum(other.course_num); | |
this->group_size = other.group_size; | |
for (int i = 0; i < other.group_size; i++) | |
AddStudToGroup(*other.students[i]); | |
return *this; | |
} | |
char*Group:: operator[](ushort num) | |
{ | |
return (*students[num - 1]).FullName(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include<iostream> | |
#include"Student.h" | |
typedef unsigned short ushort; | |
using namespace std; | |
class Group | |
{ | |
Student**students; | |
ushort group_size; | |
char*group_name; | |
char*group_spec; | |
char*course_num; | |
char*Getter(char*str)const; | |
void SetSize(ushort group_size); | |
public: | |
void SetName(const char* group_name); | |
void SetSpec(const char*group_spec); | |
void SetNum(const char*course_num); | |
ushort GetSize() const{ return this->group_size; } | |
char*GetGroup_name()const; | |
char*GetGroup_spec()const; | |
char*GetCourse_num()const; | |
Group(); | |
Group(const char*group_name, const char*group_spec, const char*course_num); | |
Group(ushort group_size); | |
Group(Group & other); | |
~Group(); | |
void AddStudToGroup(Student & student); | |
char*GroupList(); | |
char*GroupInfo(); | |
void GroupUnion(Group &some); | |
void SortStud(); | |
void StudMove(Group &target, ushort stud_num); | |
void StudDelete(ushort stud_num); | |
Group& operator=(Group&other); | |
char* operator[](ushort num); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Student.h" | |
#include"Dob.h" | |
#include"Adress.h" | |
#include<string.h> | |
Student::Student(char* phone, char*name, char*secondname, char*lastname) | |
{ | |
SetPhone(phone); | |
SetName(name); | |
SetSecondname(secondname); | |
SetLastname(lastname); | |
} | |
Student::Student() :Student("0934229968", "ivan", "ivanovich", "ivanov"){}; | |
Student::~Student() | |
{ | |
if (phone) | |
{ | |
delete[]phone; | |
phone = nullptr; | |
} | |
if (name) | |
{ | |
delete[]name; | |
name = nullptr; | |
} | |
if (secondname) | |
{ | |
delete[]secondname; | |
secondname = nullptr; | |
} | |
if (lastname) | |
{ | |
delete[]lastname; | |
lastname = nullptr; | |
} | |
} | |
char* Student::GetPhone()const | |
{ | |
unsigned int lenght = strlen(this->phone) + 1; | |
char*copyPhone = new char[lenght]; | |
strcpy_s(copyPhone, lenght, this->phone); | |
return copyPhone; | |
} | |
char* Student::GetName()const | |
{ | |
unsigned int lenght = strlen(this->name) + 1; | |
char*copyName = new char[lenght]; | |
strcpy_s(copyName, (strlen(this->name) + 1), this->name); | |
return copyName; | |
} | |
char* Student::GetSecondname()const | |
{ | |
unsigned int lenght = strlen(this->secondname) + 1; | |
char*copySecondname = new char[lenght]; | |
strcpy_s(copySecondname, lenght, this->secondname); | |
return copySecondname; | |
} | |
char* Student::GetLastname()const | |
{ | |
unsigned int lenght = strlen(this->lastname) + 1; | |
char*copyLastname = new char[lenght]; | |
strcpy_s(copyLastname, lenght, this->lastname); | |
return lastname; | |
} | |
char*Student::FullName() | |
{ | |
char *temp = new char[250]; | |
strcpy_s(temp, strlen(GetName()) + 1, GetName()); | |
strcat_s(temp, 250, " "); | |
strcat_s(temp, 250, GetSecondname()); | |
strcat_s(temp, 250, " "); | |
strcat_s(temp, 250, GetLastname()); | |
strcat_s(temp, 250, " "); | |
char*res = new char[strlen(temp) + 1]; | |
strcpy_s(res, strlen(temp) + 1, temp); | |
return res; | |
} | |
char* Student::GetExams() | |
{ | |
char*res = new char[250]; | |
char *temp = new char[3]; | |
int lenght = 0; | |
strcpy_s(res, 7, "Exams:"); | |
for (int i = 0; i<examsSize; i++) | |
{ | |
_itoa_s(exams[i], temp, 3, 10); | |
strcat_s(res, 250, temp); | |
strcat_s(res, 250, ","); | |
} | |
return res; | |
} | |
char*Student::Get1Exam(ushort index) | |
{ | |
char*temp = new char[3]; | |
_itoa_s(exams[index - 1], temp, 3, 10); | |
char*res = new char[strlen(temp) + 1]; | |
strcpy_s(res, strlen(temp) + 1, temp); | |
return res; | |
} | |
void Student::SetPhone(char* phone) | |
{ | |
if (this->phone) | |
delete[]this->phone; | |
this->phone = nullptr; | |
this->phone = new char[strlen(phone) + 1]; | |
strcpy_s(this->phone, (strlen(phone) + 1), phone); | |
} | |
void Student::SetName(char*name) | |
{ | |
if (this->name) | |
delete[]this->name; | |
this->name = nullptr; | |
this->name = new char[strlen(name) + 1]; | |
strcpy_s(this->name, (strlen(name) + 1), name); | |
} | |
void Student::SetSecondname(char*secondname) | |
{ | |
if (this->secondname) | |
delete[]this->secondname; | |
this->secondname = nullptr; | |
this->secondname = new char[strlen(secondname) + 1]; | |
strcpy_s(this->secondname, (strlen(secondname) + 1), secondname); | |
} | |
void Student::SetLastname(char*lastname) | |
{ | |
if (this->lastname) | |
delete[]this->lastname; | |
this->lastname = nullptr; | |
this->lastname = new char[strlen(lastname) + 1]; | |
strcpy_s(this->lastname, (strlen(lastname) + 1), lastname); | |
} | |
void Student::SetBirthday(Dob birthday) | |
{ | |
this->birthday = birthday; | |
} | |
void Student::SetSomeGrade(ushort*&arr, ushort &size, ushort grade) | |
{ | |
ushort*temp = new ushort[size + 1]; | |
for (int i = 0; i < size; i++) | |
temp[i] = arr[i]; | |
temp[size] = grade; | |
delete[]arr; | |
arr = temp; | |
size++; | |
} | |
void Student::SetExam(ushort grade) | |
{ | |
SetSomeGrade(exams, examsSize, grade); | |
} | |
void Student::SetCourse(ushort grade) | |
{ | |
SetSomeGrade(courses, coursesSize, grade); | |
} | |
void Student::SetTest(ushort grade) | |
{ | |
SetSomeGrade(tests, testsSize, grade); | |
} | |
char*Student::GetBirthday() | |
{ | |
return birthday.ShowDob(); | |
} | |
Student Student::BasicStudent() | |
{ | |
Student x; | |
x.phone = "No phone"; | |
x.name = "No name"; | |
x.secondname = "No secondname"; | |
x.lastname = "No lastname"; | |
return x; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include<string.h> | |
#include <iostream> | |
#include"Dob.h" | |
#include"Adress.h" | |
using namespace std; | |
typedef unsigned short ushort; | |
class Student | |
{ | |
char*phone; | |
char*name; | |
char*secondname; | |
char*lastname; | |
Dob birthday; | |
ushort*exams; | |
ushort*courses; | |
ushort*tests; | |
ushort examsSize = 0; | |
ushort coursesSize = 0; | |
ushort testsSize = 0; | |
public: | |
char *GetPhone()const; | |
char *GetName()const; | |
char *GetSecondname()const; | |
char *GetLastname()const; | |
char*Get1Exam(ushort index); | |
char* GetExams(); | |
char* GetBirthday(); | |
char*FullName(); | |
Student BasicStudent(); | |
void SetPhone(char* phone); | |
void SetName(char*name); | |
void SetSecondname(char*secondname); | |
void SetLastname(char*lastname); | |
void SetBirthday(Dob birthday); | |
void SetSomeGrade(ushort*&arr, ushort &size, ushort grade); | |
void SetExam(ushort grade); | |
void SetCourse(ushort grade); | |
void SetTest(ushort grade); | |
Student(); | |
Student(char* phone, char*name, char*secondname, char*lastname); | |
~Student(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment