程序代码:
//bccn.cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class CCommon
{
public:
CCommon(string &nName, string &nNo, size_t nTeamNo)
{
m_Name = nName;
m_No = nNo;
m_TeamNo = nTeamNo;
}
//设置名字
void SetName(string &nName){ m_Name = nName; }
//获取名字
string GetName()const{ return m_Name; }
//设置学号/工号
void SetNo(string &nNo){ m_No = nNo; }
//获取学号/工号
string GetNo()const {return m_No; }
//设置答辩组号
void SetTeamNo(size_t nTeamNo){ m_TeamNo = nTeamNo;}
//获取答辩组号
size_t GetTeamNo()const{ return m_TeamNo; }
protected:
string m_Name;//姓名
string m_No;//学号/工号
size_t m_TeamNo;//原始组
};
class CStudent: public CCommon
{//学生类
public:
CStudent(string nName, string nNo, size_t nTeamNo = 0):
CCommon(nName, nNo, nTeamNo)
{
m_NewTeamNo = nTeamNo;
}
//设置新的答辩组
void SetNewTeam(size_t nNew){ m_NewTeamNo = nNew;}
//获取新的答辩组
size_t GetNewTeam()const{ return m_NewTeamNo; }
//原始答辩组合现在分配的答辩组是否在同组 在true 否则false
bool IsSameTeam()const{return (m_TeamNo == m_NewTeamNo);}
private:
size_t m_NewTeamNo;//新组
};
class CTeacher: public CCommon
{//导师类
public:
CTeacher(string nName, string nNo, size_t nTeamNo = 0):
CCommon(nName, nNo, nTeamNo){}
//添加学生
void AddStudent(CStudent &stu){ m_StuArray.push_back(stu); }
//设置学生的答辩组id
void SetStudentTeamNo(size_t nNo)
{
vector<CStudent>::iterator itBeg = m_StuArray.begin(),
itEnd = m_StuArray.end();
while (itEnd != itBeg)
{
itBeg->SetTeamNo(nNo);
}
}
//获取所指导的学生信息
vector<CStudent>& GetStuInfo(){ return m_StuArray;}
private:
vector<CStudent> m_StuArray;//辅导的学生
};
class CTeam
{//答辩组类
public:
vector<CTeacher> m_Teacher;//答辩组中的导师们
vector<CStudent> m_ExchgStu;//需要交换的同学们
vector<CStudent> m_Student;//答辩组中的同学们
size_t m_TeamNo;//答辩组的ID
};
vector<CStudent> g_StudentList;//学生信息
vector<CTeacher> g_TeacherList;//导师信息
vector<CTeam> g_TeamList;//答辩组信息
//读取学生的信息
void ReadStudentInfo()
{
}
//读取导师的信息
void ReadTeacherInfo()
{
}
//学生分导师
void StudAttachTeach()
{
//这里采用自动分配
//策略:所有的学生平均分配到各个导师
size_t i = g_StudentList.size();//学生的人数
size_t j = g_TeacherList.size();//导师的人数
if (i < j){ cout << "学生的人数少于导师的人数!" << endl; exit(-1); }
size_t avg = i/j;//平均分配的人数
vector<CStudent>::iterator itStuBeg = g_StudentList.begin(),
itStuEnd = g_StudentList.end();
vector<CTeacher>::iterator itTeaBeg = g_TeacherList.begin(),
itTeaEnd = g_TeacherList.end();
while (itStuBeg != itStuEnd && itTeaEnd != itTeaBeg)
{
for (;avg; --avg)
{
itTeaBeg->AddStudent(*itStuBeg);
++itStuBeg;
--i;
}
--j;
++itTeaBeg;
if (0 == i || 0 == j)
{
break;
}
avg = i/j;
}
}
//导师分组
void TeachAttachTeam()
{
//这里采用自动分配
//策略:所有的导师平均分配到各个组中
size_t i;
size_t j = g_TeacherList.size();
cout << j << "名导师分成多少答辩组:";
cin >> i;
if (1 == i)
{
cout << "一个组!" << endl;
exit(-1);
}
if (i > j)
{
cout << "答辩的分组个数大于导师的人数!" << endl;
exit(-1);
}
g_TeamList.resize(i);
size_t avg = i/j;//平均分配的人数
vector<CTeacher>::iterator itTeaBeg = g_TeacherList.begin(),
itTeaEnd = g_TeacherList.end();
vector<CTeam>::iterator itTeamBeg = g_TeamList.begin(),
itTeamEnd = g_TeamList.end();
while (itTeaEnd != itTeaBeg && itTeamEnd != itTeamBeg)
{
itTeamBeg->m_TeamNo = i;//组号
for (; avg; --avg)
{
itTeaBeg->SetTeamNo(i);//设置导师的答辩组
itTeaBeg->SetStudentTeamNo(i);//设置导师所指导学生的答辩组
itTeamBeg->m_Teacher.push_back(*itTeaBeg);
++itTeaBeg;
--j;
}
--i;
++itTeamBeg;
if (0 == i || 0 == j)
{
break;
}
avg = j/i;
}
}
//调整答辩组的初始状态
void SetTeamInitStatus()
{
vector<CTeam>::iterator itTeamBeg = g_TeamList.begin(),
itTeamEnd = g_TeamList.end();
while (itTeamEnd != itTeamBeg)
{
//收集需要交换的同学信息
vector<CTeacher>::iterator itTeaBeg = itTeamBeg->m_Teacher.begin(),
itTeaEnd = itTeamBeg->m_Teacher.end();
while (itTeaBeg != itTeaEnd)
{
vector<CStudent> stu = itTeaBeg->GetStuInfo();
vector<CStudent>::const_iterator itStuBeg = stu.begin(),
itStuEnd = stu.end();
while (itStuEnd != itStuBeg)
{
itTeamBeg->m_ExchgStu.push_back(*itStuBeg);//收集信息
++itStuBeg;
}
++itTeaBeg;
}
++itTeamBeg;
}
}
//交换答辩组之间的同学
void Exchange()
{
//这里可以先处理下 把各组的答辩学生均匀分配下
//防止个别组因为导师少而学生少的情况(被平均的学生可以放到已交换的同学列中)
//交换方法:
//1、一次交换整个组
//2、把需要交换的同学平均分派到其他的组中()
}
int main(void)
{
return 0;
}