-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.cpp
More file actions
97 lines (78 loc) · 2.48 KB
/
user.cpp
File metadata and controls
97 lines (78 loc) · 2.48 KB
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
// user.cpp
#include "user.h"
#include "post.h"
int user::nextUserId = 1;
user::user() : currentFriendsCount(0), currentPostsCount(0), userId(nextUserId++) {
userName = "";
userPassword = "";
}
void user::setUserName(const string& receiveUserName) {
userName = receiveUserName;
}
void user::setUserPassword(const string& password) {
userPassword = password;
}
void user::setCurrentPostsCount(const int& receiveCurrentPostsCount) {
currentPostsCount = receiveCurrentPostsCount;
}
void user::setCurrentFriendsCount(const int& receiveCurrentFriendsCount) {
currentFriendsCount = receiveCurrentFriendsCount;
}
string user::getUserName() const {
return userName;
}
string user::getUserPassword() const {
return userPassword;
}
int user::getUserId() const {
return userId;
}
int user::getCurrentPostsCount() const {
return currentPostsCount;
}
int user::getCurrentFriendsCount() const {
return currentFriendsCount;
}
user::user(string receiveUserName, string receiveUserPassword)
: currentFriendsCount(0), currentPostsCount(0), userId(nextUserId++) {
userName = receiveUserName;
userPassword = receiveUserPassword;
}
void user::addFriend(user* receiveFriend) {
userFriends.insert(receiveFriend);
receiveFriend->userFriends.insert(this);
currentFriendsCount++;
receiveFriend->currentFriendsCount++;
}
void user::removeFriend(user* receiveFriend) {
userFriends.remove(receiveFriend);
receiveFriend->userFriends.remove(this);
currentFriendsCount--;
receiveFriend->currentFriendsCount--;
}
void user::displayFriends() {
cout << "Friends of " << userName << ": ";
listNode<user*>* tempTraversingPointer = userFriends.getHead();
while (tempTraversingPointer) {
cout << tempTraversingPointer->data->getUserName() << " ";
tempTraversingPointer = tempTraversingPointer->next;
}
cout << endl;
}
void user::createPost(post* receivePost) {
postsByUser.insert(receivePost);
currentPostsCount++;
}
void user::deletePost(post* receivePost) {
postsByUser.remove(receivePost);
currentPostsCount--;
}
void user::displayPosts() {
cout << "Posts by " << userName << ":" << endl;
listNode<post*>* tempTraversingPointer = postsByUser.getHead();
while (tempTraversingPointer) {
cout << "Post ID: " << tempTraversingPointer->data->getPostId() << " - " << tempTraversingPointer->data->getPostName() << endl;
tempTraversingPointer = tempTraversingPointer->next;
}
cout << endl;
}