-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task2.cpp
53 lines (45 loc) · 937 Bytes
/
Task2.cpp
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
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
class human {
char *name;
char *surname;
int lenn, lens;
public:
human(char *pn, char *ps);
~human();
void show();
};
human::human(char *pn, char *ps) {
lenn = strlen(pn);
lens = strlen(ps);
name = (char *)malloc(lenn + 1);
surname = (char *)malloc(lens +1);
if (!name || !surname) exit(1);
strcpy(name, pn);
strcpy(surname, ps);
};
human::~human() {
free(name);
free(surname);
};
void human::show() {
cout << name << " " << surname
<< " - length: " << lenn + lens << endl;
};
int main() {
char nm1[25], snm1[25], nm2[25], snm2[25];
cout << "Enter first name and surname" << endl;
cin >> nm1 >> snm1;
cout << "Enter second name and surname" << endl;
cin >> nm2 >> snm2;
human s1(nm1, snm1), s2(nm2, snm2);
s1.show();
s2.show();
s2.~human();
s2 = s1;
s1.show();
s2.show();
return 0;
}