机房预约系统
1、机房预约系统需求
1.1 系统简介
- 学校现有几个规格不同的机房,由于使用时经常出现"撞车"现象,现开发一套机房预约系统,解决这一问题。
1.2 身份简介
分别有三种身份使用该程序
- 学生代表:申请使用机房
- 教师:审核学生的预约申请
- 管理员:给学生、教师创建账号
1.3 机房简介
机房总共有3间
- 1号机房 — 最大容量20人
- 2号机房 — 最多容量50人
- 3号机房 — 最多容量100人
1.4 申请简介
- 申请的订单每周由管理员负责清空。
- 学生可以预约未来一周内的机房使用,预约的日期为周一至周五,预约时需要选择预约时段(上午、下午)
- 教师来审核预约,依据实际情况审核预约通过或者不通过
1.5 系统具体需求
- 首先进入登录界面,可选登录身份有:
- 学生代表
- 老师
- 管理员
- 退出
- 每个身份都需要进行验证后,进入子菜单
- 学生需要输入 :学号、姓名、登录密码
- 老师需要输入:职工号、姓名、登录密码
- 管理员需要输入:管理员姓名、登录密码
- 学生具体功能
- 申请预约 — 预约机房
- 查看自身的预约 — 查看自己的预约状态
- 查看所有预约 — 查看全部预约信息以及预约状态
- 取消预约 — 取消自身的预约,预约成功或审核中的预约均可取消
- 注销登录 — 退出登录
- 教师具体功能
- 查看所有预约 — 查看全部预约信息以及预约状态
- 审核预约 — 对学生的预约进行审核
- 注销登录 — 退出登录
- 管理员具体功能
- 添加账号 — 添加学生或教师的账号,需要检测学生编号或教师职工号是否重复
- 查看账号 — 可以选择查看学生或教师的全部信息
- 查看机房 — 查看所有机房的信息
- 清空预约 — 清空所有预约记录
- 注销登录 — 退出登录
2、 创建身份类
2.1 身份的基类
- 在整个系统中,有三种身份,分别为:学生代表、老师以及管理员
- 三种身份有其共性也有其特性,因此我们可以将三种身份抽象出一个身份基类identity
- 在头文件下创建Identity.h文件
#pragma once
#include <iostream>
using namespace std;
class Identity
{
public:
virtual void show_menu()=0;
string m_Pwd;
string m_Name;
};
2.2 学生类
2.2.1 功能分析
-
学生类主要功能是可以通过类中成员函数,实现预约实验室操作
-
学生类中主要功能有:
- 显示学生操作的菜单界面
- 申请预约
- 查看自身预约
- 查看所有预约
- 取消预约
2.2.2 类的创建
-
在头文件以及源文件下创建 student.h 和 student.cpp文件
-
student.h中添加如下代码:
#pragma once
#include <iostream>
#include "identity.h"
#include <string>
#include "computerRoom.h"
#include <fstream>
#include "globalFile.h"
#include <vector>
#include "orderFile.h"
using namespace std;
class Student:public Identity
{
public:
int m_Sno;
Student();
Student(int Sno,string Name,string Pwd);
//显示Student子菜单
virtual void show_menu();
//* 申请预约 --- 预约机房
void applyOrder();
//* 查看自身的预约 --- 查看自己的预约状态
void seeMyselfOrder();
//* 查看所有预约 --- 查看全部预约信息以及预约状态
void seeOwnOrder();
//* 取消预约 --- 取消自身的预约,预约成功或审核中的预约均可取消
void cancelOrder();
vector<ComputerRoom>vCom;
};
- student.cpp中添加如下代码:
#include <iostream>
#include "student.h"
using namespace std;
Student::Student()
{
}
Student::Student(int Sno,string Name,string Pwd)
{
this->m_Sno=Sno;
this->m_Name=Name;
this->m_Pwd=Pwd;
/*ifstream ifs;
ifs.open(COMPUTERROOM_FILE,ios::in);
ComputerRoom c;
while(ifs>>c.m_id && ifs>>c.m_capacity)
{
vCom.push_back(c);
}
ifs.close();*/
}
void Student::show_menu()
{
cout<<"欢迎同学登录"<<endl;
cout<<"\t -------------------------------\t"<<endl;
cout<<"\t|\t1.申 请 预 约\t\t|\t"<<endl;
cout<<"\t|\t\t\t\t|"<<endl;
cout<<"\t|\t2.查看自身预约\t\t|\t"<<endl;
cout<<"\t|\t\t\t\t|"<<endl;
cout<<"\t|\t3.查看所有预约\t\t|\t"<<endl;
cout<<"\t|\t\t\t\t|"<<endl;
cout<<"\t|\t4.取 消 预 约\t\t|\t"<<endl;
cout<<"\t|\t\t\t\t|"<<endl;
cout<<"\t|\t0.退 出 登 录\t\t|\t"<<endl;
cout<<"\t -------------------------------\t"<<endl;
cout<<"输入你选择的操作:"<<endl;
}
void Student::applyOrder()
{
cout<<"机房可供预约的时间段为周一至周五,请选择你想要预约的时间:"<<endl;
cout<<"1.周一"<<endl;
cout<<"2.周二"<<endl;
cout<<"3.周三"<<endl;
cout<<"4.周四"<<endl;
cout<<"5.周五"<<endl;
int date=0;
int shiDuan=0;
int room=0;
while (true)
{
cin>>date;
if (date>=1||date<=5)
{
break;
}
else
{
cout<<"请规范输入:"<<endl;;
}
}
cout<<"请选择你要预约的时间段:"<<endl;
cout<<"1.上午"<<endl;
cout<<"2.下午"<<endl;
while (true)
{
cin>>shiDuan;
if (shiDuan==1||shiDuan==2)
{
break;
}
else
{
cout<<"请规范输入:"<<endl;;
}
}
cout<<"请选择你要预约的机房:"<<endl;
cout<<"1.一号机房 容量:20"<<endl;
cout<<"2.一号机房 容量:50"<<endl;
cout<<"3.一号机房 容量:100"<<endl;
while (true)
{
cin>>room;
if (room==1||room==2||room==3)
{
break;
}
else
{
cout<<"请规范输入:"<<endl;;
}
}
cout<<"预约请求已提交"<<endl;
ofstream ofs;
ofs.open(ORDER_FILE,ios::out|ios::app);
ofs << "date:" << date << " ";
ofs << "interval:" << shiDuan << " ";
ofs << "stuId:" << this->m_Sno << " ";
ofs << "stuName:" << this->m_Name << " ";
ofs << "roomId:" << room << " ";
ofs << "status:" << 1 << endl;
ofs.close();
system("pause");
system("cls");
}
//* 查看自身的预约 --- 查看自己的预约状态
void Student::seeMyselfOrder()
{
OrderFile of;
//ifstream ifs;
//ifs.open(ORDER_FILE,ios::in);
if (of.m_Size==0)
{
cout<<"现在还没有预约信息"<<endl;
system("pause");
system("cls");
return;
}
int j=1;
for(map<int, map<string, string>>::iterator it = of.m_orderData.begin(); it != of.m_orderData.end();it++)
{
int i=1;
for (map<string, string>::iterator mit = it->second.begin(); mit != it->second.end(); mit++)
{
if (mit->second==to_string(this->m_Sno))
{
cout << j<< "、";
for (map<string, string>::iterator Mit = it->second.begin(); Mit != it->second.end(); Mit++)
{
if (i==1)
{
cout<<"星期";
cout<<Mit->second<<" ";
}
else if (i==2)
{
cout << "时段:" << "" ;
cout<<((Mit->second)=="1"?"上午":"下午")<<" ";
}
else if (i==3)
{
cout<<"机房:";
cout<<Mit->second<<" ";
}
else if(i==4)
{
cout <<"状态:" ;
if (Mit->second=="1")
{
cout<<"审核中"<<endl;
}
else if (Mit->second=="2")
{
cout<<"预约成功"<<endl;
}
else if (Mit->second=="-1")
{
cout<<"预约失败"<<endl;
}
else
{
cout<<"已取消"<<endl;
}
}
i++;
}
j++;
}
}
}
//ifs.close();
system("pause");
system("cls");
}
//* 查看所有预约 --- 查看全部预约信息以及预约状态
void Student::seeOwnOrder()
{
OrderFile of;
//ifstream ifs;
//ifs.open(ORDER_FILE,ios::in);
if (of.m_Size==0)
{
cout<<"现在还没有预约信息"<<endl;
system("pause");
system("cls");
return;
}
for(map<int, map<string, string>>::iterator it = of.m_orderData.begin(); it != of.m_orderData.end();it++)
{
cout << it->first+1 << "、";
int i=1;
for (map<string, string>::iterator mit = it->second.begin