-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuman.cpp
More file actions
70 lines (61 loc) · 1.25 KB
/
Human.cpp
File metadata and controls
70 lines (61 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Human.h"
#include<iostream>
char* Human::Gets()
{
char ch;
int n = 0;
char* str = nullptr;
while ((ch = getchar()) != '\n')
{
str = (char*)realloc(str, n + 1);
str[n] = ch;
n++;
}
str = (char*)realloc(str, n + 1);
str[n] = 0;
return str;
}
Human::Human()
{
Fio = nullptr;
}
Human::Human(const Human& CopyHuman)
{
this->Age = CopyHuman.Age;
this->Fio = (char*)malloc(strlen(CopyHuman.Fio) + 1);
strcpy_s(this->Fio, strlen(CopyHuman.Fio) + 1, CopyHuman.Fio);
}
Human& Human::operator=(const Human& CopyHuman)
{
if (this != &CopyHuman)
{
if (this->Fio != nullptr)
free(this->Fio);
this->Age = CopyHuman.Age;
this->Fio = (char*)malloc(strlen(CopyHuman.Fio) + 1);
strcpy_s(this->Fio, strlen(CopyHuman.Fio) + 1, CopyHuman.Fio);
}
return *this;
}
void Human::Vvod()
{
cout << "Vidit Fio:\n";
if (this->Fio != nullptr)
free(this->Fio);
this->Fio = Gets();
cout << "Vvedit vik:\n";
cin >> this->Age;
cin.ignore();
}
void Human::Show()
{
cout << "Fio:\t" << this->Fio << "\nAge:\t" << this->Age << "\n";
}
char* Human::Get_Fio()
{
return this->Fio;
}
Human::~Human()
{
free(this->Fio);
}