Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct date {
- int day_;
- int month_;
- int year_;
- };
- class person {
- public:
- person(const int id, const char* last_name, const char* first_name, const char* middle_name, const date birthday) : id_(id), last_name_(new char[strlen(last_name) + 1]), first_name_(new char[strlen(first_name) + 1]), middle_name_(new char[strlen(middle_name) + 1]), birthday_(birthday) {
- strcpy(last_name_, last_name);
- strcpy(first_name_, first_name);
- strcpy(middle_name_, middle_name);
- number_person_++;
- }
- person() : person(111111, "Ivanov", "Ivan", "Ivanovich", { 1,1,1993 }) {}
- person(const person& other) : person(other.id_, other.last_name_, other.first_name_, other.middle_name_, other.birthday_) {}
- person& operator=(const person& other) {
- if (this != &other) {
- id_ = other.id_;
- birthday_ = other.birthday_;
- delete[] last_name_;
- last_name_ = new char[strlen(other.last_name_) + 1];
- strcpy(last_name_, other.last_name_);
- delete[] first_name_;
- first_name_ = new char[strlen(other.first_name_) + 1];
- strcpy(first_name_, other.first_name_);
- delete[] middle_name_;
- middle_name_ = new char[strlen(other.middle_name_) + 1];
- strcpy(middle_name_, other.middle_name_);
- }
- return *this;
- }
- void print() {
- cout << last_name_ << " " << first_name_ << " " << middle_name_ << ", " << birthday_.day_ << '.' << birthday_.month_ << '.' << birthday_.year_ << ", id - " << id_ << endl;
- }
- static int get_number_person() {
- return number_person_;
- }
- ~person() {
- delete[] last_name_;
- delete[] first_name_;
- delete[] middle_name_;
- number_person_--;
- }
- void set_id(const int id) {
- id_ = id;
- }
- void set_last_name(const char* last_name) {
- delete[] last_name_;
- last_name_ = new char[strlen(last_name) + 1];
- strcpy(last_name_, last_name);
- }
- void set_first_name(const char* first_name) {
- delete[] first_name_;
- first_name_ = new char[strlen(first_name) + 1];
- strcpy(first_name_, first_name);
- }
- void set_middle_name(const char* middle_name) {
- delete[] middle_name_;
- middle_name_ = new char[strlen(middle_name) + 1];
- strcpy(middle_name_, middle_name);
- }
- void set_birthday(const int day, const int month, const int year) {
- birthday_.day_ = day;
- birthday_.month_ = month;
- birthday_.year_ = year;
- }
- private:
- int id_; // идентификационный номер
- char* last_name_; // фамилия
- char* first_name_; // имя
- char* middle_name_; // отчество
- date birthday_; // дата рождения
- static int number_person_;
- };
- class flat {
- flat() : residents_count_(0), max_count_(5), residents_(new person[max_count_]) {}
- flat(const flat& other) : residents_count_(other.residents_count_), max_count_(other.max_count_), residents_(new person[max_count_]) {
- for (int i = 0; i < residents_count_; i++) {
- residents_[i] = other.residents_[i];
- }
- }
- void add_resident(const person& new_resident) {
- if (residents_count_ == max_count_) {
- person* temp = new person[max_count_ * 2];
- for (int i = 0; i < residents_count_; i++) {
- temp[i] = residents_[i];
- }
- delete[] residents_;
- residents_ = temp;
- max_count_ *= 2;
- }
- residents_[residents_count_] = new_resident;
- residents_count_++;
- }
- // реализовать методы для удаления жильца и вывода информации по жильцу
- private:
- int residents_count_;
- int max_count_;
- person* residents_;
- };
- int person::number_person_ = 0;
- int main() {
- person p1(222222, "Petrov", "Petr", "Petrovich", { 23,8,1997 });
- person p2;
- person p3(p1);
- p1.print();
- p2.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement