blob: 3ab4ab453f071197adf44a01a421cf969786853f (
plain) (
blame)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include "InformaticsStudent.h"
void InformaticsStudent::CopyFrom(const InformaticsStudent& other)
{
int len = strlen(other.name);
name = new char[len + 1];
strcpy(name, other.name); //copy name
fn = other.fn; //copy fn
}
void InformaticsStudent::Free()
{
delete[] name;
fn = 0;
}
InformaticsStudent::InformaticsStudent()
{
name = nullptr;
fn = 0;
}
InformaticsStudent::InformaticsStudent(const char* name, int fn)
{
setName(name);
setFn(fn);
}
InformaticsStudent::InformaticsStudent(const InformaticsStudent& other)
{
CopyFrom(other); //копирам от другия обект(няма нужда да трия памет от себе си, понже това е конструктор и обекта сега се създава)
}
InformaticsStudent& InformaticsStudent::operator=(const InformaticsStudent& other)
{
if (this != &other)
{
Free(); //трия своята памет
CopyFrom(other); // копирам от другия обект
}
return *this;
}
InformaticsStudent::~InformaticsStudent()
{
Free();
}
// BIG 4 ends here
void InformaticsStudent::setName(const char* name)
{
delete[] name; //трием данните, които са били тук.
int len = strlen(name);
if (hasDigits(name, len))
{
this->name[0] = '\0';
return;
}
this->name = new char[len + 1];
strcpy(this->name, name);
}
void InformaticsStudent::setFn(int fn)
{
if (fn < 45000 || fn >45999)
fn = 45000;
this->fn = fn;
}
const InformaticsStudent::char* getName() const
{
return name;
}
int InformaticsStudent::getFn() const
{
return fn;
}
void printStudent()
{
cout << name << " fn: " << fn << endl;
}
|