验证中...
Languages: C/C++
Categories: 其他
Latest update 2019-09-11 21:22
GroupCRJ.cpp
Raw Copy
#include "GroupCRJ.h"
Group::Group(Serve* _serveOfThis, string _name = " ") :serveOfThis(_serveOfThis), name(_name) {}
Group::~Group() {}
GroupCRJ.h
Raw Copy
#ifndef GROUPCRJ_H
#define GROUPCRJ_H
#pragma once
#include <iostream>
#include <vector>
#include <string>
#include "memberCRJ.h"
#include "ServeCRJ.h"
using namespace std;
class Group {
friend class QQMember;
protected:
int ID;
string name;
Serve* serveOfThis;
virtual void disband()=0;
public:
Group(Serve* _serveOfThis, string _name);
virtual ~Group();
};
#endif
memberCRJ.cpp
Raw Copy
#include "memberCRJ.h"
Member::Member(Serve* _serveOfThis, string _name = " ") :serveOfThis(_serveOfThis), name(_name) {}
Member::~Member() {}
void Member::setBirthDate() {
cout << "输入出生月日" << endl;
getline(cin, birthDate);
cout << "设置完成" << endl;
}
void Member::setLocation() {
cout << "输入所在地" << endl;
getline(cin, location);
cout << "设置完成" << endl;
}
void Member::enquireBirthDate() {
cout << "用户生日:" << birthDate << endl;
}
void Member::enquiretAge() {
cout << "账号T龄:" << tAge << endl;
}
void Member::enquireLocation() {
cout << "用户所在地:" << location << endl;
}
memberCRJ.h
Raw Copy
#ifndef MEMBERCRJ_H
#define MEMBERCRJ_H
#pragma once
#include <iostream>
#include <vector>
#include <string>
#include "ServeCRJ.h"
using namespace std;
class Serve;
class Member{
friend class Group;
protected:
int ID;
string name, birthDate, tAge, location;
Serve* serveOfThis;
public:
Member(Serve* _serveOfThis, string _name);
virtual ~Member();
virtual void addFriend() = 0;
virtual void deleteFriend() = 0;
void setBirthDate();
void setLocation();
virtual void enquireFriendsList() = 0;
void enquireBirthDate();
virtual void enquiretAge();
void enquireLocation();
virtual void joinInGroup() = 0;
virtual void quitGroup() = 0;
virtual void createGroup() = 0;
virtual void enquireGroupList() = 0;
};
#endif
QQGroupCRJ.cpp
Raw Copy
#include "QQGroupCRJ.h"
QQGroup::QQGroup(Serve* _serveOfThis, string _name, QQMember* _groupOwner) :Group(_serveOfThis, _name), groupOwner(_groupOwner) {
ID = serveOfThis->numberOfQQGroups() + 1000;
serveOfThis->addNewQQGroup(this);
membersList.push_back(groupOwner);
groupAdministratorsList.push_back(groupOwner);
}
QQGroup::~QQGroup() {}
bool QQGroup::admitNewMember(QQMember* newMember) {
membersList.push_back(newMember);
}
bool QQGroup::kickMemberOut(QQMember* theMember) {
for (auto It = membersList.begin() + 1; It < membersList.end(); It++) {
if ((*It) == theMember) {
membersList.erase(It);
return true;
}
}
return false;
}
void QQGroup::enquireGroupMember() {
for (auto It = membersList.begin(); It < membersList.end(); It++) {
cout << "群成员昵称:" << (*It)->name << " 群成员ID:" << (*It)->ID << endl;
}
}
void QQGroup::enquireGroupOwner() {
cout << "群主昵称:" << membersList[0]->name << "群主ID:" << membersList[0]->ID << endl;
}
void QQGroup::setGroupAdministrator(QQMember* newGroupAdministrator) {
groupAdministratorsList.push_back(newGroupAdministrator);
}
void QQGroup::disband() {
for (auto It = membersList[0]->hisGroups.begin(); It < membersList[0]->hisGroups.end(); It++) {
if (*(It) == this) {
membersList[0]->hisGroups.erase(It);
break;
}
}
for (auto It = membersList[0]->groupsList.begin(); It < membersList[0]->groupsList.end(); It++) {
if (*(It) == this) {
membersList[0]->groupsList.erase(It);
break;
}
}
for (auto It = membersList.begin() + 1; It < membersList.end(); It++) {
for (auto It2 = (*It)->groupsList.begin(); It2 < (*It)->groupsList.end(); It2++) {
if ((*It2) == this) {
(*It)->groupsList.erase(It2);
break;
}
}
}
delete serveOfThis->allQQGroups[ID - 1000];
serveOfThis->allQQGroups[ID - 1000] = nullptr;
}
QQGroupCRJ.h
Raw Copy
#define QQGROUP_H
#ifndef QQGROUP_H
#pragma once
#include "GroupCRJ.h"
#include "QQmemberCRJ.h"
class QQGroup :public Group {
friend class QQMember;
protected:
QQMember* groupOwner;
vector<QQMember*> membersList;
vector<QQMember*> groupAdministratorsList;
public:
QQGroup(Serve* _serveOfThis, string _name, QQMember* _groupOwner);
~QQGroup();
bool admitNewMember(QQMember* newMember);
bool kickMemberOut(QQMember* theMember);
void enquireGroupMember();
void enquireGroupOwner();
void setGroupAdministrator(QQMember*);
void disband();
};
#endif
QQmemberCRJ.cpp
Raw Copy
#include "QQmemberCRJ.h"
QQMember::QQMember(Serve* _serveOfThis, string _name) :Member(_serveOfThis, _name) {
ID = serveOfThis->numberOfQQMembers() + 10000;
serveOfThis->addNewQQMember(this);
}
QQMember::~QQMember() {}
bool QQMember::isGroupAdministrator(QQGroup* theGroup) {
for (auto It = theGroup->groupAdministratorsList.begin(); It < theGroup->groupAdministratorsList.end(); It++) {
if (*It == this) return true;
}
return false;
}
bool QQMember::isGroupOwner(QQGroup* theGroup) {
if (theGroup->groupOwner == this) return true;
else return false;
}
void QQMember::enquiretAge() {
cout << "账号Q龄:" << tAge << endl;
}
void QQMember::addFriend() {
int IDOfNewFriend;
cout << "输入添加的ID" << endl;
cin >> IDOfNewFriend;
if ((IDOfNewFriend - 10000) >= 0 && (IDOfNewFriend - 10000) < serveOfThis->numberOfQQMembers && IDOfNewFriend != this->ID) {
if (serveOfThis->allQQMembers[IDOfNewFriend - 10000] != nullptr) {
friendsList.push_back(serveOfThis->allQQMembers[IDOfNewFriend - 10000]);
cout << "添加成功或已是好友" << endl;
}
else cout << "查无此人" << endl;
}
else if (IDOfNewFriend == this->ID) cout << "不允许添加自己为好友" << endl;
else cout << "查无此人" << endl;
}
void QQMember::deleteFriend() {
int IDOfTheFriend;
cout << "输入删除的好友的ID" << endl;
cin >> IDOfTheFriend;
for (auto It = friendsList.begin(); It < friendsList.end(); It++) {
if ((*It)->ID == IDOfTheFriend) {
cout << "已删除该好友" << endl;
friendsList.erase(It);
return;
}
}
cout << "好友列表无此人" << endl;
}
void QQMember::enquireFriendsList() {
for (auto It = friendsList.begin(); It < friendsList.end(); It++) {
cout << "好友昵称:" << (*It)->name << " 好友ID:" << (*It)->ID << endl;
}
}
void QQMember::joinInGroup() {
int IDOfNewGroup;
cout << "输入将加入的群的ID" << endl;
cin >> IDOfNewGroup;
if ((IDOfNewGroup - 1000) >= 0 && (IDOfNewGroup - 1000) < serveOfThis->numberOfQQGroups) {
if (serveOfThis->allQQGroups[IDOfNewGroup - 1000] != nullptr) {
QQGroup* newGroup = serveOfThis->allQQGroups[IDOfNewGroup - 1000];
for (auto It = groupsList.begin(); It < groupsList.end(); It++) {
if (newGroup == *It) {
cout << "已在群内" << endl;
return;
}
}
groupsList.push_back(newGroup);
newGroup->admitNewMember(this);
cout << "添加成功" << endl;
}
else cout << "查无此群" << endl;
}
else cout << "查无此群" << endl;
}
void QQMember::quitGroup() {
int IDOfTheGroup;
cout << "输入将退出群的ID" << endl;
cin >> IDOfTheGroup;
for (auto It = groupsList.begin(); It < groupsList.end(); It++) {
if ((*It)->ID == IDOfTheGroup) {
groupsList.erase(It);
(*It)->kickMemberOut(this);
cout << "已退出该群" << endl;
return;
}
}
cout << "群列表没有此群" << endl;
}
void QQMember::createGroup() {
string nameOfNewGroup;
cout << "请输入群名" << endl;
cin >> nameOfNewGroup;
QQGroup* newGroup = new QQGroup(serveOfThis, nameOfNewGroup, this);
groupsList.push_back(newGroup);
hisGroups.push_back(newGroup);
cout << "创建成功,群号:" << newGroup->ID;
}
void QQMember::setGroupAdministrator() {
int IDOfThisGroup;
cout << "输入该群ID" << endl;
cin >> IDOfThisGroup;
QQGroup* thisGroup = nullptr;
for (auto It = groupsList.begin(); It < groupsList.end(); It++) {
if (IDOfThisGroup == (*It)->ID) {
thisGroup = *It;
break;
}
}
if (thisGroup == nullptr) {
cout << "群列表无此群" << endl;
return;
}
if (isGroupOwner(thisGroup)) {
int IDOfThisMember;
cout << "你是该群群主,请输入该成员的ID" << endl;
cin >> IDOfThisMember;
for (auto It2 = thisGroup->membersList.begin(); It2 < thisGroup->membersList.end(); It2++) {
if ((*It2)->ID == IDOfThisMember) {
if ((*It2)->isGroupAdministrator(thisGroup)) {
cout << "该成员已是管理员" << endl;
return;
}
thisGroup->setGroupAdministrator(*It2);
cout << "设置成功" << endl;
return;
}
}
cout << "该群成员列表未找到此人" << endl;
}
else cout << "你不是该群群主,无此权限" << endl;
}
void QQMember::inviteNewGroupMember() {
int IDOfTheGroup;
cout << "输入该用户的ID" << endl;
cin >> IDOfTheGroup;
int IDOfTheMember;
cout << "输入推荐该用户加入的群的ID" << endl;
cin >> IDOfTheMember;
QQMember* theMember;
if ((IDOfTheMember - 10000) >= 0 && (IDOfTheMember - 10000) < serveOfThis->numberOfQQMembers && IDOfTheMember != this->ID) {
if (serveOfThis->allQQMembers[IDOfTheMember - 10000] != nullptr) {
theMember=serveOfThis->allQQMembers[IDOfTheMember - 10000];
}
else { cout << "查无此人" << endl;
return;
}
}
else if (IDOfTheMember == this->ID) {
cout << "不允许推荐自己入群" << endl;
return;
}
else {
cout << "查无此人" << endl;
return;
}
QQGroup* theGroup = nullptr;
for (auto It = groupsList.begin(); It < groupsList.end(); It++) {
if ((*It)->ID == IDOfTheGroup) theGroup = *It;
}
if (theGroup == nullptr) {
cout << "群列表中无此群" << endl;
return;
}
else {
theGroup->admitNewMember(theMember);
cout << "推荐成功" << endl;
} //向管理员请求
}
void QQMember::enquireGroupList() {
for (auto It = groupsList.begin(); It < groupsList.end(); It++) {
cout << "群名:" << (*It)->name << " 群ID:" << (*It)->ID << endl;
}
}
void QQMember::enquireHisGroup() {
for (auto It = hisGroups.begin(); It < hisGroups.end(); It++) {
cout << "群名:" << (*It)->name << " 群ID:" << (*It)->ID << endl;
}
}
QQmemberCRJ.h
Raw Copy
#define QQMEMBERCRJ_H
#ifndef QQMEMBERCRJ_H
#pragma once
#include "memberCRJ.h"
#include "QQGroupCRJ.h"
class QQMember:public Member{
friend class QQGroup;
protected:
vector<QQMember*> friendsList;
vector <QQGroup*> groupsList;
vector<QQGroup*> hisGroups;
bool isGroupAdministrator(QQGroup*);
bool isGroupOwner(QQGroup*);
public:
QQMember(Serve* _serveOfThis, string _name);
~QQMember();
void enquiretAge();
void addFriend();
void deleteFriend();
void enquireFriendsList();
void joinInGroup();
void quitGroup();
void createGroup();
void disbandGroup();
void setGroupAdministrator();
void kickGroupMemberOut();
void inviteNewGroupMember();
void enquireGroupList();
void enquireHisGroup();
};
#endif
ServeCRJ.cpp
Raw Copy
#include "ServeCRJ.h"
Serve::Serve() {
_numberOfQQMembers = 0;
_numberOfQQGroups = 0;
}
Serve::~Serve(){}
void Serve::addNewQQMember(QQMember* newQQMember) {
allQQMembers.push_back(newQQMember);
_numberOfQQMembers++;
}
void Serve::addNewQQGroup(QQGroup* newQQGroup) {
allQQGroups.push_back(newQQGroup);
_numberOfQQGroups++;
}
int Serve::numberOfQQMembers() {
return _numberOfQQMembers;
}
int Serve::numberOfQQGroups() {
return _numberOfQQGroups;
}
ServeCRJ.h
Raw Copy
#ifndef SERVECRJ_H
#define SERVECRJ_H
#pragma once
#include <vector>
#include "memberCRJ.h"
#include "GroupCRJ.h"
#include "QQmemberCRJ.h"
#include "QQGroupCRJ.h"
using namespace std;
class Member;
class Group;
class QQMember;
class Serve {
friend class Member;
friend class QQGroup;
friend class QQMember;
private:
vector<QQMember*> allQQMembers;
int _numberOfQQMembers;
vector<QQGroup*> allQQGroups;
int _numberOfQQGroups;
public:
Serve();
~Serve();
void addNewQQMember(QQMember* newMember);
void addNewQQGroup(QQGroup* newQQGroup);
int numberOfQQMembers();
int numberOfQQGroups();
};
#endif

Comment list( 0 )

You need to Sign in for post a comment

Help Search