#include"person.h" #include"help.h" #include /*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(&nameLen), sizeof(nameLen)); file.write(name, nameLen * sizeof(*name)); file.write(reinterpret_cast(&numRel), sizeof(numRel)); file.write(reinterpret_cast(&isMale), sizeof(isMale)); file.write(reinterpret_cast(&day), sizeof(day)); file.write(reinterpret_cast(&month), sizeof(month)); file.write(reinterpret_cast(&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(&numRel), sizeof(numRel)); file.read(reinterpret_cast(&isMale), sizeof(isMale)); file.read(reinterpret_cast(&day), sizeof(day)); file.read(reinterpret_cast(&month), sizeof(month)); file.read(reinterpret_cast(&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"); }