Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- class Human {
- public:
- Human();
- Human(string, long, char);
- ~Human();
- void setName(string);
- void setPassport(long);
- void setGender(char);
- void add(Human*);
- void print();
- private:
- string name;
- long passport;
- char gender;
- Human **siblings;
- int n;
- };
- Human::Human() {
- n = 0;
- siblings = NULL;
- }
- Human::Human(string name, long passport, char gender) {
- n = 0;
- siblings = NULL;
- this->name = name;
- this->passport = passport;
- this->gender = gender;
- }
- Human::~Human() {
- }
- void Human::setName(string name) {
- this->name = name;
- }
- void Human::setPassport(long passport) {
- this->passport = passport;
- }
- void Human::setGender(char gender) {
- this->gender = gender;
- }
- void Human::add(Human* a) {
- if (n == 0) {
- siblings = new Human*;
- siblings[0] = a;
- }
- else {
- Human **temp = new Human*;
- temp[0] = new Human[n];
- for (int i = 0; i < n; i++) {
- temp[0][i].name = siblings[0][i].name;
- temp[0][i].passport = siblings[0][i].passport;
- temp[0][i].gender = siblings[0][i].gender;
- }
- delete[] siblings[0];
- delete[] siblings;
- siblings = new Human*;
- siblings[0] = new Human[n + 1];
- for (int i = 0; i < n; i++) {
- siblings[0][i].name = temp[0][i].name;
- siblings[0][i].passport = temp[0][i].passport;
- siblings[0][i].gender = temp[0][i].gender;
- }
- siblings[0][n].name = a->name;
- siblings[0][n].gender = a->gender;
- siblings[0][n].passport = a->passport;
- }
- n++;
- }
- void Human::print() {
- cout << "Имя: " << name << endl
- << "Пол: " << gender << endl
- << "Паспорт: " << passport << endl
- << "-------------" << endl;
- for (int i = 0; i < n; i++) {
- siblings[0][i].print();
- }
- }
- int main() {
- setlocale(LC_ALL, "");
- Human mom("Мать", 1, 'Ж');
- Human dad("Отец", 2, 'М');
- Human son("Сын", 3, 'М');
- mom.add(&son);
- dad.add(&son);
- mom.print();
- cout << "**************************" << endl;
- dad.print();
- cout << "**************************" << endl;
- Human waifu;
- waifu.setName("Жена сына");
- waifu.setPassport(4);
- waifu.setGender('Ж');
- Human gson;
- gson.setName("Внук");
- gson.setPassport(5);
- gson.setGender('М');
- waifu.add(&gson);
- son.add(&gson);
- son.print();
- cout << "**************************" << endl;
- waifu.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement