-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task4.cpp
52 lines (44 loc) · 867 Bytes
/
Task4.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
// 2018556502 Muhammed Ali ARICI
// 2019556461 Mahmut Can ÇINGI
// 2020556061 Emre ULUSOY
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
class date {
char *p;
public:
date(char *s);
~date() {
cout << "Destructing" << endl;
}
char *get() { return p; }
friend void cleaner(date obj) { delete obj.p; } // Delete [] p function.
};
date::date(char *s) {
int l;
l = strlen(s) + 1;
p = new char[l];
if (!p) {
cout << "Allocation error" << endl;
exit(1);
}
strcpy(p, s);
}
void show(date x) {
char *s;
s = x.get();
cout << s << endl;
}
int main() {
char sd[10]= "04/06/21";
char xd[10]= "00/00/00";
date sdate(sd);
date xdate(xd);
show(sdate);
show(xdate);
xdate = sdate;
cout << sdate.get() << " " << xdate.get() << endl;
cleaner(xdate); // Delete [] p
return 0;
}