做这个系统的核心就是对文件的读写操作,其余的都是基础知识,不用搞太复杂 。这里弄得有些复杂了

Admin.h

#include"Teacher.h"
//管理员功能
class Admit:public Student,public Teacher
{
private:
string id, password;
public:
Admit();
static vector<Teacher>vecTea;//定义一个存放全部教师的容器
static vector<Student>vecStu;//定义一个存放全部学生的容器
void admitStudent();//对学生进行增删改查
void admitSubject();//对课程进行增删改查
void admitTeacher();//对教师进行增删改查
void addStudent();//添加学生
void cancel();//删除学生
void modify_Stu();//修改学生信息
void findID();//查看学生信息
void addSubject();//录入课程
void findSub();//查看所有课程
void modify_Sub();//修改课程
void cancelSub();//删除课程
void saveSub();//把课程保存到文件中
bool is_repeatID(string id);//判断学号是否重复
void read_File();//读取学生信息文件
void saveStuSub();//把学生课程信息保存到文件中
void saveStuID();//把学账号密码存入文件
void read_Stuvt();//初始化取学生类中存放教师容器,老师类中存放学生容器
void read_Sub();//读取课程文件
void read_Teacher();//读取教师信息
void addtTeacher();//录入教师
void findTeacher();//查看教师
void moidfy_Tea();//修改教师
void cancelTea();//删除教师
void saveTea();//保存教师信息到文件
bool is_repeatTea(string tempid);//判断职工号是否有重复
void repeatdefin();//重定义数据
void login();//登录
void Studentlogin();//学生登录
void Teacherlogin();//教师登录
void Admitlogin();//管理员登录
};

Admin.cpp

include"Admit.h"
vector<Student>Admit::vecStu;//静态成员类外初始化
vector<Teacher>Admit::vecTea;

