93 lines
2.3 KiB
C++
93 lines
2.3 KiB
C++
#include"person.h"
|
|
#include"help.h"
|
|
#include<iostream>
|
|
|
|
/*Person::Person():
|
|
name(nullptr),
|
|
numRel(0),
|
|
day(0),
|
|
month(0),
|
|
year(0),
|
|
isMale(true)
|
|
{}*/
|
|
|
|
Person::Person(const char* Name, unsigned char Day, unsigned char Month, short Year, bool IsMale) :
|
|
numRel(0),
|
|
day(Day),
|
|
month(Month),
|
|
year(Year),
|
|
isMale(IsMale)
|
|
{
|
|
name = new char[strLen(Name) + 1];
|
|
strCopy(name, Name);
|
|
}
|
|
|
|
|
|
Person& Person::operator=(const Person &other)
|
|
{
|
|
if (&other!=this)
|
|
{
|
|
rename(other.name);
|
|
numRel = other.numRel;
|
|
isMale = other.isMale;
|
|
day = other.day;
|
|
month = other.month;
|
|
year = other.year;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
Person::~Person()
|
|
{
|
|
delete[] name;
|
|
}
|
|
|
|
|
|
bool Person::operator==(const Person &other)const
|
|
{
|
|
return strComp(name, other.name) && isMale == other.isMale && (day == other.day || !day || !other.day) && (month == other.month || !month || !other.month) && (year == other.year || !year || !other.year);
|
|
}
|
|
|
|
|
|
void Person::save(std::ofstream &file)const
|
|
{
|
|
//
|
|
char nameLen = strLen(name);
|
|
file.write(reinterpret_cast<char*>(&nameLen), sizeof(nameLen));
|
|
file.write(name, nameLen * sizeof(*name));
|
|
file.write(reinterpret_cast<const char*>(&numRel), sizeof(numRel));
|
|
file.write(reinterpret_cast<const char*>(&isMale), sizeof(isMale));
|
|
file.write(reinterpret_cast<const char*>(&day), sizeof(day));
|
|
file.write(reinterpret_cast<const char*>(&month), sizeof(month));
|
|
file.write(reinterpret_cast<const char*>(&year), sizeof(year));
|
|
}
|
|
|
|
void Person::load(std::ifstream &file)
|
|
{
|
|
char nameLen;
|
|
file.read((char*)&nameLen, sizeof(nameLen));
|
|
|
|
name = new char[nameLen + 1];
|
|
file.read(name, nameLen * sizeof(*name));
|
|
name[nameLen] = '\0';
|
|
|
|
file.read(reinterpret_cast<char*>(&numRel), sizeof(numRel));
|
|
file.read(reinterpret_cast<char*>(&isMale), sizeof(isMale));
|
|
file.read(reinterpret_cast<char*>(&day), sizeof(day));
|
|
file.read(reinterpret_cast<char*>(&month), sizeof(month));
|
|
file.read(reinterpret_cast<char*>(&year), sizeof(year));
|
|
}
|
|
|
|
void Person::rename(const char* newName)
|
|
{
|
|
delete[] name;
|
|
name = new char[strLen(newName) + 1];
|
|
strCopy(name, newName);
|
|
}
|
|
|
|
void Person::print()const
|
|
{
|
|
std::cout << name << "\nBirthday: " << (int)day << "." << (int)month << "." << year << "\nSex: ";
|
|
std::cout << (isMale ? "Male\n\n" : "Female\n\n");
|
|
}
|