-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUserData.cpp
127 lines (100 loc) · 3.84 KB
/
UserData.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include <ctime>
#include <string>
#include "UserData.h"
UserData::UserData(std::string name, std::string dateOfBirth, std::string address, std::string phoneNumber,
std::string email, std::string username, std::string password, std::string role
) {
_strName = name;
_strDateOfBirth = dateOfBirth;
_iAge = userAge(dateOfBirth);
_strAddress = address;
_strPhoneNumber = phoneNumber;
_strEmail = email;
_strUserName = username;
_strPassword = password;
_strRole = role;
}
UserData::UserData() {
_strName = "";
_strDateOfBirth = "";
_iAge = 0;
_strAddress = "";
_strPhoneNumber = "";
_strEmail = "";
_strUserName = "";
_strPassword = "";
_strRole = "";
}
UserData::~UserData() {
_strName = "";
_strDateOfBirth = "";
_iAge = 0;
_strAddress = "";
_strPhoneNumber = "";
_strEmail = "";
_strUserName = "";
_strPassword = "";
_strRole = "";
}
int UserData::userAge(std::string dateOfBirth) const {
int iAge = 0;
time_t currentTime = time(0);
tm* pLocalTime = localtime(¤tTime);
int iCurrentDay = pLocalTime->tm_mday;
int iCurrentMonth = 1 + pLocalTime->tm_mon;
int iCurrentYear = 1900 + pLocalTime->tm_year;
//type string dateOfBirth DD/MM/YYYY
int iDayOfBirth = std::stoi(dateOfBirth.substr(0, 2));
int iMonthOfBirth = std::stoi(dateOfBirth.substr(3, 2));
int iYearOfBirth = std::stoi(dateOfBirth.substr(6, 4));
if (iMonthOfBirth > iCurrentMonth) {
iAge = iCurrentYear - iYearOfBirth - 1;
} else if (iMonthOfBirth < iCurrentMonth) {
iAge = iCurrentYear - iYearOfBirth;
} else {
if (iDayOfBirth > iCurrentDay) {
iAge = iCurrentYear - iYearOfBirth - 1;
} else {
iAge = iCurrentYear - iYearOfBirth;
}
}
return iAge;
}
std::string UserData::getName() const { return _strName; }
void UserData::setName(std::string name) { _strName = name; }
std::string UserData::getDateOfBirth() const { return _strDateOfBirth; }
void UserData::setDateOfBirth(std::string dateOfBirth) {
_strDateOfBirth = dateOfBirth;
_iAge = userAge(dateOfBirth);
}
int UserData::getAge() { return _iAge; }
std::string UserData::getAddress() const { return _strAddress; }
void UserData::setAddress(std::string address) { _strAddress = address; }
std::string UserData::getPhoneNumber() const { return _strPhoneNumber; }
void UserData::setPhoneNumber(std::string phoneNumber) { _strPhoneNumber = phoneNumber; }
std::string UserData::getEmail() const { return _strEmail; }
void UserData::setEmail(std::string email) { _strEmail = email; }
std::string UserData::getUserName() const { return _strUserName; }
void UserData::setUserName(std::string username) { _strUserName = username; }
std::string UserData::getPassword() const { return _strPassword; }
void UserData::setPassword(std::string password) { _strPassword = password; }
std::string UserData::getRole() const { return _strRole; }
// void UserData::setRole(std::string role) { _strRole = role; }
bool UserData::operator!=(const UserData& user) const {
return _strUserName != user._strUserName || _strPassword != user._strPassword || _strRole != user._strRole || _strName != user._strName || _strDateOfBirth != user._strDateOfBirth || _iAge != user._iAge || _strAddress != user._strAddress || _strPhoneNumber != user._strPhoneNumber || _strEmail != user._strEmail;
}
UserData& UserData::operator=(const UserData& user) {
if (this != &user) {
_strName = user._strName;
_strDateOfBirth = user._strDateOfBirth;
_iAge = user._iAge;
_strAddress = user._strAddress;
_strPhoneNumber = user._strPhoneNumber;
_strEmail = user._strEmail;
_strUserName = user._strUserName;
_strPassword = user._strPassword;
_strRole = user._strRole;
}
return *this;
}