//重定义数据
void Admit::repeatdefin()
{
//先清空所有容器
vecStu.clear();
vecTea.clear();
vt.clear();
vs.clear();
mSub.clear();
//重新读取信息
read_File();//读取学生信息
read_Sub();//读取课程信息
read_Teacher();//读取教师信息
read_Stuvt();//初始化取学生类中存放教师容器,老师类中存放学生容器
}
Admit::Admit()
{
//增加四门选修课
string Sub[4] = { "电路","线代","物理","历史" };
int id2[4] = { 1005,1006,1007,1008 };
for (int i = 0; i < 4; i++)
{
mSub.insert(make_pair(id2[i], Sub[i]));
}
read_File();//读取学生信息
read_Sub();//读取课程信息
read_Teacher();//读取教师信息
read_Stuvt();//初始化取学生类中存放教师容器,老师类中存放学生容器
}
//初始化取学生类中存放教师容器,老师类中存放学生容器
void Admit::read_Stuvt()
{
//初始化取学生类中存放教师容器
vector<Teacher>::iterator it;
for (it = vecTea.begin(); it != vecTea.end(); it++)
{
vector<Student>::iterator it1;
for (it1 = vecStu.begin(); it1 != vecStu.end(); it1++)
{
vector<Subject>::iterator it2;
for (it2 = it1->vcs.begin(); it2 != it1->vcs.end(); it2++)
{
if (it2->id == it->Subid)
{
it1->vt.push_back(*it);
break;
}
}
for (it2 = it1->ves.begin(); it2 != it1->ves.end(); it2++)
{
if (it2->id == it->Subid)
{
it1->vt.push_back(*it);
break;
}
}
}
}
//初始化老师类中存放学生容器
vector<Student>::iterator it3;
for (it3 = vecStu.begin(); it3 != vecStu.end(); it3++)
{
vector<Teacher>::iterator it4;
for (it4 = vecTea.begin(); it4 != vecTea.end(); it4++)
{
vector<Subject>::iterator it5;
for (it5 = it3->vcs.begin(); it5 != it3->vcs.end(); it5++)
{
if (it5->id == it4->Subid)
{
it4->vs.push_back(*it3);
break;
}
}
for (it5 = it3->ves.begin(); it5 != it3->ves.end(); it5++)
{
if (it5->id == it4->Subid)
{
it4->vs.push_back(*it3);
break;
}
}
}
}
}
//对学生进行增删改查
void Admit::admitStudent()
{
bool is_continute = true;
while (is_continute)
{
cout << " ===================管理学生=====================" << endl;
cout << " -----------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "添 加 学 生" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "查 看 学 生" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "修 改 学 生" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "删 除 学 生" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "5." << "返 回 上 一 个 菜 单" << " |" << endl;
cout << " | |" << endl;
cout << " -----------------------------------" << endl;
char choice;
cout << "请输入您要进行的操作:";
cin >> choice;
switch (choice)
{
case '1':
{
addStudent();
system("pause");
system("cls");
break;
}
case '2':
{
system("cls");
findID();
system("cls");
break;
}
case '3':
{
modify_Stu();
system("pause");
system("cls");
break;
}
case '4':
{
cancel();
system("pause");
system("cls");
break;
}
case '5':
{
is_continute = false;
break;
}
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//对课程进行增删改查
void Admit::admitSubject()
{
bool is_continute = true;
while (is_continute)
{
cout << " ===================管理课程=====================" << endl;
cout << " -----------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "添 加 课 程" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "查 看 课 程" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "修 改 课 程" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "删 除 课 程" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "5." << "返 回 上 一 个 菜 单" << " |" << endl;
cout << " | |" << endl;
cout << " -----------------------------------" << endl;
char choice;
cout << "请输入您要进行的操作:";
cin >> choice;
switch (choice)
{
case '1':
addSubject();//录入课程
system("pause");
system("cls");
break;
case '2':
findSub();//查看所有课程
system("pause");
system("cls");
break;
case '3':
modify_Sub();
system("pause");
system("cls");
break;
case '4':
cancelSub();
system("pause");
system("cls");
break;
case '5':
is_continute = false;
break;
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//添加学生
void Admit::addStudent()
{
cout << "请录入学号:";
string tempid;
cin >> tempid;
bool is_continut = true;
while (is_continut)
{
vector<Teacher>::iterator it1;
for (it1 = vecTea.begin(); it1 != vecTea.end(); it1++)
{
if (tempid == it1->get_id())
{
cout << "学号不能与职工号重复,请重新输入:";
cin >> tempid;
break;
}
}
if (it1 == vecTea.end())
{
is_continut = false;
break;
}
}
while (is_repeatID(tempid))
{
cout << "该学号已存在!请重新输入:";
cin >> tempid;
}
string temppassword = "123456";//默认密码为123456
Student stu(tempid);
vecStu.push_back(stu);//把录入的学生添加到容器中
saveStuID();
saveStuSub();
cout << "学号:" << tempid << "录入成功" << endl;
}
//删除学生
void Admit::cancel()
{
cout << "请输入所要删除学生的学号:";
string tempid;
cin >> tempid;
vector<Student>::iterator it;
for (it = vecStu.begin(); it != vecStu.end(); it++)
{
if (it->get_id() == tempid)
{
break;
}
}
//若查无此人,则删除失败
if (it == vecStu.end())
{
cout << "没有该学号,无法删除!" << endl;
}
else
{
cout << "已成功删除!" << endl;
vecStu.erase(it);
this->saveStuID();
this->saveStuSub();
}
}
//查看学生信息
void Admit::findID()
{
bool is_continute = true;
while (is_continute)
{
cout << " ===================查询学生信息===================" << endl;
cout << " -----------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "查 询 全 部 学 生" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "查 询 学 生 个 人" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "查 询 学 生 课 程" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "返 回 上 一 个 菜 单" << " |" << endl;
cout << " | |" << endl;
cout << " -----------------------------------" << endl;
cout << "请输入您的操作:";
char choice;
cin >> choice;
switch (choice)
{
case '1':
{
cout << "姓名" << '\t' << "学号:" << '\t' << "专业:" << endl;
for (vector<Student>::iterator it = vecStu.begin(); it != vecStu.end(); it++)
{
cout << it->name << "\t" << it->get_id() << '\t' << it->specialize << endl;
}
system("pause");
system("cls");
break;
}
case '2':
{
cout << "请输入所要查询学生的学号:";
string tempid;
cin >> tempid;
for (vector<Student>::iterator it = vecStu.begin(); it != vecStu.end(); it++)
{
if (it->get_id() == tempid)
{
it->displayID();
it->displaySub();
}
}
system("pause");
system("cls");
break;
}
case '3':
{
for (vector<Student>::iterator it = vecStu.begin(); it != vecStu.end(); it++)
{
it->displaySub();
}
system("pause");
system("cls");
break;
}
case '4':
is_continute = false;
break;
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//修改学生信息
void Admit::modify_Stu()
{
cout << "请输入所要修改学生的学号:";
string tempid;
cin >> tempid;
vector<Student>::iterator it;
bool is_continute = true;
while (is_continute)
{
int number = 0;
for (it = vecStu.begin(); it != vecStu.end(); it++)
{
if (it->get_id() == tempid)
{
number++;
system("cls");
it->modify_ID();
is_continute = false;
saveStuID();
saveStuSub();
break;
}
}
if (number==0)
{
cout << "没有该学号!" << endl;
cout << "请重新输入所要修改学生的学号:";
cin >> tempid;
}
}
}
//判断学号是否重复
bool Admit::is_repeatID(string id)
{
vector<Student>::iterator it;
for (it = vecStu.begin(); it != vecStu.end(); it++)
{
if (it->get_id() == id)
{
return true;
}
}
return false;
}
//把学生信息保存到文件中
void Admit::saveStuSub()
{
//对学生的课程进行保存
ofstream ofs("StudentSubject.txt", ios::trunc| ios::out);
vector<Student>::iterator it;
for (it = vecStu.begin(); it != vecStu.end(); it++)
{
vector<Subject>::iterator it1;
//把学生的必修课程存入文件
for (it1 = it->vcs.begin(); it1 != it->vcs.end(); it1++)
{
ofs << it->get_id() << " " << it1->id << " " << it1->subject << " " << it1->score << endl;
}
//把学生的选修课程存入文件
for (it1 = it->ves.begin(); it1 != it->ves.end(); it1++)
{
ofs << it->get_id() << " " << it1->id << " " << it1->subject << " " << it1->score << endl;
}
}
ofs.close();
}
//把学账号密码存入文件(修改学生密码)
void Admit::saveStuID()
{
ofstream ofs("StudentID.txt", ios::trunc | ios::out);
vector<Student>::iterator it;
for (it = vecStu.begin(); it != vecStu.end(); it++)
{
ofs << it->get_id() << " " << it->get_password()<<" " << it->name << " " << it->specialize << endl;
}
ofs.close();
}
//读取文件(初始化)
void Admit::read_File()
{
ifstream ifs("StudentID.txt", ios::in);
string tempid, temppassword,tempname,tempspeacilze;
while (ifs >>tempid&&ifs>>temppassword&&ifs>>tempname&&ifs>>tempspeacilze)
{
Subject tempSub;
string tempSubject;
int tempSubid, tempscore;
vector<Subject>tempvcs;
vector<Subject>tempves;
Student tempStu(tempid);
tempStu.name = tempname;
tempStu.specialize = tempspeacilze;
tempStu.modify_password(temppassword);
ifstream ifs1("StudentSubject.txt", ios::in);
string tempid1;
while (ifs1 >> tempid1 && ifs1 >> tempSubid && ifs1 >> tempSubject && ifs1 >> tempscore)
{
if (tempid != tempid1)
{
continue;
}
if (tempSubject == "c++" || tempSubject == "高数" || tempSubject == "英语")//必修课
{
Subject tempSubject2;
tempSubject2.id = tempSubid;
tempSubject2.subject = tempSubject;
tempSubject2.score = tempscore;
tempvcs.push_back(tempSubject2);
}
else
{
Subject tempSubject3;
tempSubject3.id = tempSubid;
tempSubject3.subject = tempSubject;
tempSubject3.score = tempscore;
tempves.push_back(tempSubject3);
}
}
ifs1.close();
tempStu.vcs = tempvcs;
tempStu.ves = tempves;
vecStu.push_back(tempStu);
}
ifs.close();
}
//对课程进行保存
void Admit::saveSub()
{
ofstream ofs("课程信息.txt", ios::trunc | ios::out);
ofs << "1001" << " " << "c++" << " " << "必修课" << endl;
ofs << "1002" << " " << "高数" << " " << "必修课" << endl;
ofs << "1003" << " " << "英语" << " " << "必修课" << endl;
for (map<int, string>::iterator it = mSub.begin(); it != mSub.end(); it++)
{
ofs << it->first << " " << it->second << " " << "选修课" << endl;
}
ofs.close();
}
//录入课程
void Admit::addSubject()
{
cout << "请录入课程代码:";
int Subid;
cin >> Subid;
while (true)
{
if (Subid == 1001 || Subid == 1002 || Subid == 1003)
{
cout << "该课程代码已存在!请重新输入:";
cin >> Subid;
continue;
}
map<int, string>::iterator it;
for (it = mSub.begin(); it != mSub.end(); it++)
{
if (it->first == Subid)
{
cout << "该课程代码已存在!请重新输入:";
cin >> Subid;
break;
}
}
if (it == mSub.end())
{
break;
}
}
cout << "请输入该课程科目:";
string Subname;
cin >> Subname;
mSub.insert(make_pair(Subid, Subname));
saveSub();
cout << "已成功录入此课程!" << endl;
}
//查看所有课程
void Admit::findSub()
{
cout << "所有课程如下:"<<endl;
cout << endl;
cout << " " << "课程代码" << '\t' << "课程名称" << '\t' << endl;
cout << " " << "1001" << '\t' << "\t" << "c++" << '\t' << '\t' << endl;
cout << " " << "1002" << '\t' << '\t' << "高数" << '\t' << '\t'<< endl;
cout << " " << "1003" << '\t' << "\t" << "英语" << '\t' << '\t' << endl;
for (map<int, string>::iterator it = mSub.begin(); it != mSub.end(); it++)
{
cout << " " << it->first << '\t' << '\t' << it->second << '\t' << '\t' << endl;
}
}
//修改课程
void Admit::modify_Sub()
{
cout << "请输入所要修改的课程代码:";
int tempid=0;
cin >> tempid;
if (tempid == 1001 || tempid == 1002 || tempid == 1003)
{
cout << "必修课程无法修改!" << endl;
}
else
{
string tempname;
int tempid2;
map<int, string>::iterator it;
for (it = mSub.begin(); it != mSub.end(); it++)
{
if (it->first == tempid)
{
cout << "请输入新的课程代码:";
cin >> tempid2;
bool is_continute = true;
while (is_continute)
{
map<int, string>::iterator it2;
for (it2 = mSub.begin();it2!= mSub.end(); it2++)
{
if (it2->first == it->first)
{
continue;
}
if (it2->first == tempid2|| tempid2 == 1001 || tempid2 == 1002 || tempid2 == 1003)
{
cout << "已存在该课程代码!请重新输入:";
cin >> tempid2;
break;
}
}
if (it2 == mSub.end())
{
is_continute = false;
}
}
cout << "请输入课程科目:";
cin >> tempname;
break;
}
}
if (it == mSub.end())
{
cout << "没有该课程代码!" << endl;
}
else
{
mSub.erase(it);
mSub.insert(make_pair(tempid2, tempname));
cout << "修改成功!" << endl;
saveSub();
}
}
}
//删除课程
void Admit::cancelSub()
{
cout << "请输入所要删除的课程代码:";
int tempid;
cin >> tempid;
if (tempid == 1001 || tempid == 1002 || tempid == 1003)
{
cout << "必修课程无法删除!" << endl;
}
else
{
map<int, string>::iterator it;
for (it = mSub.begin(); it != mSub.end(); it++)
{
if (it->first == tempid)
{
break;
}
}
if (it == mSub.end())
{
cout << "没有该课程代码!" << endl;
}
else
{
mSub.erase(it);
saveSub();
cout << "删除成功!" << endl;
}
}
}
//读取课程文件(初始化)
void Admit::read_Sub()
{
ifstream ifs("课程信息.txt", ios::in);
int tempid;
string tempname,Subname;
while (ifs >> tempid && ifs >> tempname && ifs >> Subname)
{
if (Subname == "选修课")
{
mSub.insert(make_pair(tempid, tempname));
}
}
}
//登录
void Admit::login()
{
bool is_continue = true;
while (is_continue)
{
cout << "==============================欢迎使用学生信息管理系统==============================" << endl;
cout << "请选择您的身份:" << endl;;
cout << " ----------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "管 理 员" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "学 生" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "教 师" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "退 出" << " |" << endl;
cout << " | |" << endl;
cout << " ----------------------------" << endl;
cout << "请选择您的操作:";
char choice;
cin >> choice;
switch (choice)
{
case '1':
{
Admitlogin();//管理员登录
repeatdefin();//重定义数据
system("pause");
system("cls");
break;
}
case '2':
{
Studentlogin();//学生登录
repeatdefin();//重定义数据
system("cls");
break;
}
case '3':
{
Teacherlogin();//教师登录
repeatdefin();//重定义数据
system("cls");
break;
}
case '4'://退出
cout << "欢迎下次使用!" << endl;
exit(0);
break;
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//学生登录
void Admit::Studentlogin()
{
cout << "请输入您的登录账号:";
string tempid;
cin >> tempid;
//先查找有没有该账号
vector<Student>::iterator it;
while (true)
{
for (it = vecStu.begin(); it != vecStu.end(); it++)
{
if (it->get_id() == tempid)
{
break;
}
}
if (it != vecStu.end())
{
break;
}
if (it == vecStu.end())
{
cout << "该账号不存在!请重新输入:";
cin >> tempid;
}
}
cout << "请输入您的登录密码:";
string temppassword;
cin >> temppassword;
//判断密码是否正确
while (true)
{
if (it->get_password() == temppassword)
{
break;
}
else
{
cout << "密码错误!请重新输入:";
cin >> temppassword;
}
}
if (it->name == "张三" && it->get_password() == "123456")
{
cout << "首次登陆,请先修改密码!" << endl;
cout << "请输入您的新密码:";
string temp;
cin >> temp;
it->modify_password(temp);
cout << "密码修改成功!" << endl;
cout << "请输入您的用户名:";
string tempname;
cin >> tempname;
it->name = tempname;
cout << "登录成功!" << endl;
saveStuID();
}
else
{
cout << "登录成功!" << endl;
}
system("pause");//按任意键继续
system("cls");//清屏
//学生功能界面
char choice;
bool is_continue = true;
while (is_continue)
{
//界面
cout << "欢迎学生," << it->name << "登录!" << endl;
cout << " -------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "查 看 个 人 信 息" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "查 看 课 表" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "进 行 选 课" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "进 行 评 教" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "5." << "修 改 信 息" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "6." << "退 出 登 录" << " |" << endl;
cout << " | |" << endl;
cout << " -------------------------------" << endl;
cout << "请选择您的操作:";
cin >> choice;
switch (choice)
{
case '1'://查看个人信息
{
it->displayID();
system("pause");
system("cls");
break;
}
case '2'://查看课表
{
it->displaySub();
system("pause");
system("cls");
break;
}
case '3'://选课
{
it->eletiving();
//添加选课的课程代码所对应的教师
it->vt.clear();//先清空该学生存放的教师容器,在重新选入教师
for (vector<Teacher>::iterator it5 = vecTea.begin(); it5 != vecTea.end(); it5++)
{
for (vector<Subject>::iterator it6 = it->vcs.begin(); it6 != it->vcs.end(); it6++)
{
if (it5->Subid == it6->id)
{
it->vt.push_back(*it5);
}
}
for (vector<Subject>::iterator it6 = it->ves.begin(); it6 != it->ves.end(); it6++)
{
if (it5->Subid == it6->id)
{
it->vt.push_back(*it5);
}
}
}
saveStuSub();
system("pause");
system("cls");
break;
}
case '4'://评教
{
it->judgeTea();
//对管理员存放的教师进行修改
for (vector<Teacher>::iterator it3 = it->vt.begin(); it3 != it->vt.end(); it3++)
{
for (vector<Teacher>::iterator it4 = vecTea.begin(); it4 != vecTea.end(); it4++)
{
if (it4->get_id() == it3->get_id())
{
it4->individual.excellent = it3->individual.excellent;
it4->individual.kelter = it3->individual.kelter;
}
}
}
saveTea();
system("pause");
system("cls");
break;
}
case '5':
{//修改信息
system("cls");
it->modify_ID();
saveStuID();
saveStuSub();
system("cls");
break;
}
case '6'://退出登录
{
is_continue = false;
cout << "已成功退出登录!" << endl;
system("pause");
break;
}
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//教师登录
void Admit::Teacherlogin()
{
cout << "请输入您的登录账号:";
string tempid;
cin >> tempid;
//先查找有没有该账号
vector<Teacher>::iterator it;
while (true)
{
for (it = vecTea.begin(); it != vecTea.end(); it++)
{
if (it->get_id() == tempid)
{
break;
}
}
if (it != vecTea.end())
{
break;
}
if (it == vecTea.end())
{
cout << "该账号不存在!请重新输入:";
cin >> tempid;
}
}
cout << "请输入您的登录密码:";
string temppassword;
cin >> temppassword;
//判断密码是否正确
while (true)
{
if (it->get_password() == temppassword)
{
break;
}
else
{
cout << "密码错误!请重新输入:";
cin >> temppassword;
}
}
if (it->name == "教职工" && it->get_password() == "123456")
{
cout << "首次登陆,请先修改密码!" << endl;
cout << "请输入您的新密码:";
string temp;
cin >> temp;
it->modify_password(temp);
cout << "密码修改成功!" << endl;
cout << "请输入您的用户名:";
string tempname;
cin >> tempname;
it->name = tempname;
cout << "登录成功!" << endl;
saveTea();
}
else
{
cout << "登录成功!" << endl;
}
system("pause");//按任意键继续
system("cls");//清屏
//教师功能界面
char choice;
bool is_continue = true;
while (is_continue)
{
//界面
cout << "欢迎教师," << it->name << "登录!" << endl;
cout << " ----------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "查 看 个 人 信 息" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "查 看 学 生 评 教" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "查 看 学 生 信 息" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "录 入 课 程 成 绩" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "5." << "修 改 信 息" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "6." << "退 出 登 录" << " |" << endl;
cout << " | |" << endl;
cout << " ----------------------------------" << endl;
cout << "请选择您的操作:";
cin >> choice;
switch (choice)
{
case '1'://查看个人信息
{
it->display_ID();
system("pause");
system("cls");
break;
}
case '2'://查看评教
{
it->display_ind();
}
case '3'://查看学生信息
{
it->display_Stu();
system("pause");
system("cls");
break;
}
case '4'://录入课程成绩
{
system("cls");
it->mark();
for (vector<Student>::iterator it4 = it->vs.begin(); it4 != it->vs.end(); it4++)
{
for (vector<Student>::iterator it5 = vecStu.begin(); it5 != vecStu.end(); it5++)
{
if (it4->get_id() == it5->get_id())
{
it5->vcs = it4->vcs;
it5->ves = it4->ves;
}
}
}
saveStuID();
saveStuSub();
system("cls");
break;
}
case '5': // 修改信息
{
system("cls");
it->modify_ID();
for (vector<Student>::iterator it4 = it->vs.begin(); it4 != it->vs.end(); it4++)
{
for (vector<Student>::iterator it5 = vecStu.begin(); it5 != vecStu.end(); it5++)
{
if (it4->get_id() == it5->get_id())
{
it5->vcs = it4->vcs;
it5->ves = it4->ves;
}
}
}
saveTea();
saveStuID();
saveStuSub();
system("cls");
break;
}
case '6'://退出登录
{
is_continue = false;
cout << "已成功退出登录!" << endl;
system("pause");
break;
}
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//管理员登录
void Admit::Admitlogin()
{
cout << "请输入您的账号:";
string tempid;
cin >> tempid;
cout << "请输入您的密码:";
string temppassword;
cin >> temppassword;
while (tempid != "admin" || temppassword != "123456")
{
cout << "账号密码错误,请重新输入!" << endl;
cout << "请重新输入您的账号:";
cin >> tempid;
cout << "请重新输入您的密码:";
cin >> temppassword;
}
cout << "登录成功!" << endl;
system("pause");
system("cls");
bool is_continute = true;
while (is_continute)
{
cout << "欢迎管理员,admin登录!" << endl;
cout << " ----------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "管 理 学 生" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "管 理 教 师" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "管 理 课 程" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "退 出 登 录" << " |" << endl;
cout << " | |" << endl;
cout << " ----------------------------" << endl;
cout << "请选择您的操作:";
char choice;
cin >> choice;
switch (choice)
{
case '1'://管理学生
{
system("cls");
admitStudent();
system("cls");
break;
}
case '2':
{
system("cls");
admitTeacher();
system("cls");
break;
}
case '3'://管理课程
{
system("cls");
admitSubject();//管理课程
system("cls");
break;
}
case '4'://退出登录
is_continute = false;
cout << "已成功退出登录" << endl;
break;
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//保存教师信息到文件
void Admit::saveTea()
{
ofstream ofs("TeacherID.txt", ios::trunc | ios::out);
vector<Teacher>::iterator it;
//把教职工的职工号、密码、姓名、课程代码、课程名称、评价优、评价良存入文件
for (it = vecTea.begin(); it != vecTea.end(); it++)
{
ofs << it->get_id() << " " << it->get_password() << " " << it->name<< " " << it->Subid
<<" "<<it->Subname <<" "<<it->individual.excellent<<" "<<it->individual.kelter << endl;
}
ofs.close();
}
//读取教师信息
void Admit::read_Teacher()
{
ifstream ifs("TeacherID.txt", ios::in);
string tempid, temppassword, tempname, tempSubname;
int tempSubid, tempexc, tempkel;
//读取教职工的职工号、密码、姓名、课程代码、课程名称、评价优、评价良
while (ifs >> tempid && ifs >> temppassword && ifs >> tempname && ifs >> tempSubid && ifs >> tempSubname && ifs >> tempexc && ifs >> tempkel)
{
Teacher tempTea(tempid);
tempTea.modify_password(temppassword);
tempTea.name = tempname;
tempTea.Subid = tempSubid;
tempTea.Subname = tempSubname;
tempTea.individual.excellent = tempexc;
tempTea.individual.kelter = tempkel;
vecTea.push_back(tempTea);
}
ifs.close();
}
//判断职工号是否有重复
bool Admit::is_repeatTea(string tempid)
{
vector<Teacher>::iterator it;
for (it = vecTea.begin(); it != vecTea.end(); it++)
{
if (it->get_id() == tempid)
{
return true;
}
}
return false;
}
//录入教师
void Admit::addtTeacher()
{
cout << "请录入职工号:";
string tempid;
cin >> tempid;
bool is_continut = true;
while (is_continut)
{
vector<Student>::iterator it1;
for (it1 = vecStu.begin(); it1 != vecStu.end(); it1++)
{
if (tempid == it1->get_id())
{
cout << "职工号不能与学号重复,请重新输入:";
cin >> tempid;
break;
}
}
if (it1 == vecStu.end())
{
is_continut = false;
break;
}
}
while (is_repeatTea(tempid))
{
cout << "该职工号已存在!请重新输入:" ;
cin >> tempid;
}
string temppassword = "123456";//默认密码为123456
Teacher tea(tempid);
tea.modify_password(temppassword);
tea.Subname = "课程";
tea.name = "教职工";
cout << "请选择该教师的课程代码,可选择的课程代码如下" << endl;
int a=0, b=0, c=0;
map<int, string>::iterator it;
for (it = mSub.begin(); it != mSub.end(); it++)
{
vector<Teacher>::iterator it1;
for (it1 = vecTea.begin(); it1!= vecTea.end(); it1++)
{
if (it1->Subid == it->first)
{
break;
}
if (it1->Subid == 1001)
{
a++;
}
if (it1->Subid == 1002)
{
b++;
}
if (it1->Subid == 1003)
{
c++;
}
}
if (it1 == vecTea.end())
{
cout <<'\t' << "课程代码:" << it->first << '\t' << "课程名称:" << it->second << endl;
}
}
if (a == 0)
{
cout << '\t' << "课程代码:" << 1001 << '\t' << "课程名称:" << "c++" << endl;
}
if (b == 0)
{
cout << '\t' << "课程代码:" << 1002 << '\t' << "课程名称:" << "高数" << endl;
}
if (c== 0)
{
cout << '\t' << "课程代码:" << 1003 << '\t' << "课程名称:" << "英语" << endl;
}
cout << "请输入所选的课程代码:";
int tempSubjectid;
cin >> tempSubjectid;
while (true)
{
int number = 0;
map<int, string>::iterator it2;
for (it2 = mSub.begin(); it2 != mSub.end(); it2++)
{
if (it2->first==tempSubjectid)
{
number++;
}
}
if (number!=0)
{
break;
}
if (tempSubjectid == 1001 || tempSubjectid == 1002 || tempSubjectid == 1003)
{
break;
}
else
{
cout << "没有该课程代码!请重新输入:";
cin >> tempSubjectid;
}
}
for (it = mSub.begin(); it != mSub.end(); it++)
{
vector<Teacher>::iterator it1;
for (it1 = vecTea.begin(); it1 != vecTea.end(); it1++)
{
while (true)
{
int tempnuber = 0;
map<int, string>::iterator it2;
for (it2 = mSub.begin(); it2 != mSub.end(); it2++)
{
if (tempSubjectid == it2->first)
{
tempnuber++;
break;
}
}
if (tempnuber!=0)
{
break;
}
if (tempSubjectid == 1001 || tempSubjectid == 1002 || tempSubjectid == 1003)
{
break;
}
else
{
cout << "没有该课程代码!请重新输入:";
cin >> tempSubjectid;
}
}
if (it1->Subid == tempSubjectid)
{
cout << "该课程代码已经被其他教师选择,请重新输入:";
cin >> tempSubjectid;
break;
}
}
if (it1 == vecTea.end())
{
break;
}
}
tea.Subid = tempSubjectid;//把课程代码所对应的课程名称赋值给教师所教的课程
if (tempSubjectid == 1001)
{
tea.Subname = "c++";
}
if (tempSubjectid == 1002)
{
tea.Subname = "高数";
}
if (tempSubjectid == 1003)
{
tea.Subname = "英语";
}
for (it = mSub.begin(); it != mSub.end(); it++)
{
if (it->first == tea.Subid)
{
tea.Subname=it->second;
}
}
//若已有学生选该课程代码,添加学生到该教师的学生容器
for (vector<Student>::iterator it8 = vecStu.begin(); it8 != vecStu.end(); it8++)
{
for (vector<Subject>::iterator it9 = it8->vcs.begin(); it9 != it8->vcs.end(); it9++)
{
if (it9->id == tempSubjectid)
{
tea.vs.push_back(*it8);
}
}
for (vector<Subject>::iterator it9 = it8->ves.begin(); it9 != it8->ves.end(); it9++)
{
if (it9->id == tempSubjectid)
{
tea.vs.push_back(*it8);
}
}
}
vecTea.push_back(tea);//把录入的教职工添加到容器中
saveTea();
cout << "职工号:" << tempid << "录入成功" << endl;
}
//查看教师
void Admit::findTeacher()
{
bool is_continute = true;
while (is_continute)
{
cout << " ===================查询教师信息===================" << endl;
cout << " -----------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "查 询 全 部 教 师" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "查 询 教 师 个 人" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "查 询 教 师 评 优" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "返 回 上 一 个 菜 单" << " |" << endl;
cout << " | |" << endl;
cout << " -----------------------------------" << endl;
cout << "请输入您的操作:";
char choice;
cin >> choice;
switch (choice)
{
case '1':
{
cout << "所有教师如下:" << endl;
int number = 0;//记录是否有教师
cout << "姓名" << "\t" << "职工号" << '\t' << "课程代码" << '\t' << "课程名称" << endl;
for (vector<Teacher>::iterator it = vecTea.begin(); it != vecTea.end(); it++)
{
cout << it->name << "\t" << it->get_id() << '\t' << it->Subid<<'\t'<<'\t' << it->Subname << endl;
number++;
}
if (number == 0)
{
cout << "暂无教师" << endl;
}
system("pause");
system("cls");
break;
}
case '2':
{
cout << "请输入所要查询教师的职工号:";
string tempid;
cin >> tempid;
while (true)
{
int number1 = 0;
int number = 0;////记录是否有教师
for (vector<Teacher>::iterator it = vecTea.begin(); it != vecTea.end(); it++)
{
if (it->get_id() == tempid)
{
number1++;
it->display_ID();
number++;
break;
}
}
if (number1 != 0)
{
break;
}
if (number == 0)
{
cout << "输入错误,没有该职工号" << endl;
cout << "请重新输入职工号:";
cin >> tempid;
}
}
system("pause");
system("cls");
break;
}
case '3':
{
int number = 0;
for (vector<Teacher>::iterator it = vecTea.begin(); it != vecTea.end(); it++)
{
number++;
}
if (number == 0)
{
cout << "暂无教师,请先添加教师" << endl;
}
else
{
cout << "职工号" << '\t' << "姓名" << '\t' << "优秀" << '\t' << "良好" << endl;
for (vector<Teacher>::iterator it = vecTea.begin(); it != vecTea.end(); it++)
{
int numberstu = 0;//记录该教师有多少位学生
for (vector<Student>::iterator it1 = it->vs.begin(); it1 != it->vs.end(); it1++)
{
numberstu++;
}
cout << it->get_id() << '\t' << it->name << '\t' << it->individual.excellent << "/"
<< numberstu << '\t' << it->individual.kelter << "/" << numberstu << endl;
}
}
system("pause");
system("cls");
break;
}
case '4':
is_continute = false;
break;
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//修改教师
void Admit::moidfy_Tea()
{
cout << "请输入所要修改教师的职工号:";
string tempid;
cin >> tempid;
vector<Teacher>::iterator it;
bool is_continute = true;
bool is_exitTea = false;
while (is_continute)

{
for (it = vecTea.begin(); it != vecTea.end(); it++)
{
if (it->get_id() == tempid)
{
is_exitTea = true;
system("cls");
bool is_continute = true;
while (is_continute)
{
cout << " ===================修改信息===================" << endl;
cout << " -----------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "姓 名" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "密 码" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "教 师 评 优" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "返 回 上 一 个 菜 单" << " |" << endl;
cout << " | |" << endl;
cout << " -----------------------------------" << endl;
cout << "请选择您要修改的操作:";
char choice;
cin >> choice;
switch (choice)
{
case '1':
{
cout << "请输入您要更改的名字:";
string name1;
cin >> name1;
it ->name= name1;
cout << "已成功修改姓名" << endl;
system("pause");
system("cls");
break;
}
case '2':
{
cout << "请输入您要更改的密码:";
string password1;
cin >> password1;
it->modify_password(password1);
cout << "已成功修改密码" << endl;
system("pause");
system("cls");
break;
}
case '3':
{
system("cls");
cout << "请评教该教师" << endl;
cout << "请输入优秀票数:";
int temp;
cin >> temp;
it->individual.excellent = temp;
cout << "请输入良好票数:";
cin >> temp;
it->individual.kelter = temp;
cout << "评教成功!" << endl;
system("pause");
system("cls");
break;
}
case '4':
{
is_continute = false;
break;
}
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
saveTea();
break;
}
}
if (!is_exitTea)
{
cout << "没有该职工号!" << endl;
cout << "请重新输入所要修改教师的职工号:";
cin >> tempid;
}
}
}
//删除教师
void Admit::cancelTea()
{
cout << "请输入所要删除教师的职工号:";
string tempid;
cin >> tempid;
vector<Teacher>::iterator it;
for (it = vecTea.begin(); it != vecTea.end(); it++)
{
if (it->get_id() == tempid)
{
break;
}
}
//若查无此人,则删除失败
if (it == vecTea.end())
{
cout << "没有该职工号,无法删除!" << endl;
}
else
{
cout << "已成功删除!" << endl;
for (vector<Student>::iterator tempit1 = vecStu.begin(); tempit1 != vecStu.end(); tempit1++)
{
for (vector<Teacher>::iterator tempit = tempit1->vt.begin(); tempit != tempit1->vt.end(); tempit++)
{
if (tempit->get_id() == it->get_id())
{
tempit1->vt.erase(tempit);
break;
}
}
}
vecTea.erase(it);
saveTea();
}
}
//对教师进行增删改查
void Admit::admitTeacher()
{
bool is_continute = true;
while (is_continute)
{
cout << " ===================管理教师=====================" << endl;
cout << " -----------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "添 加 教 师" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "查 看 教 师" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "修 改 教 师" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "删 除 教 师" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "5." << "返 回 上 一 个 菜 单" << " |" << endl;
cout << " | |" << endl;
cout << " -----------------------------------" << endl;
char choice;
cout << "请输入您要进行的操作:";
cin >> choice;
switch (choice)
{
case '1':
{
addtTeacher();
system("pause");
system("cls");
break;
}
case '2':
{
system("cls");
findTeacher();
system("cls");
break;
}
case '3':
{
moidfy_Tea();
system("cls");
break;
}
case '4':
{
cancel();
system("pause");
system("cls");
break;
}
case '5':
{
is_continute = false;
break;
}
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}

Teacher.h

#include<iostream>
using namespace std;
#include<fstream>
#include<string>
#include<vector>
#include"Student.h"
#include<cstdlib>
class Student;
//评教
struct Judge
{
int excellent;//评价教师优秀的人数
int kelter;//评价教师良好的人数
};
//教师功能
class Teacher
{
private:
string id, password;//职工号、密码
public:
string name;//姓名
int Subid;//所教的课程代码
string Subname;//所教的课程名称
Teacher();
Teacher(string id);//初始化教师
vector<Student>vs;//定义一个存放学生的容器
string get_id() { return this->id; }//对外获取职工号
string get_password() { return this->password; }//对外获取密码
void modify_password(string password);//修改密码
void mark();//给学生打分数
void allmark();//给全部学生打分数
void indmark();//个别学生打分数
void modify_ID();//修改信息
void display_ID();//打印个人信息
void display_Stu();//打印所教的学生信息
void display_ind();//查看评教
Judge individual;//评价
};

Teacher.cpp

#include"Teacher.h"
Teacher::Teacher()
{
this->name = "教职工";
this->individual.excellent = 0;
this->individual.kelter = 0;
}
Teacher::Teacher(string id)
{
this->name = "教职工";
this->individual.excellent = 0;
this->individual.kelter = 0;
this->id = id;
}
//打印个人信息
void Teacher::display_ID()
{
cout << "姓名:" << this->name << "\t" << "职工号:" << this->id << '\t' << "所教的课程代码:"
<< this->Subid<<'\t' << "课程名称:" << this->Subname<<endl;
}
//打印所教的学生信息
void Teacher::display_Stu()
{
vector<Student>::iterator it;
bool is_exitStu = false;//判断是否存在学生
for (it = vs.begin(); it != vs.end(); it++)
{
is_exitStu = true;
}
if (!is_exitStu)
{
cout << "暂无学生选择该课程" << endl;
}
else
{
cout << "学号" << '\t' << "姓名" << '\t' << "科目" << '\t' << "分数" << endl;
for (it = vs.begin(); it != vs.end(); it++)
{
int tempscore = it->get_Subscore(this->Subid);
if (tempscore == -1)
{
cout << it->get_id() << '\t' << it->name << '\t' << this->Subname << '\t' << "未考试" << endl;
}
else
{
cout << it->get_id() << '\t' << it->name << '\t' << this->Subname << '\t' << tempscore << endl;
}
}
}
}
//修改密码
void Teacher::modify_password(string password)
{
this->password = password;
}
//修改信息
void Teacher::modify_ID()
{
//界面菜单
bool is_continute = true;
while (is_continute)
{
cout << " ===================修改信息===================" << endl;
cout << " -----------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "姓 名" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "密 码" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "学 生 成 绩" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "返 回 上 一 个 菜 单" << " |" << endl;
cout << " | |" << endl;
cout << " -----------------------------------" << endl;
cout << "请选择您要修改的操作:";
char choice;
cin >> choice;
switch (choice)
{
case '1':
{
cout << "请输入您要更改的名字:";
string name1;
cin >> name1;
this->name = name1;
cout << "已成功修改姓名" << endl;
system("pause");
system("cls");
break;
}
case '2':
{
cout << "请输入您要更改的密码:";
string password1;
cin >> password1;
this->password = password1;
cout << "已成功修改密码" << endl;
system("pause");
system("cls");
break;
}
case '3':
{
indmark();
system("pause");
system("cls");
break;
}
case '4':
{
is_continute = false;
break;
}
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//给全部学生打分数
void Teacher::allmark()
{
vector<Student>::iterator it;
int number = 0;
for (it = vs.begin(); it != vs.end(); it++)
{
number++;
}
if (number == 0)
{
cout << "暂无学生选该课程" << endl;
}
else
{
cout << "选择" << this->Subid << "(" << this->Subname << ")" << "如下" << endl;
display_Stu();
for (it = vs.begin(); it != vs.end(); it++)
{
cout << "请给" << it->get_id() << it->name << "学生录入成绩:";
int tempscore;
cin >> tempscore;
it->enterscore(this->Subid, tempscore);
}
cout << "成绩已成功录入" << endl;
}
}
//个别学生打分数
void Teacher::indmark()
{
vector<Student>::iterator it;
int number = 0;
for (it = vs.begin(); it != vs.end(); it++)
{
number++;
}
if (number == 0)
{
cout << "暂无学生选择您的课程" << endl;
}
else
{
cout << "请输入学生的学号:";
string tempid;
cin >> tempid;
while (true)
{
for (it = vs.begin(); it != vs.end(); it++)
{
if (it->get_id() == tempid)
{
break;
}
}
if (it != vs.end())
{
break;
}
else
{
cout << "学号输入错误!请重新输入:";
cin >> tempid;
}
}
int tempscore = it->get_Subscore(this->Subid);
if (tempscore == -1)
{
cout << "学号:" << it->get_id() << '\t' << "姓名:" << it->name << '\t' << "分数:" << "未考试" << endl;
cout << "请录入分数:";
cin >> tempscore;
it->enterscore(this->Subid, tempscore);
cout << "成绩录入成功!" << endl;
}
else
{
cout << "学号:" << it->get_id() << '\t' << "姓名:" << it->name << '\t' << "分数:" << tempscore << endl;
cout << "请输入修改的分数:";
cin >> tempscore;
it->enterscore(this->Subid, tempscore);
cout << "成绩修改成功!" << endl;
}
}
}
//给学生打分数
void Teacher::mark()
{
bool is_continute = true;
while (is_continute)
{
cout << " ============================录入成绩================================" << endl;
cout << " ----------------------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "录 入 个 别 学 生 的 成 绩" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "录 入 全 部 学 生 的 成 绩" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "返 回 上 一 个 菜 单" << " |" << endl;
cout << " | |" << endl;
cout << " ----------------------------------------------" << endl;
cout << "请选择您的操作:";
char choice;
cin >> choice;
switch (choice)
{
case '1'://录 入 个 别 学 生 的 成 绩
{
indmark();
system("pause");
system("cls");
break;
}
case '2'://录 入 全 部 学 生 的 成 绩
{
allmark();
system("pause");
system("cls");
break;
}
case '3':
{
is_continute = false;
break;
}
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//查看评教
void Teacher::display_ind()
{
cout << "认为您优秀的学生有:" << this->individual.excellent << "人" << endl;
cout << "认为您良好的学生有:" << this->individual.kelter << "人" << endl;
}

Student.h

#include<iostream>
using namespace std;
#include<fstream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include"Teacher.h"
//定义结构体存放课程和分数
class Teacher;
struct Subject
{
int id = 10001;
string subject;
int score=-1;//该科目的分数,用负一表示该课程未考试
};
//学生功能
class Student
{
private:
string id, password;//账号密码
public:
Student() {};
Student(string id);//初始化学生,给学生增加必修课
vector<Subject>vcs;//定义结构体容器,存放该学生的必修课
vector<Subject>ves;//存放学生已选的选修课
static const string compulsory[3];//定义三门必修课
static map<int ,string>mSub;//存放选修课程容器(增加,查找,修改,删除)
static int index;//定义索引选修课的数量
void eletiving();//进行选修课程
void modify_password(string temppassword) { this->password = temppassword; }//对密码进行修改
void modify_ID();//修改信息
void displayID();//打印学生个人信息
void displaySub();//打印课程信息
void modify_Sub();//修改课程
void judgeTea();//评教
bool is_repeatSub(string Sub);//判断所选的课程是否重复
int get_Subscore(int tempid);//获取tempid课程代码所对应的分数
void enterscore(int tempSubid,int tempscore);//对tempSubid课程代码所对应的课程打分数
string get_id() { return this->id; }//对外获取账号
string get_password() { return this->password; }//对外获取密码
string name = "张三";//姓名
string specialize;//专业
vector<Teacher>vt;//定义存放该学生的老师容器
};

Student,cpp

#include"Student.h"
const string Student::compulsory[3] = { "c++","高数","英语" };
map<int,string>Student::mSub;
int Student::index = 4;//定义索引选修课的数量
Student::Student(string id)
{
//初始化课程科目
Subject subcom[3];
int id1[3] = { 1001,1002,1003};
for (int i = 0; i < 3; i++)
{
subcom[i].subject = compulsory[i];
subcom[i].id = id1[i];
this->vcs.push_back(subcom[i]);//把必修课加入到学生信息中
}
this->id = id;
this->password = "123456";
this->specialize = "网络工程";
}

//修改信息
void Student::modify_ID()
{
//界面菜单
bool is_continute = true;
while (is_continute)
{
cout << " ===================修改信息===================" << endl;
cout << " -----------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "姓 名" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "专 业" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "课 程" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "4." << "密 码" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "5." << "返 回 上 一 个 菜 单" << " |" << endl;
cout << " | |" << endl;
cout << " -----------------------------------" << endl;
cout << "请选择您要修改的操作:";
char choice;
cin >> choice;
switch (choice)
{
case '1':
{
cout << "请输入您要更改的名字:";
string name1;
cin >> name1;
this->name = name1;
cout << "已成功修改姓名" << endl;
system("pause");
system("cls");
break;
}
case '2':
{
cout << "请输入您要更改的专业:";
string specialize1;
cin >> specialize1;
this->specialize = specialize1;
cout << "已成功修改专业" << endl;
system("pause");
system("cls");
break;
}
case '3':
{
system("cls");
modify_Sub();
system("cls");
break;
}
case '4':
{
cout << "请输入您要更改的密码:";
string password1;
cin >> password1;
this->password = password1;
cout << "已成功修改密码" << endl;
system("pause");
system("cls");
break;
}
case '5':
{
is_continute = false;
break;
}
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//打印学生个人信息
void Student::displayID()
{
cout << "姓名:" << this->name << '\t' << "学号:" << this->id << '\t' << "专业:" << this->specialize << endl;
}
//打印课程信息
void Student::displaySub()
{
cout << this->get_id()<<this->name<< "的课程信息如下:" << endl;
vector<Subject>::iterator it;//用迭代器进行遍历两个容器
cout <<"课程代码"<<'\t' << "课程名称" << '\t' << "课程类型" << '\t' << "分数" << endl;
for (it = vcs.begin(); it != vcs.end(); it++)
{
if (it->score != -1)
{
cout <<it->id<<'\t' << '\t' << it->subject << '\t' << '\t' << "必修课" << '\t' << '\t' << it->score << endl;
}
else
{
cout <<it->id<<'\t' << '\t' << it->subject << '\t' << '\t' << "必修课" << '\t' << '\t' << "未考试" << endl;
}
}
for (it = ves.begin(); it != ves.end(); it++)
{
if (it->score != -1)
{
cout << it->id << '\t' << '\t' << it->subject << '\t' << '\t' << "选修课" << '\t' << '\t' << it->score << endl;
}
else
{
cout << it->id << '\t' << '\t' << it->subject << '\t' << '\t' << "选修课" << '\t' << '\t' << "未考试" << endl;
}
}
}
//进行选修课程
void Student::eletiving()
{
//界面
cout << "可以选择课程如下:" << endl;
map<int, string>::iterator it;
int i = 0;
cout << " -------------------------------------------" << endl;

for (it=mSub.begin();it!=mSub.end();it++)
{
i++;
cout << '\t'<< "课程代码:" << it->first<<'\t'<<"课程名称:"<<it->second << endl;
}
cout << " -------------------------------------------" << endl;
int choice;
cout << "请输入所选的课程代码:";
cin >> choice;
i = 0;
for (vector<Subject>::iterator it1 = ves.begin(); it1 != ves.end(); it1++)
{
if (it1->id == choice)
{
i++;
cout << "已选过该课程!无法再次选择" << endl;
}
}
if (i == 0)
{
map<int, string>::iterator it2;
for (it2 = mSub.begin(); it2 != mSub.end(); it2++)
{
if (it2->first == choice)
{
Subject tempSub;
tempSub.id = it2->first;
tempSub.subject = it2->second;
ves.push_back(tempSub);
cout << "已成功选修该课程" << endl;
break;
}
}
if (it2 == mSub.end())
{
cout << "没有该课程代码" << endl;
}
}
}
//判断所选的课程是否重复
bool Student::is_repeatSub(string Sub)
{
vector<Subject>::iterator it = ves.begin();
for (; it != ves.end(); it++)
{
if (it->subject == Sub)
{
return true;
}
}
return false;
}
//修改课程
void Student::modify_Sub()
{
bool is_continute = true;
while (is_continute)
{
cout << " ===================修改课程===================" << endl;
cout << " -----------------------------------" << endl;
cout << " | |" << endl;
cout << " | " << "1." << "增 加 课 程" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "2." << "删 除 课 程" << " |" << endl;
cout << " | |" << endl;
cout << " | " << "3." << "返 回 上 一 个 菜 单" << " |" << endl;
cout << " | |" << endl;
cout << " -----------------------------------" << endl;
cout << "请输入您的操作:";
char choice;
cin >> choice;
switch (choice)
{
case '1'://添增课程
{
eletiving();
system("pause");
system("cls");
break;
}
case '2'://删除课程(选修课)
{
cout << "已选课程如下:" << endl;
vector<Subject>::iterator it;//用迭代器进行遍历两个容器
cout <<"课程代码"<<'\t' << "课程名称" << '\t' << "课程类型" << '\t' << "分数" << endl;
for (it = ves.begin(); it != ves.end(); it++)
{
if (it->score != -1)
{
cout <<it->id<<'\t'<<'\t' << it->subject << '\t' << '\t' << "选修课" << '\t' << '\t' << it->score << endl;
}
else
{
cout <<it->id << '\t' << '\t'<< it->subject << '\t' << '\t' << "选修课" << '\t' << '\t' << "未考试" << endl;
}
}
cout << "请输入所要删除的课程代码:";
int Sub;
cin >> Sub;
//查找所选的课程里是否有该课程
for (it = ves.begin(); it != ves.end(); it++)
{
if (it->id == Sub)
{
break;
}
}
if (it != ves.end())//进行删除课程
{
ves.erase(it);
cout << "已成功删除此课程" << endl;
}
else
{
cout << "未查找到此课程!" << endl;
}
system("pause");
system("cls");
break;
}
case '3':
is_continute = false;
break;
default:
{
cout << "暂无此选项!" << endl;
system("pause");
system("cls");
}
}
}
}
//获取tempid课程代码所对应的分数
int Student::get_Subscore(int tempid)
{
vector<Subject>::iterator it;
for (it = vcs.begin(); it != vcs.end(); it++)
{
if (it->id == tempid)
{
return it->score;
}
}
for (it = ves.begin(); it != ves.end(); it++)
{
if (it->id == tempid)
{
return it->score;
}
}
return 0;
}
//对tempSubid课程代码所对应的课程打分数
void Student::enterscore(int tempSubid,int tempscore)
{
vector<Subject>::iterator it;
for (it = vcs.begin(); it != vcs.end(); it++)
{
if (it->id == tempSubid)
{
it->score = tempscore;
}
}
for (it = ves.begin(); it != ves.end(); it++)
{
if (it->id == tempSubid)
{
it->score = tempscore;
}
}
}
//评教
void Student::judgeTea()
{
int number = 0;
cout << "您的老师有:"<<endl;
for (vector<Teacher>::iterator it = vt.begin(); it != vt.end(); it++)
{
number++;
cout << it->Subname <<"老师" << '\t' << it->name << endl;
}
if (number == 0)
{
cout << "暂无教师" << endl;
}
else
{
for (vector<Teacher>::iterator it = vt.begin(); it != vt.end(); it++)
{
number++;
cout << "您觉得您的" << it->Subname << "老师" << "(1.优 秀 2.良 好):";
char choice;
cin >> choice;
bool is_continute = true;
while (is_continute)
{
switch (choice)
{
case '1':
{
it->individual.excellent++;
is_continute = false;
break;
}
case '2':
{
it->individual.kelter++;
is_continute = false;
break;
}
default:
{
cout << "操作错误!请重新输入:";
cin >> choice;
}
}
}
}
cout << "评教成功!" << endl;
}

}

main

#include<iostream>
using namespace std;
#include "Admit.h"
#include"Student.h"
int main()
{
Admit ad;
ad.login();//学生信息管理系统登录
return 0;
}

效果

学生信息管理系统_ios

学生信息管理系统_#include_02

学生信息管理系统_ios_03

学生信息管理系统_初始化_04

具体功能可以自己测试一下,总之整个系统只是对文件的读写,代码不难理解