前言
衔接上一篇“c++学习笔记-STL案例-机房预约系统5-学生模块”,本文主要设计老师模块,从,老师登录和注销、查看所有预约、审核预约三个方面进行分析和实现。
目录
在Teacher类的构造函数中,初始化教师信息,代码如下:
//有参构造 参数:职工号,姓名,密码
Teacher::Teacher(int empid, string name, string pwd)
{
this->m_EmpId = empid;
this->m_Name = name;
this->m_Pwd = pwd;
}
?添加位置如图:
????????查看所有预约
????????审核预约
? ? ? ? 注销功能
添加全局函数 void TeacherMenu(Identity*&manager)代码如下:
//进入老师子菜单
void teacherMenu(Identity*& teacher)
{
while (true)
{
//调用子菜单界面
teacher->operMenu();
//将父类指针 转为子类指针 调用子类指针特有的功能
Teacher * tea = (Teacher*)teacher;
int select;//接收用户选择
cin >> select;
if (select == 1) //查看所以预约
{
tea->showAllOrder();
}
else if (select == 2) //审核预约
{
tea->validOrder();
}
else
{
delete teacher;
cout << "注销成功" << endl;
system("pause");
system("cls");
return;
}
}
}
??添加位置如图:
//菜单界面
void Teacher::operMenu()
{
cout << "欢迎教师" << this->m_Name << "登录!" << endl;
cout << "\t\t -------------------------------------------------" << endl;
cout << "\t\t| |\n";
cout << "\t\t| 1.查看所有预约 |\n";
cout << "\t\t| |\n";
cout << "\t\t| 2.审核预约 |\n";
cout << "\t\t| |\n";
cout << "\t\t| 0.注销登录 |\n";
cout << "\t\t| |\n";
cout << "\t\t -------------------------------------------------" << endl;
cout << "请选择您的操作:" << endl;
}
??添加位置如图:
//进入教师身份子菜单
teacherMenu(person);
???添加位置如图:
登录老师账号:
注销老师账号:
该功能与学生身份的查看所有预约功能相似,用于显示所以预约记录
在Teacher.cpp中实现成员函数void Teacher::showAllOrder()
//查看所有预约
void Teacher::showAllOrder()
{
OrderFile of;
if (of.m_Size == 0)
{
cout << "无预约记录!" << endl;
system("pause");
system("cls");
return;
}
for (int i = 0; i < of.m_Size; i++)
{
cout << i + 1 << "、";
cout << "预约日期:周" << of.m_orderDate[i]["data"];
cout << "预约时段:" << (of.m_orderDate[i]["interval"] == "1" ? "上午" : "下午");
cout << "学号:" << of.m_orderDate[i]["stuId"];
cout << "姓名:" << of.m_orderDate[i]["stuName"];
cout << "机房号:" << of.m_orderDate[i]["roomId"];
string status = "状态:";
//1审核中 2已预约 -1预约失败 0取消预约
if (of.m_orderDate[i]["status"] == "1")
{
status += "审核中";
}
else if (of.m_orderDate[i]["status"] == "2")
{
status += "已预约";
}
else if (of.m_orderDate[i]["status"] == "-1")
{
status += "预约失败,审核未通过";
}
else if (of.m_orderDate[i]["status"] == "0")
{
status += "预约已经取消";
}
cout << status << endl;
}
system("pause");
system("cls");
}
?添加位置如图:
//审核预约
void Teacher::validOrder()
{
OrderFile of;
if (of.m_Size == 0)
{
cout << "无预约记录" << endl;
system("pause");
system("cls");
return;
}
vector<int>v;
int index = 0;
cout << "审核中的预约记录如下:" << endl;
for (int i = 0; i < of.m_Size; i++)
{
if (of.m_orderDate[i]["status"] == "1")//审核中的预约
{
v.push_back(i);
cout << ++index << "、";
cout << "预约日期:周" << of.m_orderDate[i]["date"];
cout << " 时间段:" << (of.m_orderDate[i]["interval"] == "1" ? "上午" : "下午");
cout << " 学生编号:" << of.m_orderDate[i]["stuId"];
cout << " 学生姓名:" << of.m_orderDate[i]["stuName"];
cout << " 机房编号:" << of.m_orderDate[i]["roomId"];
string status = " 状态:审核中";
cout << status << endl;
}
}
cout << "请输入审核的预约记录,0代表返回" << endl;
int select = 0;//接受用户选择的预约记录
int ret = 0;//接受预约结果记录
while (true)
{
cin >> select;
if (select >= 0 && select <=v.size())
{
if (select == 0)
{
break;
}
else
{
cout << "请输入审核结果" << endl;
cout << "1、通过" << endl;
cout << "2、不通过" << endl;
cin >> ret;
if (ret == 1)
{
//通过情况
of.m_orderDate[v[select - 1]]["status"] = "2";
}
else
{
//不通过情况
of.m_orderDate[v[select - 1]]["status"] = "-1";
}
of.updateOrder();//更新预约记录
cout << "审核完毕!" << endl;
break;
}
}
cout << "输入有误,重新输入!" << endl;
}
system("pause");
system("cls");
}
??添加位置如图:
审核通过测试:
order.txt文件第一条预约也对应更改为“2”表示审核通过:?
审核不通过测试:
order.txt文件第一条预约也对应更改为“-1”表示审核不通过:??
查看所有预约,?第一条预约为"已预约”、?第二条预约为"预约失败,审核未通过”,符合上面两个操作审核的过程结果: