-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerson.cpp
66 lines (53 loc) · 910 Bytes
/
Person.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
54
55
56
57
58
59
60
61
62
63
64
65
66
#define _CRT_SECURE_NO_WARNINGS
#include "Person.h"
#include <string.h>
#include <iostream>
using namespace std;
//Default C'tor
Person::Person()
{
m_id = 0;
m_name = NULL;
}
//C'tor
Person::Person(const char* name, int id) : m_name(NULL)
{
SetId(id);
SetName(name);
}
//Copy C'tor
Person::Person(const Person& other) : m_name(NULL)
{
SetId(other.GetId());
SetName(other.GetName());
}
//Deletes the dynamic assignment
Person::~Person()
{
delete m_name;
}
//Set new name
void Person::SetName(const char* newName)
{
if (this->m_name != nullptr)
{
delete m_name;
}
m_name = new char[strlen(newName) + 1];
strcpy(m_name, newName);
}
//Set new ID
void Person::SetId(int newId)
{
m_id = newId;
}
//Return name
char* Person::GetName() const
{
return m_name;
}
//Return ID
int Person::GetId() const
{
return m_id;
}