-
Notifications
You must be signed in to change notification settings - Fork 1
/
Member.h
68 lines (63 loc) · 2.35 KB
/
Member.h
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
/**
*hidden file of class Member
*Authors Alexey Titov and Shir Bentabou
*Version 1.0
**/
#pragma once
//libraries
#include <iostream>
#include <vector>
using namespace std;
extern int cnt; //global variable for all files
//This class represents a member in the social media/
class Member{
private:
int numfollowers; //num of followers the member has
int numfollowing; //num of people the member is following
vector <Member*> following; //list of people the member is following
vector <Member*> followers; //list of people that are following the member
public:
//This is the class constructor. Sets values to 0.
Member(){
this->numfollowers=0;
this->numfollowing=0;
cnt++;
}
//Destructor for a member object
~Member(){
cnt--;
//First we erase ourselves from the 'followers' of every member we are following.
for (int i=0; i<this->following.size(); i++)
{
this->following[i]->delFollower();
for (int j=0;j<this->following[i]->followers.size();j++)
if (this==this->following[i]->followers[j])
{
this->following[i]->followers.erase(this->following[i]->followers.begin()+j);
break;
}
}
//Now, we make every member that follows us - unfollow us by decreasing number of following and erasing ourselves from their following list.
for (int j=0;j<this->followers.size();j++)
{
this->followers[j]->numfollowing--;
for(int i=0;i<this->followers[j]->following.size();i++)
if(this==this->followers[j]->following[i])
{
this->followers[j]->following.erase(this->followers[j]->following.begin()+i);
break;
}
}
//delete
this->following.clear();
this->followers.clear();
}
void follow(Member &m);
void unfollow(Member &m);
int numFollowers();
int numFollowing();
static int count();
private:
void addFollower();
void delFollower();
};